Using XPath in ElementTree

后端 未结 5 1443
情话喂你
情话喂你 2020-11-30 00:51

My XML file looks like the following:




        
5条回答
  •  庸人自扰
    2020-11-30 00:56

    One of the most straight forward approach and works even with python 3.0 and other versions is like below:

    It just takes the root and starts getting into it till we get the specified "Amount" tag

     from xml.etree import ElementTree as ET
     tree = ET.parse('output.xml')
     root = tree.getroot()
     #print(root)
     e = root.find(".//{http://webservices.amazon.com/AWSECommerceService/2008-08-19}Amount")
     print(e.text)
    

提交回复
热议问题