[XML-SIG] Regarding 2 XML Files Comparision using Python

Stefan Behnel stefan_ml at behnel.de
Thu Jun 4 13:35:16 CEST 2009

testing123 test wrote:
> Hi all,
>   I am prasad.I need a help to write a python script to compare two XML
> Files.Is there any tutorial.Should we include any library?Please help me
> How to start?

... by looking at the Python package index?

If your XML files are small, you may get away with the xmldiff package.

Also, a very simple way to do that is to pretty print your XML files and
then run a normal line diff on them. Depends on what you want to achieve
with your 'script'.

If you need more than that and want to implement it in Python, you may
consider using lxml (or cElementTree if you can afford to ignore comments)
to parse the two files and then run through the two trees to look for
differences. But note that this is not trivial. There is some scientific
literature on good algorithms to compare XML tree structures.

Note that lxml.html comes with an HTML diff algorithm, which you can look
at for inspiration.


More information about the XML-SIG mailing list