I have xml data that wrapped in string, xml data look like this:
<Root>
<Header>
<information>info</information>
</Header>
<Main>
<Product>
<Name>name1</Name>
<Description>description1</Description>
</Product>
<Product>
<Name>name2</Name>
<Description>description2</Description>
</Product>
</Main>
</Root>
I want delete Header tag from it
tree = ET.fromstring(xml_string)
tree.remove(tree.findall('.//Header'))
But it rise error list.remove(x): x not in list. What i did wrong. Thank you
tree.remove takes a single element, not a list of elements, which is what tree.findall returns. You can either call tree.remove for every header you find, or just use tree.find instead of tree.findall if there's only ever going to be one Header.
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