Skip to content

Instantly share code, notes, and snippets.

@hugoledoux
Last active April 25, 2019 09:43
Show Gist options
  • Save hugoledoux/acc66a41b2262ff9b8efb7cf515440f9 to your computer and use it in GitHub Desktop.
Save hugoledoux/acc66a41b2262ff9b8efb7cf515440f9 to your computer and use it in GitHub Desktop.
remove carriage returns in an XML file
#!/usr/local/bin/python
from lxml import etree
import sys
fin = sys.argv[1]
parser = etree.XMLParser(remove_blank_text=True)
tree = etree.parse(fin, parser)
root = tree.getroot()
sys.stdout.write(etree.tostring(root, pretty_print=False, xml_declaration=True, encoding="UTF-8"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment