Quantcast
Channel: How to parse multi record XML file ues XML::Simple in Perl - Stack Overflow
Viewing all articles
Browse latest Browse all 4

How to parse multi record XML file ues XML::Simple in Perl

$
0
0

My data.xml

<?xml version="1.0" encoding="ISO-8859-1"?><catalog><cd country="UK"><title>Hide your heart</title><artist>Bonnie Tyler</artist><price>10.0</price></cd><cd country="CHN"><title>Greatest Hits</title><artist>Dolly Parton</artist><price>9.99</price></cd><cd country="USA"><title>Hello</title><artist>Say Hello</artist><price>0001</price></cd></catalog>

my test.pl

#!/usr/bin/perl   # use module   use XML::Simple;   use Data::Dumper;   # create object   $xml = new XML::Simple;   # read XML file   $data = $xml->XMLin("data.xml");   # access XML data   print "$data->{cd}->{country}\n";   print "$data->{cd}->{artist}\n";   print "$data->{cd}->{price}\n";   print "$data->{cd}->{title}\n";

Output:

Not a HASH reference at D:\learning\perl\t1.pl line 16.

Comment: I googled and found the article(handle single xml record). http://www.go4expert.com/forums/showthread.php?t=812I tested with the article code, it works quite well on my laptop.

Then I created my practice code above to try to access multiple record. but failed. How can I fix it? Thank you.


Viewing all articles
Browse latest Browse all 4

Latest Images

Trending Articles



Latest Images