Created
April 21, 2022 18:38
-
-
Save iaverypadberg/0a9c548c7b2483b5ce0f6d8fa519573d to your computer and use it in GitHub Desktop.
A python script for formatting lots of xml files in a directory.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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