What I have tried so far is to load one file into a twig and use the TwigHandlers on the second file to do the comparison on if the information inside the ifIndex has changed.<tmsinfo> <rtr name="router1"> <ifIndex value="127"> <ifDescr value="FastEthernet0/0/1.87"/> <ifSpeed value="100000000"/> <ipAdEntIfIndex value="10.0.0.1"/> </ifIndex> <ifIndex value="32"> <ifDescr value="Serial0/1/1:0"/> <ifSpeed value="256000"/> <ipAdEntIfIndex value="10.0.0.2"/> <locIfDescr value="SomeLink"/> </ifIndex> . .cut . <ifIndex value="146"> <ifDescr value="FastEthernet0/0/1.95"/> <ifSpeed value="64000"/> <ccarConfig ccarDir="1"> <ccarIndex value="1"> <AclNo value="2160"/> <ExtLimit value="8000"/> <Limit value="8000"/> <Rate value="64000"/> </ccarIndex> </ccarConfig> <ccarConfig ccarDir="2"> <ccarIndex value="1"> <AclNo value="3160"/> <ExtLimit value="8000"/> <Limit value="8000"/> <Rate value="64000"/> </ccarIndex> </ccarConfig> <ipAdEntIfIndex value="10.0.0.3"/> </ifIndex> </rtr> </tmsinfo>
I deleted a whole ifIndex section from one of the files, but still end up with an "empty" result. Thanks in advance for any help.#!/usr/bin/perl -w use strict; use XML::Twig; my $router=$ARGV[0]; my $fname="$router.xml"; my $RoutersLastState = XML::Twig->new(); #Last received State ### Load Last State/s $fname="$fname.last"; $RoutersLastState->parsefile($fname); print "Loaded Last State\n"; my $RoutersCurrState = XML::Twig->new( TwigHandlers => { ifIndex => \ +&find_diff }, ); #Current State ### Load Current State $RoutersCurrState->parsefile($fname); print "Loaded Current\n"; my $outfname="$fname.changes"; open (FH,"> $outfname"); $RoutersCurrState->print(\*FH,'indented'); close (FH); exit; sub find_diff{ my( $twig, $ifindex)= @_; my $indexval=$ifindex->att('value'); # print "$indexval\n"; foreach my $oldindex ($RoutersLastState->root->first_child('router') +->children('ifIndex')){ my $oldindexval=$oldindex->att('value'); print "$indexval\t$oldindexval \n"; if ($indexval eq $oldindexval){ $ifindex->cut; print "found one \n"; } } }
In reply to Comparing two XML Files with XML::Twig by DannMan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |