Hello Monks, I have some XML such as this, where the linktext element contains a combination of text and other elements:

<citreference id="mycite"> <linktext><keyword conref="ds"/> support for IPv6 addresses</linktext> </citreference>

I can capture this with XML::Twig by creating an array, and referencing it thusly, where $citref is my handler:

my(@children) = $citref->first_child('linktext')->children; $linktext{$citref->att('id')} = \@children;

Simple enough. The question I'm having is how to extract that into another element elsewhere? I couldn't find that in the documentation. Something like:

my($h) = $linktext{'xxx'}; # the xxx is the appropriate id for the has +h $newcontext->set_text(\@$h); # $newcontext is 'xref' in this case

That doesn't work right, but I'm getting something in the output:

<xref>ARRAY(0x4128670)</xref>

I suspect the $e->set_text() function only applies to text (not elements) and I suspect if there's more than one text segment each will clobber the previous. Hence I'm cautious about iterating through the array.

Any tips on how to do this? Thank you.


In reply to XML::Twig - setting text and elements by slugger415

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.