in reply to Modify XML

Here's how I would do it with XML::LibXML. The query searches for the TestElement with "Hello" and changes it to "Bye".
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";
Output:
<?xml version="1.0"?> <XML> <TestElement>Bye</TestElement><TestElement>Some Other Element</T +estElement></XML>
Note that "Some Other Element" remains unchanged.