Created
February 28, 2022 14:17
-
-
Save bradmartin333/485eec02c42af28a7103983ab6bab46d to your computer and use it in GitHub Desktop.
Find missing/added elements in 2 XML files
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 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