Reading XML file and fetching its attributes value in Python
Here’s an lxml snippet that extracts an attribute as well as element text (your question was a little ambiguous about which one you needed, so I’m including both): from lxml import etree doc = etree.parse(filename) memoryElem = doc.find(‘memory’) print memoryElem.text # element text print memoryElem.get(‘unit’) # attribute You asked (in a comment on Ali Afshar’s … Read more