Using xpath/xquery from python scripts
Wow, I like the XPath interface so much more than the awkward DOM models that I have used up until now. Look at how it cleans up the code:
from xml.etree.ElementTree import parse tree = parse('my_file.xml') # Old: tree.getElementsByTagName('creator')[0].childNodes[0].data artst = tree.find('/creator').text
Or as another example for processing gps tracks from my watch, I can select all of the tracks with just a:
tree.find('//trk')
Simple. I like it.
blog comments powered by Disqus