in reply to Re: Perl XPath
in thread Perl XPath

Hi,

Thanks for your response.

Is there a way that I could pass a node to setNodeText()? I'm able to retrieve the different node values using getNodeText() method by passing the $node parameter. I'm assuming that I could do the same for setNodeText() method but somehow the method doesn't recognize the $node in XPath.

Thanks

Replies are listed 'Best First'.
Re^3: Perl XPath
by Corion (Patriarch) on Feb 27, 2012 at 20:10 UTC

    I assume once you have the XML::LibXML::Text node, you can use ->replaceData or ->setData to change the values. But I've never done anything like it using XML::LibXML, so you'll have to find out whether it works yourself.

      The problem with that route is that it fails for elements with zero or more than one text child nodes. That may not be an issue here.

      I used the below approach to replace the node value.

      my $parent = $node->getParentNode(); $parent->removeChild($node); my $element = XML::XPath::Node::Element->new('category +'); my $attr = XML::XPath::Node::Attribute->new($key, $val +ue); $element->appendAttribute($attr); $result = $parent->appendChild($element);

      It works fine but the execution time is long. I've about 1000 nodes to change and the script takes 40 minutes to finish.

      Is this a bad approach?