Created
October 19, 2016 16:28
-
-
Save howardhamilton/a0c09a14fe1626e76c281d812d0e7b12 to your computer and use it in GitHub Desktop.
Pattern to wrap XML content in outer tag, in order to get attributes in original root tag
This file contains hidden or 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
from lxml import etree | |
from lxml.builder import E | |
if __name__ == "__main__": | |
with open('sample.xml') as f: | |
xml = f.read() | |
new_xml = E.Wrapper(etree.XML(xml)) | |
print(etree.tostring(new_xml, pretty_print=True)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment