I find the initial learning curve a little steep with lxml - just common tasks, such as grabbing nodes by name, attribute and getting their contents. Here is a very simple question.
I have an XML file. I would like to find all the XML nodes called <Review>. How can I do this most efficiently with lxml?
f = open('./test.xml')
xml = f.read()
tree = etree.parse(StringIO(xml))
context = etree.iterparse(StringIO(xml))
reviews = tree.findall('Review') # Something like this?
I don't know if I should use objectify, xpath ...
Comments are also welcome along the path that I read in the file, and turning it into an parsed lxml object. Thank you
source
share