I've the following code which parses an XML response and returns a list of Element objects representing products.
tree = ET.ElementTree(ET.fromstring(raw_xml_response))
products = root.findall('//Product')
I now need to get the raw XML from each Product so I can store it in a DB. It seems Element doesn't have a method to do this - what's the customary way to get the raw XML from each Product Element?
Thanks,
There is a top-level function called tostring (docs) that accepts an element, try
print([ET.tostring(product) for product in products])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With