Created
June 28, 2019 08:17
-
-
Save bricksdont/e979e8c967d2e28e6113ccb2bdada282 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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