Ejemplo n.º 1
0
void XercesUpdateFactory::applyRename(const PendingUpdate &update, DynamicContext *context)
{
  const XercesNodeImpl *nodeImpl = (const XercesNodeImpl*)update.getTarget()->getInterface(Item::gXQilla);
  DOMNode *domnode = const_cast<DOMNode*>(nodeImpl->getDOMNode());

  ATQNameOrDerived *qname = (ATQNameOrDerived*)update.getValue().first().get();

  if(domnode->getNodeType() == DOMNode::PROCESSING_INSTRUCTION_NODE) {
    DOMProcessingInstruction *newPI = domnode->getOwnerDocument()->
      createProcessingInstruction(qname->getName(), domnode->getNodeValue());
    domnode->getParentNode()->replaceChild(newPI, domnode);
    domnode = newPI;
  }
  else {
    // If $newName has an implied namespace binding that conflicts with an existing namespace binding
    // in the namespaces property of $target, a dynamic error is raised [err:XUDY0024].

    // If $target has a parent, and $newName has an implied namespace binding that conflicts with a
    // namespace binding in the namespaces property of parent($target), a dynamic error is raised [err:XUDY0024].

    domnode->getOwnerDocument()->renameNode(domnode, qname->getURI(), qname->getName());
    if(qname->getURI() != 0 && *qname->getURI() != 0)
      domnode->setPrefix(qname->getPrefix());

    removeType(domnode);
  }

  // Deliberately create a new XercesNodeImpl, since the PI is actually
  // replaced, not just renamed, meaning it is no longer attached to the tree
  addToPutSet(nodeImpl, &update, context);
}
Ejemplo n.º 2
0
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, GetDOMNodeMemoryManager);

                // 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, GetDOMNodeMemoryManager);

            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, GetDOMNodeMemoryManager);
    }
}