Skip to content

Instantly share code, notes, and snippets.

@howardhamilton
Created October 19, 2016 16:28
Show Gist options
  • Save howardhamilton/a0c09a14fe1626e76c281d812d0e7b12 to your computer and use it in GitHub Desktop.
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
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