Here is a short XML file with 2 nodes having the same children (but with 2 different values).
5000 for the node MIAMI
7777 for the node WASHINGTON
<country id="USA">
<city id="MIAMI" method="modify">
<attributes>
<number_people>5000</number_people>
<average_income>40</average_income>
</attributes>
</city>
<city id="WASHINGTON" method="modify">
<attributes>
<number_people>7777</number_people>
<average_income>40</average_income>
</attributes>
</city>
</country>
Using Perl::Twig, I want to check if the nodes MIAMI and WASHINGTON are IDENTICAL (having the same children and the same values).
Here is what I did which is not working
($M->children eq $W->children) is found to be TRUE.
It should be false since “number_people” value is different.
#!/usr/bin/perl -w
use warnings;
use XML::Twig;
my $t= XML::Twig->new;
my $v= XML::Twig::Elt->new;
$t-> parsefile ('file.xml');
my $M=$t->first_elt('city'); # retrieve node MIAMI
my $W=$M->next_sibling('city'); # retrieve node WASHINGTON
if ($M->children eq $W->children) {print "the two nodes are exactly IDENTICAL"; }
What’s about module Data::Compare, it help to compare two perl data structures recursively.
I check documentation for module XML::Twig you can get structure of any TWIG object using method
simplify. So$M->children->simplify