objA fooA fooB objB fooA fooB #### 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_roots => { # following gives "unrecognized expression in handler" error #q(myconfig/myobj[uniqueName="objA"]/myattributes/attribB) => \&getfoo, q(myconfig/myobj/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";