View Single Post
  #1 (permalink)  
Old August 13th, 2009, 01:24 PM
geek.shrek geek.shrek is offline
Authorized User
 
Join Date: Nov 2007
Location: , , .
Posts: 33
Thanks: 2
Thanked 0 Times in 0 Posts
Question XML::Simple parsing xml

Hi,

First, I'm sorry if this is not the right forum.

I'm trying to parse XML file with XML::Simple in perl.

Here's my input
Code:
<Library>
     <book>
            <id>1</id>
            <name>ABC</name>
     </book>
     <book>
            <id>2</id>
            <name>ABC123</name>
     </book>
     <book>
            <id>3</id>
            <name>ABCDEF</name>
     </book>
</Library>
I would like to get the name of id '1'.

Code:
my $LibList = XMLin('library.xml', forcearray=>1, keyattr => ['id']);

my $name = $LibList->{'1'}->{name};
print "Customer id " . $name . "\n";
It doesn't return anything.

Can someone tell me what did I do wrong?

Thanks,
Reply With Quote