Skip to content

Instantly share code, notes, and snippets.

@odashi
Last active December 1, 2021 07:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save odashi/5ba522b51032203d2a0a36559ff1726f to your computer and use it in GitHub Desktop.
Save odashi/5ba522b51032203d2a0a36559ff1726f to your computer and use it in GitHub Desktop.
Pretty-prints XML file.
#!/usr/bin/env python3
import argparse
from xml.dom import minidom
def main():
p = argparse.ArgumentParser(description='Pretty-print an XML file.')
p.add_argument('file', type=str, help='File path to print.')
args = p.parse_args()
data = open(args.file).read()
pretty = minidom.parseString(data).toprettyxml(indent=' ')
print(pretty)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment