XML Simple in Perl - Attributes

Home > Search
  by

Let's consider this XML file that contains an attribute called description.

<acme>
  <name description="Main Character">Bugs Bunny</name>
  <name description="Support Character">Elmer Fudd</name>
  <name description="Support Character">Yosemite Sam</name>
</acme>

 

Using the ForceArray => 1 flag.

$cartoon = $xml->XMLin("cartoon.xml", ForceArray => 1 );

 

The value of each attribute can be printed like this.

print $cartoon->{'name'}->[0]->{'description'};
print $cartoon->{'name'}->[1]->{'description'};
print $cartoon->{'name'}->[2]->{'description'};

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter in the box below so that we can be sure you are a human.




Comments