thanks. that solved the problem with the missing parents. I still have the problem with how to select on a specific node. I'm still getting two nodes recognized. I did correct one typo with the object name, and I no longer get a parsing error, but I still cant figure out how to select the specific myobj that I'm looking for. modified example (got rid of spaces in demo.xml uniqueName node, and added the '@' in front of uniqueName in the handler filter.
use strict; use warnings; use English; use XML::Twig; my $xmlFile = "demo.xml"; my $t = XML::Twig->new( keep_atts_order => 1, pretty_print => 'indented_a', twig_handlers => { q(myconfig/myobj[@uniqueName=objA]/myattributes/attribB) = +> \&getfoo, } ); $t->parsefile( $xmlFile ); $t->print; exit 0; sub getfoo { my ($t, $e) = @_; print "text=", $e->text(), "' tag='", $e->tag(), "' path='", $e->path(), "' parentTag='", $e->parent->tag(), "'\n"; }
output:
text= fooB ' tag='attribB' path='/myconfig/myobj/myattributes/attribB' + parentTag='myattributes' text= fooB ' tag='attribB' path='/myconfig/myobj/myattributes/attribB' + parentTag='myattributes' <myconfig> <myobj> <uniqueName>objA</uniqueName> <myattributes> <attribA> fooA </attribA> <attribB> fooB </attribB> </myattributes> </myobj> <myobj> <uniqueName>objB</uniqueName> <myattributes> <attribA> fooA </attribA> <attribB> fooB </attribB> </myattributes> </myobj> </myconfig>
In reply to Re^2: XML::Twig correct parent, xpath filter
by dcbecker
in thread XML::Twig correct parent, xpath filter
by dcbecker
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |