|
Hey mirod,
Good catch. I'm not sure what I was thinking when I wrote the subroutine. I remembered the concept of shift after I posted. I appreciate the response.
So, second question, and hopefully it's not stupid (like the above, lol). Using this module, I understand that if I had XML that looked like:
<parent>
<name>Anakin</name>
<child>
<name>Luke</name>
<grandchild weapon="lightsaber">
<name>Ben</name>
</grandchild>
</child>
</parent>
If I wanted to get the name of the grandchild element, I'd could, for example, do a new twig and set the twig root to $twig = new XML::Twig( TwigRoots => { 'parent/child/grandchild' => 1 } );
$twig->parsefile($file);
$grandchild = $twig->root;
$name = $grandchild->first_child('name')->text;
print "\n" . $name . "\n";
But, what do I do if I want to get the weapon ATTRIBUTE?? I understand how to get child elements and their text value, but I don't understand how to get the attributes of an element. I've been reading the cpan documentation. Would something like this work? (code continues from the above)
$weapon = $grandchild->att('weapon')->text;
?? For what it's worth, I've definitely tried the above, and anything else I can think of. I can't figure out for the life of me how to get a specific attribute's text value. |