Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
XML comparison
#1
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?
Larz60+ write Mar-17-2024, 01:22 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020