in reply to xml::twig twig_roots / ignore_elts

I don't think you can get ignore_elts to work the way you want. You could write a handler to delete the titles you want to skip:
my $sel = 'title'; my $twig = XML::Twig->new( pretty_print => 'indented', twig_roots => { "$sel" => \&parse_title }, ); $twig->parsefile('1.xml'); $twig->print; sub parse_title { my ($t,$title) = @_; $title->delete if $title->get_xpath( 'name/fnm[@letter="a"]' ); }
Output using your example XML:
<?xml version="1.0"?> <titles> <title id="1">testing<name><snm>Houston</snm>, <fnm letter="c">Carl< +/fnm></name><g>69</g><ppg>20.1</ppg><rpg>3.4</rpg><apg>2.8</apg><blk> +14</blk></title> <title id="3">testign <name>Houston <fnm j="b">Bob</fnm><g>49</g><title> testing the sub title in title </title><title> this is pcdata in subtitle <title> second sub level </title></title></name></title> </titles>

Replies are listed 'Best First'.
Re^2: xml::twig twig_roots / ignore_elts
by dimitarsh1 (Novice) on Oct 26, 2015 at 20:38 UTC

    Dear tangent,

    thank you very much for the response. I guess that's the only way to go... I tried also some regexes for the title_roots but it didn't work.

    If there are other ways to condition based on children nodes, I'd like to learn about it.

    Thanks a lot, once again.