Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: XML::Twig removing tags from content

by Lotus1 (Curate)
on Sep 27, 2011 at 16:56 UTC ( #928120=note: print w/replies, xml ) Need Help??

in reply to XML::Twig removing tags from content

Here is one way to do this with XML::LibXML.

#!/usr/bin/perl use warnings; use strict; use XML::LibXML; my $xmlfile = 'test.xml'; my $parser = XML::LibXML->new(); my $doc = $parser->parse_file($xmlfile); my ($li_node) = $doc->findnodes("//li"); my ($p_element) = $doc->findnodes("//li/p"); foreach ($p_element->childNodes) { $li_node->appendChild( $_ ); } $li_node->removeChild( $p_element ); print $doc->toString;

Contents of test.xml:

<?xml version="1.0" encoding="utf-8"?> <li> <p> Some <b>text<c1> here</c1></b> </p> </li>


<?xml version="1.0" encoding="utf-8"?> <li> Some <b>text<c1> here</c1></b> </li>

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://928120]
[atcroft]: PriNet: Those code bits worked for me, with test hashes, but I didn't test it with more than a few simple test cases. *shrug* Had hoped it would help, at least.
[PriNet]: i think i found the problem, the "source" array that sets the individual key values isn't being cleared, it's keeping the previous values...
[atcroft]: PriNet: You might consider posting a small, self-contained snippet of that segment of your code, and see if someone else has a better idea.....
[atcroft]: PriNet: Ahhh... interesting.

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2017-06-28 03:12 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (619 votes). Check out past polls.