in reply to Re^2: Perl XPath
in thread Perl XPath

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.

Replies are listed 'Best First'.
Re^4: Perl XPath
by ikegami (Patriarch) on Feb 27, 2012 at 21:35 UTC
    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.
Re^4: Perl XPath
by GoForIt (Novice) on Feb 28, 2012 at 19:26 UTC

    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?