I have to read an XML file containing phone call billing detailed information. I decided to stay straightforward in my approach and choosed to use XML::Simple.

First skeleton of code (I do it in a Windows environment) :

#!c:/perl/bin/perl -w
 
use strict;
use XML::Simple;
use Data::Dumper;
 
my $xml = new XML::Simple;
 
my $data = $xml->XMLin("myfile.xml");
print Dumper($data);

the $data variable contains a hashref, so ot see the content of the first level, I could do smth like this :

foreach my $element (keys %$data) { # dereference the hashref
	print "$element\n";
}

Let's say this element is named Bill. I can then have a look at the children :

foreach my $element (keys %{$data->{Bill}}) {
	print "$element\n";
}
 
programmation/perl/xml-simple.txt · Dernière modification: 2006/03/25 08:17 (édition externe)