Skip to content

Instantly share code, notes, and snippets.

@bricksdont
Created June 28, 2019 08:17
Show Gist options
  • Save bricksdont/e979e8c967d2e28e6113ccb2bdada282 to your computer and use it in GitHub Desktop.
Save bricksdont/e979e8c967d2e28e6113ccb2bdada282 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import lxml.etree as et
xml="""
<text:doc xmlns:text="www.doc.com">
<text:span text:style-name="Kursiv_5f_KeiinRecht">
<text:span text:style-name="T25">madhuparká</text:span>
</text:span>
</text:doc>
"""
ns = {"text": "www.doc.com"}
tree = et.fromstring(xml)
for remove_elem in tree.xpath("//text:span[@text:style-name='Kursiv_5f_KeiinRecht']", namespaces=ns):
children = remove_elem.getchildren()
parent = remove_elem.getparent()
parent.remove(remove_elem)
for index, child in enumerate(children):
parent.insert(index, child)
print et.tostring(tree, pretty_print=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment