in reply to Perl XPath
Your code affects two title nodes at once because your XPath expression matches two title nodes:
/catalog/book/titles/title[ $i+1 ]
You will need to either make your XPath expression match the specific book you are currently modifying:
/catalog/book[ $j ]/titles/title[ $i+1 ]
... or you have to remove the text node from the current element and append your own text node. See XML::LibXML::Element->appendTextChild and XML::LibXML::Node->removeChildNodes:
my $element = ...; $element->removeChildNodes(); $element->appendTextNode("Hello!");
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Perl XPath
by GoForIt (Novice) on Feb 27, 2012 at 19:55 UTC | |
by Corion (Patriarch) on Feb 27, 2012 at 20:10 UTC | |
by ikegami (Patriarch) on Feb 27, 2012 at 21:35 UTC | |
by GoForIt (Novice) on Feb 28, 2012 at 19:26 UTC |