Sample XML file:
<?xml version="1.0"?> <orders> <order id="1" name="Red T-Shirt" customerId="2" count="2"/> <order id="2" name="Blue T-Shirt" customerId="2" count="1"/> </orders>XML processing code:
import libxml2
def listAllOrders(xmlFile):
doc = libxml2.parseFile(xmlFile)
for order in doc.xpathEval('//order'):
rowResult = "OrderId is " + order.xpathEval('@id')[0].content
print rowResult
doc.freeDoc()
listAllOrders('sample.xml')
Output:
OrderId is 1 OrderId is 2Regards
Rafael Sobek
