Skip to content

Instantly share code, notes, and snippets.

@walkerdb
Created October 5, 2015 14:56
Show Gist options
  • Select an option

  • Save walkerdb/54b5f4923738d6481419 to your computer and use it in GitHub Desktop.

Select an option

Save walkerdb/54b5f4923738d6481419 to your computer and use it in GitHub Desktop.
# create a new parser object
parser = etree.XMLParser(remove_blank_text=True)
# when we parse the input file, add a parser argument
tree = etree.parse("path/to/ead.xml", parser=parser)
[... making edits ...]
# when making the output string, add a new pretty_print argument
ead_text = etree.tostring(tree, pretty_print=True, xml_declaration=True, encoding="utf-8")
# write the file
with open(os.path.join("path/to/ead/directory", "ead_filename.xml"), mode="w") as f:
f.write(ead_text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment