I have a XML file which looks like:
<root>
<product>
...multiple tags
</product>
<product>
...multiple tags
</product>
.
.
.
</root>
There are multiple products in the file, each having a set of tags. I want to pass the XML corresponding to a product as an argument for a HTTP request. I looked through this but could not find how to "get" a child element.
Could someone please help. Thanks
EDIT: I have tried using:
import xml.etree.ElementTree as ET
tree = ET.parse('sample.xml')
root = tree.getroot()
for child in root:
print child //also tried child.text
But I get the following output and not the XML corresponding to each child:
<Element 'product' at 0xb729328c>
<Element 'product' at 0xb7293d0c>
<Element 'product' at 0xb72987ec>
<Element 'product' at 0xb729b2cc>
<Element 'product' at 0xb729bcec>
Elementobjects. You've just printed them, rather than actually dumping their text content withET.dumps(child), but you don't actually want to pass that dump to the function, you want the child element you already have, which you can manipulate.tostring:for child in root: x = ET.tostring(child); print x