Python Forum
XML comparison - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: XML comparison (/thread-41762.html)



XML comparison - Nik1811 - Mar-15-2024

Hi,

I need to compare two XML's. I have a baseline XML("B_XML.xml) for reference that I use to compare with every new generated XML(A_XML.xml).
I want to do one-one parsing, checking for all attributes and their respective values. I want to flag, if:
1) there are new attributes added to the XML
2) change in value for any attribute

Also, I need a way to report through which I can exactly identify which new field is different/added


I'm trying with xmldiff library. This is great if one value is changed. But if a new attribute is added, then there is a whole long list of failures for multiple attributes:


import xml.etree.ElementTree as ET
from xmldiff import main, formatting

formatter = formatting.XMLFormatter(normalize=formatting.WS_BOTH)
diff_1 = main.diff_files("B_XML.xml", "A_XML.xml")
print(diff_1)



I've heard of the canonical method, but is there anyone who has used it and was successful with retrieving differences that specifies just the location of new attributes?