Hi all.
With the long discussion about getTextContent going I was reading the DOM
specification and put the code together for setTextContent as well. You
can't have one without the other. They are like peas and carrots (*slapping
myself for using Forrest Gump reference... again*). Anyway here it is in the
normal format: Compiled but untested. Please verify. I had one issue though
and it is commented in the code.
Regards
Erik Rydgren
Mandarinen systems AB
Sweden
void DOMNodeImpl::setTextContent(const XMLCh* textContent){
if (textContent != NULL) {
if (isReadOnly())
throw DOMException(DOMException::NO_MODIFICATION_ALLOWED_ERR, 0);
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:
{
// 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:
thisNode->setNodeValue(textContent);
break;
case DOMNode::DOCUMENT_NODE:
case DOMNode::DOCUMENT_TYPE_NODE:
case DOMNode::NOTATION_NODE:
// Not quite sure what to do here, the specification is unclear on
this point.
// Issue textContent-5:
// Setting the text property on a Document, Document Type, or
Notation node is an error for MS. How do we expose it? Exception? Which one?
// Resolution: (teleconference 23 May 2001) consistency with
nodeValue. Remove Document from the list.
// What list? And consistency with setNodeValue? I do not
understand. I'm setting the node value. Consistent enough? :)
thisNode->setNodeValue(textContent);
break;
default:
throw DOMException(DOMException::NOT_SUPPORTED_ERR, 0);
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]