Skip to content

Instantly share code, notes, and snippets.

@bradmartin333
Created February 28, 2022 14:17
Show Gist options
  • Save bradmartin333/485eec02c42af28a7103983ab6bab46d to your computer and use it in GitHub Desktop.
Save bradmartin333/485eec02c42af28a7103983ab6bab46d to your computer and use it in GitHub Desktop.
Find missing/added elements in 2 XML files
import os
import xml.etree.ElementTree as ET
import difflib
dataA = []
dataB = []
f = []
for subdir, dirs, files in os.walk(os.getcwd()):
for file in files:
if '.xml' in file:
f.append(file)
if len(f) > 2:
print("\nMore than 2 .XML files present!\n")
exit(0)
root = ET.parse(f[0]).getroot()
for elem in root.iter():
dataA.append(elem.tag)
root = ET.parse(f[1]).getroot()
for elem in root.iter():
dataB.append(elem.tag)
diff = difflib.Differ().compare(dataA, dataB)
print ('\n'.join(diff))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment