tng 2002/09/17 05:42:22 Modified: c/src/xercesc/dom/impl DOMDocumentImpl.cpp Log: DOM Fix: 1. Make sure the passed in name is not null before creating the node. 2. Also allow replacing a document type node. Revision Changes Path 1.22 +28 -14 xml-xerces/c/src/xercesc/dom/impl/DOMDocumentImpl.cpp Index: DOMDocumentImpl.cpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/dom/impl/DOMDocumentImpl.cpp,v retrieving revision 1.21 retrieving revision 1.22 diff -u -r1.21 -r1.22 --- DOMDocumentImpl.cpp 21 Aug 2002 20:58:31 -0000 1.21 +++ DOMDocumentImpl.cpp 17 Sep 2002 12:42:21 -0000 1.22 @@ -261,7 +261,7 @@ DOMAttr *DOMDocumentImpl::createAttribute(const XMLCh *nam) { - if(!isXMLName(nam)) + if(!nam || !isXMLName(nam)) throw DOMException(DOMException::INVALID_CHARACTER_ERR,0); return new (this, DOMDocumentImpl::ATTR_OBJECT) DOMAttrImpl(this,nam); }; @@ -290,7 +290,7 @@ DOMDocumentType *DOMDocumentImpl::createDocumentType(const XMLCh *nam) { - if (!isXMLName(nam)) + if (!nam || !isXMLName(nam)) throw DOMException( DOMException::INVALID_CHARACTER_ERR, 0); @@ -304,7 +304,7 @@ const XMLCh *publicId, const XMLCh *systemId) { - if (!isXMLName(qualifiedName)) + if (!qualifiedName || !isXMLName(qualifiedName)) throw DOMException( DOMException::INVALID_CHARACTER_ERR, 0); @@ -315,7 +315,7 @@ DOMElement *DOMDocumentImpl::createElement(const XMLCh *tagName) { - if(!isXMLName(tagName)) + if(!tagName || !isXMLName(tagName)) throw DOMException(DOMException::INVALID_CHARACTER_ERR,0); return new (this, DOMDocumentImpl::ELEMENT_OBJECT) DOMElementImpl(this,tagName); @@ -332,7 +332,7 @@ DOMEntity *DOMDocumentImpl::createEntity(const XMLCh *nam) { - if (!isXMLName(nam)) + if (!nam || !isXMLName(nam)) throw DOMException( DOMException::INVALID_CHARACTER_ERR, 0); @@ -343,7 +343,7 @@ DOMEntityReference *DOMDocumentImpl::createEntityReference(const XMLCh *nam) { - if (!isXMLName(nam)) + if (!nam || !isXMLName(nam)) throw DOMException( DOMException::INVALID_CHARACTER_ERR, 0); @@ -354,7 +354,7 @@ DOMNotation *DOMDocumentImpl::createNotation(const XMLCh *nam) { - if (!isXMLName(nam)) + if (!nam || !isXMLName(nam)) throw DOMException( DOMException::INVALID_CHARACTER_ERR, 0); @@ -366,7 +366,7 @@ DOMProcessingInstruction *DOMDocumentImpl::createProcessingInstruction( const XMLCh *target, const XMLCh *data) { - if(!isXMLName(target)) + if(!target || !isXMLName(target)) throw DOMException(DOMException::INVALID_CHARACTER_ERR,0); return new (this, DOMDocumentImpl::PROCESSING_INSTRUCTION_OBJECT) DOMProcessingInstructionImpl(this,target,data); }; @@ -431,6 +431,10 @@ ) throw DOMException(DOMException::HIERARCHY_REQUEST_ERR,0); + // if the newChild is a documenttype node created from domimplementation, set the ownerDoc first + if ((newChild->getNodeType() == DOMNode::DOCUMENT_TYPE_NODE) && !newChild->getOwnerDocument()) + ((DOMDocumentTypeImpl*)newChild)->setOwnerDocument(this); + fParent.insertBefore(newChild,refChild); // If insert succeeded, cache the kid appropriately @@ -443,6 +447,18 @@ }; +DOMNode* DOMDocumentImpl::replaceChild(DOMNode *newChild, DOMNode *oldChild) { + if(oldChild->getNodeType() == DOMNode::DOCUMENT_TYPE_NODE) + fDocType=0; + + insertBefore(newChild, oldChild); + // changed() already done. + + if(oldChild->getNodeType() == DOMNode::DOCUMENT_TYPE_NODE) + return fParent.removeChild(oldChild); + else + return removeChild(oldChild); +} bool DOMDocumentImpl::isXMLName(const XMLCh *s) { @@ -493,7 +509,7 @@ DOMElement *DOMDocumentImpl::createElementNS(const XMLCh *fNamespaceURI, const XMLCh *qualifiedName) { - if(!isXMLName(qualifiedName)) + if(!qualifiedName || !isXMLName(qualifiedName)) throw DOMException(DOMException::INVALID_CHARACTER_ERR,0); //XMLCh * pooledTagName = this->fNamePool->getPooledString(qualifiedName); return new (this, DOMDocumentImpl::ELEMENT_NS_OBJECT) DOMElementNSImpl(this, fNamespaceURI, qualifiedName); @@ -504,7 +520,7 @@ const XMLSSize_t lineNo, const XMLSSize_t columnNo) { - if(!isXMLName(qualifiedName)) + if(!qualifiedName || !isXMLName(qualifiedName)) throw DOMException(DOMException::INVALID_CHARACTER_ERR,0); return new (this) XSDElementNSImpl(this, fNamespaceURI, qualifiedName, lineNo, columnNo); @@ -514,7 +530,7 @@ DOMAttr *DOMDocumentImpl::createAttributeNS(const XMLCh *fNamespaceURI, const XMLCh *qualifiedName) { - if(!isXMLName(qualifiedName)) + if(!qualifiedName || !isXMLName(qualifiedName)) throw DOMException(DOMException::INVALID_CHARACTER_ERR,0); return new (this, DOMDocumentImpl::ATTR_NS_OBJECT) DOMAttrNSImpl(this, fNamespaceURI, qualifiedName); } @@ -667,8 +683,6 @@ DOMNode* DOMDocumentImpl::getPreviousSibling() const {return fNode.getPreviousSibling (); }; bool DOMDocumentImpl::hasChildNodes() const {return fParent.hasChildNodes (); }; void DOMDocumentImpl::normalize() {fParent.normalize (); }; - DOMNode* DOMDocumentImpl::replaceChild(DOMNode *newChild, DOMNode *oldChild) - {return fParent.replaceChild (newChild, oldChild); }; bool DOMDocumentImpl::isSupported(const XMLCh *feature, const XMLCh *version) const {return fNode.isSupported (feature, version); }; void DOMDocumentImpl::setPrefix(const XMLCh *prefix) {fNode.setPrefix(prefix); };
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]