[VPM] Comparing XML Files - XML::Simple is your friend

Doug Snead semaphore_2000 at yahoo.com
Wed Dec 8 15:05:04 CST 2004


--- abez <abez at abez.ca> wrote:
> Parse the XML into a tree composed of arrays (because you
> have more than one subelement of the same type). 

You might look at XML::Simple to slurp the xml into perl
hashes/arrays for you.

Try something like this on your XML, first. dumpxml.pl : 

#!/usr/bin/perl
use XML::Simple;
use LWP::Simple;
use Data::Dumper;
my $x0 = XMLIn(get($ARGV[0]));
print Dumper($x0);

Now test this on one of your XML files.

$ perl dumpxml.pl file:something.xml | less

That will give you a fast peek at how well XML::Simple can
parse your particular XML.  It should then also be (more)
obvious how write a perl script to navigate and compare the
trees. You'll get hashes of arrays, and arrays of hashes. 

So to compare two files you might try something like this.

#!/usr/bin/perl
use XML::Simple;
use LWP::Simple;
use Data::Dumper;
my $x0 = XMLIn(get($ARGV[0]));
my $x1 = XMLIn(get($ARGV[1]));
# compare trees in $x1 and $x2 here : ...

Hope that helps some. If you get stuck email small sample xml
files to be compared and I'll take a look.

Doug






		
__________________________________ 
Do you Yahoo!? 
Yahoo! Mail - Easier than ever with enhanced search. Learn more.
http://info.mail.yahoo.com/mail_250


More information about the Victoria-pm mailing list