Skip to content

Instantly share code, notes, and snippets.

@respondcreate
Last active November 12, 2021 19:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save respondcreate/5347729 to your computer and use it in GitHub Desktop.
Save respondcreate/5347729 to your computer and use it in GitHub Desktop.
Using lxml to convert XML into python objects
# You'll need lxml, install it like this:
# $ pip install lxml
# Import objectify from lxml
from lxml import objectify
# Open the XML file in question
f = open('/path/to/xml/file.xml', 'r')
#Ensure the file is ready for parsing
f.seek(0)
# Convert XML into python object tree
root = objectify.fromstring(f.read())
# Now root.tag_name will create a list of all tags with that name
# Here's how you iterate through a list of '<episode>' tags
for episode in root.episode:
# And print the value of a tag named '<start_time>' found within each '<episode>' tag
print episode.start_time
@leryss
Copy link

leryss commented Nov 12, 2021

and still a DOM under the hood, worthless

@respondcreate
Copy link
Author

and still a DOM under the hood, worthless

???

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment