in reply to XML::Twig - setting text and elements

What is the xml that you want to create? (yes I realize there is maybe a word description of what you want, but actual xml is easier to interpret)
  • Comment on Re: XML::Twig - setting text and elements

Replies are listed 'Best First'.
Re^2: XML::Twig - setting text and elements ( reparent move cut detach )
by Anonymous Monk on Sep 08, 2015 at 23:35 UTC

    So dom style http://xmltwig.org

    #!/usr/bin/perl -- use strict; use warnings; use XML::Twig; my $t = XML::Twig->new( pretty_print => 'indented' ); $t->xparse(q{<roooooo> <citreference id="mycite"> <linktext> <keyword conref="ds"/> support for IPv6 addresses</linktext> </citreference> <moops></moops> </roooooo>}); $t->print; my( @links ) = $t->findnodes( '//linktext' ); my( $moops ) = $t->findnodes( '//moops' ); for my $link ( @links ){ print $link->path, "\n"; $link->cut->paste( $moops ); } $t->print; __END__ <roooooo> <citreference id="mycite"> <linktext><keyword conref="ds"/> support for IPv6 addresses</linkt +ext> </citreference> <moops></moops> </roooooo> /roooooo/citreference/linktext <roooooo> <citreference id="mycite"></citreference> <moops> <linktext><keyword conref="ds"/> support for IPv6 addresses</linkt +ext> </moops> </roooooo>

      Thank you for the suggestion. My solution was this:

      $topicref->set_content(@$h);
Re^2: XML::Twig - setting text and elements
by slugger415 (Monk) on Sep 09, 2015 at 16:40 UTC

    Sorry i wasn't clear about that. I'd like everything inside of linktext to go inside of xref.

    <xref><keyword conref="ds"/> support for IPv6 addresses</xref>

    I also didn't mention there might be other elements midway.

    <linktext><keyword conref="ds"/> support for <b>IPv6</b> addresses</li +nktext>

    So I need to iterate through the @children array and handle each child, which is either text or an element.

    thanks, will try these other suggestions.