Hi--

I've been using $foo->paste('last_child', $bar) to graft subtrees onto a larger tree and it's been working as expected. That is, the paste will *copy* the contents of foo onto bar.

Now, it seems that the paste is using a pointer of foo to the bar tree. Since foo is populated within a loop with a "new" for foo at the start of the iteration, each time the new is hit, the contents of the prior foo (now attached to bar) vanishes. What persists on bar is only the value of foo.

Strangely, the population of the nodes within foo is done via the same paste/last-child mechanism, but this works as expected.

Can someone clarify this? Or am I doing something wrong? Thanks.

use XML::Twig; my $objectsTwig = new XML::Twig; $objectsTwig->parse('<objects />'); $OBJECTS_ROOT = $objectsTwig->root; do { my $object = new XML::Twig; $object->parse('<object />'); $OBJECT_ROOT = $object->root; ... Add elements to <object> node $OBJECT_ROOT->paste('last_child', $OBJECTS_ROOT); } until (yada...);

In reply to XML-Twig paste by zuma53

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.