> Given a DOM Document object that has been parsed from an XML file, I am
> using org.apache.xpath.XPathAPI to selectSingleNode for modification.
> Unfortunately, the returned node is static. Is there a way to modify
> the returned node such that the changes are propagated back into the
> Document object?
This works:
http://www-128.ibm.com/developerworks/library/x-domjava/listing3.html
public static Node setValue(Node startNode, String value, String xql)
throws Exception
{
Node targetNode = XPathAPI.selectSingleNode( startNode,xql );
NodeList children = targetNode.getChildNodes();
int index = 0;
int length = children.getLength();
// Remove all of the current contents
for(index = 0; index < length; index++) {
targetNode.removeChild( children.item( index ) );
}
// Add in the new value
Document doc = startNode.getOwnerDocument();
targetNode.appendChild( doc.createTextNode(value) );
return targetNode;
}