I wanted to build an awesome place for people to discuss module specific issues, but I don't have any more time for this, and there are much better places to discuss Perl-related issues. I'd recommend asking your question on Stack Overflow or on Perl Monks.
If you are looking for a Perl tutorial or Perl-related news, I hope these links will serve you well.
Posted on 2012-03-05 18:47:55.403982-08 by b0sque in response to 13656
Re: Passing XML twig element to another subroutine
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.
Direct Responses: 13661 | Write a response