#!/usr/bin/perl use XML::Twig; use strict; use warnings; my $xml = XML::Twig->new( twig_handlers => { '*[text:bookmark]' => \&handler_bookmark } ); # twig_handlers => { 'text:bookmark' => \&handler_bookmark } ); $xml->parse(\*DATA); print qq(\n-\n); $xml->print; exit(0); sub handler_bookmark { my( $twig, $bookmark)= @_; print qq(OK\n); print $bookmark->text; my @bmk = $bookmark->children('text:bookmark'); foreach my $b (@bmk) { my $anchor = $b->att('text:name'); print "Anchor: ", $anchor, "\n"; } } __DATA__ Bar foo Foo bar