Skip to content

Instantly share code, notes, and snippets.

@iaverypadberg
Created April 21, 2022 18:38
Show Gist options
  • Save iaverypadberg/0a9c548c7b2483b5ce0f6d8fa519573d to your computer and use it in GitHub Desktop.
Save iaverypadberg/0a9c548c7b2483b5ce0f6d8fa519573d to your computer and use it in GitHub Desktop.
A python script for formatting lots of xml files in a directory.
import glob
import subprocess
# Replace this file directory with the location of the xml files
files = glob.glob('/home/isaac/Desktop/work_area/test2_xml/*.xml')
for xml_file in files:
bashCmd = ["xmllint","-format", "-o", "{}".format(xml_file), "{}".format(xml_file)]
process = subprocess.Popen(bashCmd, stdout=subprocess.PIPE)
output, error = process.communicate()
print("Successfully formatted all xml files or I failed. Could be either.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment