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>

In reply to Re: xml::twig twig_roots / ignore_elts by tangent
in thread xml::twig twig_roots / ignore_elts by dimitarsh1

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.