There is no level2_children method, but you might be able to use descendants, or just use a map. Note that you can use a regexp (which will be applied to the element name) as a condition. I am sure there are other ways as well, the condition can be a code ref for example, so you could test exactly what you want in there.
Anyway, here is some example code:
#!/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)$/) } @res
+ults;
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__
<rra>
<child id="child_01">
<cdp_prep id="cdp_prep_01">content</cdp_prep>
<database id="database_01">content</database>
<other id="other_01">content</other>
<cdp_prep id="cdp_prep_02">
<other id="other_02">content</other>
</cdp_prep>
</child>
<child id="child_02">
<other id="other_03">content</other>
<database id="database_02">content</database>
</child>
<child id="child_03">
<other id="other_04"><other id="other_05">content</other></other>
</child>
</rra>
|