Frell! (*slaps myself for using Farcape reference*)

I read the specification again. And I think I got it this time.

http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/core.html#Node3-textC
ontent

"When it is defined to be null, setting it has no effect."

Content is defined to be null for DOCUMENT_NODE, DOCUMENT_TYPE_NODE and
NOTATION_NODE. Which solves the whole problem I had.
I like the do nothing solution. To bad that the same solution doesn't work
on all kinds of work. :)

Here is the new code.

/ Erik


void             DOMNodeImpl::setTextContent(const XMLCh* textContent){
        DOMNode *thisNode = castToNode(this);
  switch (thisNode->getNodeType()) {
    case DOMNode::ELEMENT_NODE:
    case DOMNode::ENTITY_NODE:
    case DOMNode::ENTITY_REFERENCE_NODE:
    case DOMNode::DOCUMENT_FRAGMENT_NODE:
    {
      if (isReadOnly())
        throw DOMException(DOMException::NO_MODIFICATION_ALLOWED_ERR, 0);

      // Remove all childs
      DOMNode* current = thisNode->getFirstChild();
      while (current != NULL) {
        thisNode->removeChild(current);
        current = thisNode->getFirstChild();
      }
      if (textContent != NULL) {
        // Add textnode containing data
        current =
((DOMDocumentImpl*)thisNode->getOwnerDocument())->createTextNode(textContent
);
        thisNode->appendChild(current);
      }
    }
    break;

    case DOMNode::ATTRIBUTE_NODE:
    case DOMNode::TEXT_NODE:
    case DOMNode::CDATA_SECTION_NODE:
    case DOMNode::COMMENT_NODE:
    case DOMNode::PROCESSING_INSTRUCTION_NODE:
      if (isReadOnly())
        throw DOMException(DOMException::NO_MODIFICATION_ALLOWED_ERR, 0);

      thisNode->setNodeValue(textContent);
    break;

    case DOMNode::DOCUMENT_NODE:
    case DOMNode::DOCUMENT_TYPE_NODE:
    case DOMNode::NOTATION_NODE:
    break;

    default:
      throw DOMException(DOMException::NOT_SUPPORTED_ERR, 0);
  }
}



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

Reply via email to