You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@xml.apache.org by Wi...@techsol.com on 2000/06/21 00:07:40 UTC

question on setNodeValue() and appending nodes


Hello all;
  I am attempting to append a newly created node to an existing DOM tree, then
set the value of that node.
The adding of the node seems to work fine, but I am unable to set the value of
the node.
Environment is xerces ver 1.0.4, Win 2000, and java 1.2.

//************************************************
// myDom is existing good DOM Tree in memory.
Element errorNode = MyDOM.createElement("error");
errorNode.setNodeValue("Some_Error");
Node myNode = XPathAPI.selectSingleNode(MyDOM , "//commands/command/response");
myNode.appendChild(errorNode);
//*************************************************


After this code is ran; sure enough there is a new error node in the right place
 in the DOM Tree, but it doesn't have any value. I have tried perhaps 20 small
variations on this code-- no worky...
Any insight?

Cheers, Will



Re: question on setNodeValue() and appending nodes

Posted by Andy Clark <an...@apache.org>.
Sean Kelly wrote:
> errorNode.appendChild(MyDOM.createTextNode("Some_Error"));

Sean is right. Element nodes do not have a node value. They
contain text node children which have node values.

-- 
Andy Clark * IBM, JTC - Silicon Valley * andyc@apache.org

Re: question on setNodeValue() and appending nodes

Posted by Sean Kelly <ke...@mail2a.jpl.nasa.gov>.
William ... try this:

errorNode.appendChild(MyDOM.createTextNode("Some_Error"));

--Sean