Search code examples
perlxml-twig

Perl XML::Twig Copying without children


Is it possible to use somthing like

my $nodeCopy = $node->copy();

without copying the children? I can't find anything on the page on CPAN about it. But maybe I'm missing something?


Solution

  • Nevermind, I found a way. Going to leave it here if ever somebody else looks for something similar. All you have to do is use cut_children. I did it like this:

    my $nodeCopy = $node->copy();       #copy the node
    $nodeCopy->paste('before', $node);  #paste the node
    $node->cut_children();             #remove children from the original node