http://qs1969.pair.com?node_id=1152786


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