Skip to content

Instantly share code, notes, and snippets.

@audiodude
Created September 11, 2019 23:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save audiodude/ad44f412779de3b802dfbcdd3a5a98f5 to your computer and use it in GitHub Desktop.
Save audiodude/ad44f412779de3b802dfbcdd3a5a98f5 to your computer and use it in GitHub Desktop.
import xml.etree.ElementTree as Et
tree = Et.ElementTree(file = 'test.xml')
root = tree.getroot()
for child in root:
for grandchild in child:
print(grandchild.findall('.//Raw_Material'))
<XML_Order order_Id='1' terms='Net30' ship_via='UPS'>
<Line_Items>
<Line_Item upc='1234567' item_id='1' color='blk' qty='15'>
<Raw_Materials>
<Raw_Material Item_Id='H188' Vendor_Id='DI0001'/>
<Raw_Material Item_Id='ST03' Vendor_Id='DI0001'/>
</Raw_Materials>
</Line_Item>
<Line_Item upc='12345678' item_id='1' color='blk' qty='15'>
<Raw_Materials>
<Raw_Material Item_Id='H188' Vendor_Id='F10001'/>
<Raw_Material Item_Id='ST03' Vendor_Id='FI0001'/>
</Raw_Materials>
</Line_Item>
</Line_Items>
</XML_Order>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment