Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Comparing two XML files with XML::Simple using FOREACH and IF using

by mr_ron (Chaplain)
on Jan 14, 2016 at 16:33 UTC ( #1152786=note: print w/replies, xml ) Need Help??


in reply to Comparing two XML files with XML::Simple using FOREACH and IF using

> Now I'm trying to stores these files in an array and compare them.
> How can one store the entire file in an array?
XML is a tree structure and a single array isn't really designed to be the most intuitive or simple way to store a tree.

> Now I have to compare the two XML files
Comparing XML files is a problem many people need to solve these days so a CPAN search might help. After looking through the modules in the CPAN search results and some experimenting I came up with XML::SemanticDiff. The sample code and output might give further ideas on how the module might be applied to the posted problem.

use strict; use warnings; use XML::SemanticDiff; my $x = XML::SemanticDiff->new; my @diffs = $x->compare( <<EOXML_1, <top> <firstTag>abc</firstTag> <secondTag>def</secondTag> <thirdTag>ghi</thirdTag> </top> EOXML_1 <<EOXML_2 <top> <firstTag>abc</firstTag> <secondTag>456</secondTag> <lastTag>ghi</lastTag> </top> EOXML_2 ); foreach my $change (@diffs) { print "$change->{message}\n\tin XPath context $change->{context} +\n"; } __END__ Character differences in element 'secondTag'. in XPath context /top[1]/secondTag[1] Child element 'thirdTag' missing from element '/top[1]'. in XPath context /top[1] Rogue element 'lastTag' in element '/top[1]'. in XPath context /top[1]
Ron
  • Comment on Re: Comparing two XML files with XML::Simple using FOREACH and IF using
  • Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1152786]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (7)
As of 2022-12-07 20:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?