#!/bin/perl -w use strict; use XML::Twig; my $doc= ' e1 e2 e3 '; my $twig= new XML::Twig( twig_roots => { l2 => 1 } twig_handlers => { e2 => \&e2} ); $twig->parse( $doc); sub e2 { my( $t, $e2)= @_; print "ancestors: "; print map { $_->gi . " " } $e2->ancestors; # print l2 doc print "\n"; print "siblings: "; print $e2->prev_sibling->gi; # print e1 print " no next sibling\n" unless $e2->next_sibling; # e3 is not there yet print "purge!\n"; $t->purge; print "ancestors: "; print map { $_->gi . " " } $e2->ancestors; # print l2 doc (still there) print "\n"; print "siblings: "; print " no prev sibling\n" unless $e2->prev_sibling; # e1 is gone print " no next sibling\n" unless $e2->next_sibling; # e3 is still not there }