How to compare two xml files in python in script?

Manu picture Manu · Aug 8, 2013 · Viewed 11.4k times · Source

I am new python. I have some predefined xml files. I have a script which generate new xml files. I want to write an automated script which compares xmls files and stores the name of differing xml file names in output file? Thanks in advance

Answer

user2286078 picture user2286078 · Aug 8, 2013

I think you're looking for the filecmp module. You can use it like this:

import filecmp
cmp = filecmp.cmp('f1.xml', 'f2.xml')

# Files are equal
if cmp:
    continue
else:
    out_file.write('f1.xml') 

Replace f1.xml and f2.xml with your xml files.