OK, so that was a dumb idea. Looking at the source code, it's clear that there's only one implementation for setTextContent() that adjusts its behavior depending on the type of node being operated on. It throws the exception you're seeing only if the node is not a document, document type, element, attribute, entity, entity reference, document fragment, text, CDATA section, comment, processing instruction, or notation node. Since that list includes every node type from the DOM specification, I'm not sure how it's possible to get that exception. Perhaps some routine that setTextContent() calls is throwing it.
 
In your shoes, I'd debug into setTextContent() and see what's going on, in particular, what the type of the node is. Given your code, I don't see how it can be anything other than an element. At the moment, I'm baffled, but I'm sure the problem will be obvious in retrospect.



From: Mannion, Enda [mailto:[EMAIL PROTECTED]
Sent: Wednesday, June 07, 2006 10:25 AM
To: [email protected]
Subject: RE: setNodeValue not working

Sorry to keep pestering on this one,

 

But I just can’t get setTextContent to work for me even when I cast it to an element.

 

 

 

Is there anything else I need to do after I call setTextContent to write the text to the XML file?

 

 

My current call to setTextContent throws an exception with code=9 = NOT_SUPPORTED_ERR.

 

 

Enda

 


From: Jesse Pelton [mailto:[EMAIL PROTECTED]
Sent: 06 June 2006 18:27
To: [email protected]
Subject: RE: setNodeValue not working

 

setTextContent isn't supported for DOMNode, which is the class you're using. Try casting aNode to a DOMElement pointer before calling setTextContent(). This is safe because you've already checked that it really is an element node.

 

 

                  ((DOMElement*)aNode)->setTextContent(DOMStr("New Text"));


From: Mannion, Enda [mailto:[EMAIL PROTECTED]
Sent: Tuesday, June 06, 2006 12:51 PM
To: [email protected]
Subject: RE: setNodeValue not working

Gareth,

 

Is it possible for you to explain what you mean here??

 

> Yes it is common. Its likely because you are not using on an element.

> Not all node types can be set this way.

 

Please. Can you give an example of what you are telling me or even correct my code:

 

 

 

 

 

DOMNodeList* list = docNode->getChildNodes();

DOMNode* aNode = NULL;

 

 

for(int i = 0; i<list->getLength(); i++)

{

 

aNode = list->item(i);

 

 

if(DOMNode::ELEMENT_NODE == aNode->getNodeType())

{

            char* nodeName = XMLString::transcode(aNode->getNodeName());

            if(strcmp(nodeName, szTag.c_str()) == 0)

            {

                  aNode->setTextContent(DOMStr("New Text"));    // ß I want this to work

                  break;

            }

}

}

 

 

Also, I had exception handling code set and the exception code returned was 9 = Not Supported Error

 

 

Thanks,

Enda

                       

 

-----Original Message-----
From: Gareth Reakes [mailto:[EMAIL PROTECTED]
Sent: 06 June 2006 16:07
To: [email protected]
Subject: Re: setNodeValue not working

 

Hi,

 

Mannion, Enda wrote:

> Thanks,

>

> I have read the function spec and the exception is of type DOMException,

>

> The msg content of the exception class was not returned so I am not sure

> if it refers to this

>

> DOMException  NO_MODIFICATION_ALLOWED_ERR: Raised when the node is

> readonly. 

 

Have you tried catching the DOMException and looking to see what type it is?

 

 

 

> Is it possible to see a sample of setTextContent() being called, surely

> this is a very common function.

 

Yes it is common. Its likely because you are not using on an element.

Not all node types can be set this way.

 

>

> Is this the standard way to update text in an XML tag?

 

This or add new children.

 

 

Gareth

 

--

Gareth Reakes, Managing Director           Embrace Mobile

+44-1865-811197              http://www.embracemobile.com

 

---------------------------------------------------------------------

To unsubscribe, e-mail: [EMAIL PROTECTED]

For additional commands, e-mail: [EMAIL PROTECTED]

 

Reply via email to