I was in the middle of writing a long explanation on why this is normal, when it occured to me to try your code, and apparently it works just fine in XML::Twig 3.32. Which is completely wrong (not to mention baffling!). So I think I need to investigate this one a bit.

In any case the gist of the explanation was that XML::Twig works by storing trees. In order to ensure that even when twig_roots is used, it always store the root of the document. Which flush (should!) duly print when asked to. If you just use print instead of flush, then you should get what you want (and the subsequent purge should get rid of the element anyway, so you shouldn't see any increase in memory usage).

Does that help?In any case it looks like you helped me find a regression in the code, so thanks a lot.


In reply to Re: XML Twig - Isolate Element by mirod
in thread XML Twig - Isolate Element by zacc

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.