0

I have the following code:

from lxml import etree

root = etree.fromstring(bytes(xml, encoding="utf-8"))
tree = etree.ElementTree(root)

mynode = "/myNamespace:Message/myNamespace:header/myNamespace:id"

for elem in root.iter():
    if tree.getpath(elem) == mynode:
        elem.remove

I however can't get the node to be removed. The xml format looks like so:

<?xml version="1.0" encoding="UTF-8" ?>
<abc:Message xmlns:abc="http://www.zyx.com/abc" schemaVersion="1.2">
<abc:header>
<abc:id>888</abc:id>
<abc:id1>888</abc:id1>  
</abc:header>
<abc:body>
</abc:body>
</abc:Message>

Where am I go wrong with the remove?

mzjn
  • 48,958
  • 13
  • 128
  • 248
pymat
  • 1,090
  • 1
  • 23
  • 45

0 Answers0