I parse in the XML using
from lxml import etree
tree = etree.parse(\'test.xml\', etree.XMLParser())
Now I want to work on the parsed XML. I\'m
The remove
method should do what you want:
>>> from lxml import etree
>>> from StringIO import StringIO
>>> s = 'foo '
>>> tree = etree.parse(StringIO(s))
>>> print(etree.tostring(tree.getroot()))
foo
>>> title = tree.find('//Title')
>>> title.getparent().remove(title)
>>> etree.tostring(tree.getroot())
' '
>>> print(etree.tostring(tree.getroot()))