http://www.perlmonks.org?node_id=927935


in reply to Re: XML::Twig removing tags from content (XML::Twig)
in thread XML::Twig removing tags from content

Hi Canon, getting closer, but for some reason the children are coming out in the wrong order (reversed?):

Original:

<li class="c2">
	<p class="Number1">In the XYZ pane, select the <span class="c1">PageID</span> ruleset and click the <span class="c1">Lock/Unlock ruleset</span> button. Then expand the
	<span class="c1">PageID</span> ruleset to view the two rules.</p>
</li>

Result:

      <li class="c2"> ruleset to view the two rules.<span class="c1">PageID</span> button. Then expand the
            <span class="c1">Lock/Unlock ruleset</span> ruleset and click the <span class="c1">PageID</span>In the XYZ pane, select the </li>

Thoughts?

Replies are listed 'Best First'.
Re^3: XML::Twig removing tags from content (XML::Twig)
by slugger415 (Monk) on Sep 26, 2011 at 22:27 UTC

    To answer my own question, using reverse seems to fix the problem:

    for my $p ($elt->children('p')) { for my $c (reverse($p->cut_children())) { $c->paste($elt); } $p->delete(); }

    I don't understand why it's needed, but it works.