in reply to Lib::XML removing Node
I need to remove one of the <new> nodes.
...is a difficult thing to put into code. Either of two? Duplicate tags? Tags with duplicate values? Last one? All after first? Here's snippet that does the last one. Use the docs -- XML::LibXML -- to adjust as needed.
use warnings; use strict; use XML::LibXML; my $doc = XML::LibXML->new->parse_fh(\*DATA); # or ->parse_file("news.xml") my $root = $doc->getDocumentElement; my @nodes = $root->findnodes("new"); $root->removeChild($nodes[-1]); # Remove the last. print $doc->serialize();# Or... print $root->serialize(); __DATA__ <listaNews> <new> blah blah blah </new> <new> blah blah blah </new> </listaNews>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Lib::XML removing Node
by ikegami (Patriarch) on Jun 13, 2009 at 22:03 UTC | |
|
Re^2: Lib::XML removing Node
by smattiuz (Initiate) on Jun 13, 2009 at 21:56 UTC | |
by Your Mother (Archbishop) on Jun 13, 2009 at 23:02 UTC | |
by smattiuz (Initiate) on Jun 17, 2009 at 13:13 UTC |