Last active
November 12, 2021 19:06
-
-
Save respondcreate/5347729 to your computer and use it in GitHub Desktop.
Using lxml to convert XML into python objects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
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
and still a DOM under the hood, worthless