Output:use strict; use warnings; use XML::LibXML; my $parser = XML::LibXML->new({"encoding" => "utf-8"}); my $doc = $parser->load_xml(string => "<XML> <TestElement>Hello</TestE +lement><TestElement>Some Other Element</TestElement></XML>"); my $qry = "/XML[TestElement='Hello']/TestElement/text()"; my ($node) = $doc->findnodes($qry); if (defined $node) { $node->setData("Bye"); } else { die "no match for $qry"; } print $doc->toString(), "\n";
Note that "Some Other Element" remains unchanged.<?xml version="1.0"?> <XML> <TestElement>Bye</TestElement><TestElement>Some Other Element</T +estElement></XML>
In reply to Re: Modify XML
by richb
in thread Modify XML
by perl@1983
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |