Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Monks i need to cut a element with children and paste in another location. I tried using XML::Twig. But i could not able to get correct output. I have shown below what i tried and sample example. where am i going wrong?

input: ------ <test> <author> <name><snm>surname</snm><fnm>firstname</fnm></name> </author> <player> <name><snm>surname</snm><fnm>firstname</fnm></name> </player> <some> <here>here some text</here> </some> </test> output: ------- <test> <player> <name><snm>surname</snm><fnm>firstname</fnm></name> </player> <some> <here>here some text</here> <author> <name><snm>surname</snm><fnm>firstname</fnm></name> </author> </some> </test> my $twig = new XML::Twig( pretty_print = +> 'indented' + ); $twig->parse($input); my $pl = XML::Twig::Elt->new("$place"); for ($twig->get_xpath($path)) { $_->cut ; $_->paste('last_child', $pl) ; } $input = $twig->sprint;

Replies are listed 'Best First'.
Re: XML::Twig 'cut' and 'paste'
by Herkum (Parson) on Jun 09, 2006 at 16:23 UTC

    Considering you did not even post code that works, you are limiting the amount of help you can get.

    In addition you don't explain what you are trying to do, which is another problem. It makes it hard to explain what is wrong with your thinking when I cannot even figure what you think is wrong with your (broken) code fragment.

      I just want to 'cut' the <author> part and place it inside the <some> tag.

      cut this part: <author> <name><snm>surname</snm><fnm>firstname</fnm></name> </author> Paste here: <some> <author> <name><snm>surname</snm><fnm>firstname</fnm></name> </author> </some>

      How to achieve this?