#!/usr/bin/perl -lw use strict; use XML::Twig; my $t= XML::Twig->new( pretty_print => 'indented', error_context => 1) ->parse( \*DATA); my $rra= $t->root; { print "results in document order:"; my @results= map { $_, $_->children( qr/cdp_prep|database/) } $rra->children; print $_->id foreach (@results); } { print "results by level then document order:"; my @results= $rra->children; push @results, map { $_->children( qr/^(cdp_prep|database)$/) } @results; print $_->id foreach (@results); } { # works only if cdp_prep and database elements can only be found as # grand-children of rra print "results using descendants:"; print $_->id foreach ( $rra->children, $rra->descendants( qr/^(cdp_prep|database)$/) ); } __DATA__ content content content content content content content