DOMNode* DOMElementImpl::rename(const XMLCh* namespaceURI, const XMLCh* name) { DOMDocumentImpl* doc = (DOMDocumentImpl*) fParent.fOwnerDocument; if (!namespaceURI || !*namespaceURI) { fName = doc->getPooledString(name); fAttributes->reconcileDefaultAttributes(getDefaultAttributes()); // and fire user data NODE_RENAMED event castToNodeImpl(this)->callUserDataHandlers(DOMUserDataHandler::NODE_RENAMED, this, this); return this; } else { // create a new ElementNS DOMElementNSImpl* newElem = (DOMElementNSImpl*)doc->createElementNS(namespaceURI, name); // transfer the userData doc->transferUserData(castToNodeImpl(this), castToNodeImpl(newElem)); // remove old node from parent if any DOMNode* parent = getParentNode(); DOMNode* nextSib = getNextSibling(); if (parent) { parent->removeChild(this); } // move children to new node DOMNode* child = getFirstChild(); while (child) { removeChild(child); newElem->appendChild(child); child = getFirstChild(); } // insert new node where old one was if (parent) { parent->insertBefore(newElem, nextSib); } // move specified attributes to new node newElem->fAttributes->moveSpecifiedAttributes(fAttributes); // and fire user data NODE_RENAMED event castToNodeImpl(newElem)->callUserDataHandlers(DOMUserDataHandler::NODE_RENAMED, this, newElem); return newElem; } }
DOMNode* DOMAttrImpl::rename(const XMLCh* namespaceURI, const XMLCh* name) { DOMElement* el = getOwnerElement(); DOMDocumentImpl* doc = (DOMDocumentImpl*)fParent.fOwnerDocument; if (el) el->removeAttributeNode(this); if (!namespaceURI || !*namespaceURI) { fName = doc->getPooledString(name); if (el) el->setAttributeNode(this); // and fire user data NODE_RENAMED event castToNodeImpl(this)->callUserDataHandlers(DOMUserDataHandler::NODE_RENAMED, this, this); return this; } else { // create a new AttrNS DOMAttr* newAttr = doc->createAttributeNS(namespaceURI, name); // transfer the userData doc->transferUserData(castToNodeImpl(this), castToNodeImpl(newAttr)); // move children to new node DOMNode* child = getFirstChild(); while (child) { removeChild(child); newAttr->appendChild(child); child = getFirstChild(); } // reattach attr to element if (el) el->setAttributeNodeNS(newAttr); // and fire user data NODE_RENAMED event castToNodeImpl(newAttr)->callUserDataHandlers(DOMUserDataHandler::NODE_RENAMED, this, newAttr); return newAttr; } }