Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
Do you know where your variables are?
 
PerlMonks  

Comparing two xml files

by ritvik_raj2012 (Initiate)
on Apr 21, 2012 at 08:31 UTC ( #966323=perlquestion: print w/ replies, xml ) Need Help??
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.

Comment on Comparing two xml files
Re: Comparing two xml files
by choroba (Prior) 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
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: $@"; }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://966323]
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (11)
As of 2013-05-19 00:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best material for plates (tableware) is:









    Results (396 votes), past polls