in reply to XML::Twig and subchildren

Did you try $elt->first_child('LINK_CONFIG')->first_child( 'RELATIONSHIP')? This would give you the element, you can get the content by applying text to it.

Replies are listed 'Best First'.
Re^2: XML::Twig and subchildren
by jfroebe (Parson) on Aug 10, 2004 at 20:45 UTC

    Unfortunately, $elt->first_child() doesn't return an element object... so my $RELATIONSHIP = $elt->first_child('LINK_CONFIG')->first_child('RELATIONSHIP')->text; will fail on compilation with "Can't call method "first_child" on an undefined value".

    Jason

    No one has seen what you have seen, and until that happens, we're all going to think that you're nuts. - Jack O'Neil, Stargate SG-1

      $elt->first_child('LINK_CONFIG') returns an element, unless there is no LINK_CONFIG child. So if the code fails it will be at runtime, not compilation.

      If this is likely to happen then you have to process this case:

      if( my $link_config= $elt->first_child('LINK_CONFIG')) { my $relationship= $link_config->first_child('RELATIONSHIP')->text; + # ... } else { warn "no LINK_CONFIG found\n"; # or any other processing necessary }

        Something so obvious! Must need more caffeine! Thanks!

        No one has seen what you have seen, and until that happens, we're all going to think that you're nuts. - Jack O'Neil, Stargate SG-1