in reply to Re: XML::Twig - can't find my uncle!
in thread XML::Twig - can't find my uncle!

OK, let's clear some misconceptions about XML::Twig with some explanations and a bit of code (I'll add this to the doc of the module for next version):

Now for something completely similar:

#!/bin/perl -w use strict; use XML::Twig; my $doc= '<doc> <l1> <l2> <e1>e1</e1> <e2>e2</e2> <e3>e3</e3> </l2> </l1> </doc>'; 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 t +here 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 }