Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
XML compare
#1
Im looking for a script what can compare xml and works simular as the compare function in notepad++.

Is there a script like that?
Reply
#2
difflib or try some third party like xmldiff.
I can do test with difflib and use rich for better look.
from difflib import Differ
from rich import print

with open("1.xml") as f1,open("2.xml") as f2:
    f_1 = [i.strip() for i in f1]
    f_2 = [i.strip() for i in f2]

diff = Differ()
difference = list(diff.compare(f_1, f_2))
difference = '\n'.join(difference)
print(difference)
[Image: 8ov7jJ.png]
So it work fine,files used:
1.xml
<app>
  <name>ExtendsClass</name>
  <type>Web</type>
  <url>https://python-forum.io</url>
  <description>Free Online forum</description>
</app>
2.xml
<app>
	<name>ExtendsClass</name>
	<type>Web</type>
	<url>https://vg.no</url>
	<description>Online forum</description>
</app>
Reply


Forum Jump:

User Panel Messages

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