You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by Stuart D Jackson <st...@jhu.edu> on 2000/07/05 17:34:55 UTC

setNodeValue

I am having aproblem with setting the value of an Element.  I am using 
Document.createElement( String )
to create the Element, but when I try to use
Element.setNodeValue( String ),
I get a Modification not allowed error.  Am I doing something wrong?

I am trying to create a new Element, set its value, add a couple of
Attributes, then add it to a tree.  Thanks a lot.

-Stuart


Re: setNodeValue

Posted by Lars Oppermann <la...@kurtius-looft.com>.
I think what you mean by setting the value of the node is adding a
text-node to this element, so you'll want to appendChild() a text-node
to your Element. The value of the Element itself is the tagname and thus
can't be changed (in fact': you don't want that, otherwise you would
have created it with that name :).
Just call the createTextNode() method of the document to which the new
text-node shall be appended and then append it to your element or do it
in a single step like this:

Element myElemet=myDoc.craeteElement("myelementname");
myElenet.appendChild(myDoc.createTextNode("this is my text node
content"));

In DOM-terms you are appending a node of type text with a value of 'this
is my...' to a node of type element with a value of 'myelementname'.

Bests,
Lars

Stuart D Jackson wrote:
> 
> I am having aproblem with setting the value of an Element.  I am using
> Document.createElement( String )
> to create the Element, but when I try to use
> Element.setNodeValue( String ),
> I get a Modification not allowed error.  Am I doing something wrong?
> 
> I am trying to create a new Element, set its value, add a couple of
> Attributes, then add it to a tree.  Thanks a lot.
> 
> -Stuart
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-dev-help@xml.apache.org