ritvik_raj2012 has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks,
i want to comparetwo xml files of different version,i want to compare it node by node.suppose i take the first node compare it with the first node of other xml.and i want to compare each and every thing like attributes, values.
the two xml files are actually little bit different. like.
sample file 1:
<xml> <abc>abcd</abc> </xml> sample file 2:
<xml> <abc>abcd e</abc> </xml>
now the difference here is in data.so i want to list out such differences.
so,please monks help me out in this.thanks.

Replies are listed 'Best First'.
Re: Comparing two xml files
by Khen1950fx (Canon) on Apr 21, 2012 at 09:25 UTC
    Using XML::Compare:
    #!/usr/bin/perl use strict; use warnings; use XML::Compare tests => 2; my $xml1 = '<xml><abc> abcd </abc></xml>'; my $xml2 = '<xml><abc> abcd e </abc></xml>'; my $same = eval { XML::Compare::same( $xml1, $xml2 ); }; if ($same) { print "same" ; } else { print "different: $@"; }
Re: Comparing two xml files
by choroba (Cardinal) on Apr 21, 2012 at 08:38 UTC
    I usually just run
    xmllint --c14n "$xml" | xmllint --format -
    on both files and use standard diff on the results. But it really depends on the type of XML files and typical changes that occur in them.
Re: Comparing two xml files
by Anonymous Monk on Apr 21, 2012 at 08:54 UTC