I am trying to replace some nodes value in XML using the XML:LibXML file parser from user input.
Example XML
<header> <id x_id="1"> <a></a> <b></b> <c>NA</c> </id> </header>
Code:
use strict; use warnings; use XML::LibXML; print "Please specify node c content\n"; my $node_c = <STDIN>; chomp $node_c; my $template = "xx.xml"; my $parser = XML::LibXML->new(); my $doc = $parser->parse_file($template); my($object0) = $doc->findnodes("/header/id/c/text()"); my $text0 = XML::LibXML::Text->new($node_c); $object0->replaceNode($text0);
Currently my code is working, but it somehow removed and from the xml when I tried to replace Node b content if both nodes are empty. If there is some value in node a or b, it works fine.
In reply to XML replacenode by michael99
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |