tng 2002/09/17 06:11:48 Modified: c/src/xercesc/dom/impl DOMAttrImpl.cpp DOMAttrImpl.hpp Log: DOM Fix: the child nodes of the Attr node may be either Text or EntityReference nodes, so we need to consider the EntityReference nodes case when retrieving the node value. Revision Changes Path 1.9 +34 -23 xml-xerces/c/src/xercesc/dom/impl/DOMAttrImpl.cpp Index: DOMAttrImpl.cpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/dom/impl/DOMAttrImpl.cpp,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- DOMAttrImpl.cpp 16 Aug 2002 19:20:28 -0000 1.8 +++ DOMAttrImpl.cpp 17 Sep 2002 13:11:48 -0000 1.9 @@ -143,33 +143,44 @@ if (fParent.fFirstChild == 0) { return XMLUni::fgZeroLenString; // return ""; } + + // Simple case where attribute value is just a single text node DOMNode *node = castToChildImpl(fParent.fFirstChild)->nextSibling; - if (node == 0) { + if (node == 0 && fParent.fFirstChild->getNodeType() == DOMNode::TEXT_NODE) { return fParent.fFirstChild->getNodeValue(); } - int length = 0; - for (node = fParent.fFirstChild; node != 0; node = castToChildImpl(node)->nextSibling) - length += XMLString::stringLen(node->getNodeValue()); - - // revisit - Come up with some way of not allocating a new string each - // time we do this. But it's not an immediate pressing problem, - // becuase we only allocate a new string when we have attribute - // values that contain entity reference nodes. And the parser - // does not ever produce such a thing. - - //XMLCh * retString = new (this->getOwnerDocument()) XMLCh[length+1]; - length = sizeof(XMLCh) * (length+1); - length = (length % 4) + length; - XMLCh * retString = (XMLCh*) ((DOMDocumentImpl *)this->getOwnerDocument())->allocate(length); - retString[0] = 0; - for (node = fParent.fFirstChild; node != 0; node = castToChildImpl(node)->nextSibling) - { - XMLString::catString(retString, node->getNodeValue()); - }; - return retString; + // + // Complicated case whre attribute value is a DOM tree + // + // According to the spec, the child nodes of the Attr node may be either + // Text or EntityReference nodes. + // + // The parser will not create such thing, this is for those created by users. + // + // In such case, we have to visit each child to retrieve the text + // + + XMLBuffer buf; + getTextValue(fParent.fFirstChild, buf); + + return (XMLCh*) ((DOMDocumentImpl *)this->getOwnerDocument())->getPooledString(buf.getRawBuffer()); }; +void DOMAttrImpl::getTextValue(DOMNode* node, XMLBuffer& buf) const +{ + if (node->getNodeType() == DOMNode::TEXT_NODE) + buf.append(node->getNodeValue()); + else if (node->getNodeType() == DOMNode::ENTITY_REFERENCE_NODE) + { + for (node = node->getFirstChild(); node != 0; node = castToChildImpl(node)->nextSibling) + { + getTextValue(node, buf); + } + } + + return; +} void DOMAttrImpl::setNodeValue(const XMLCh *val) 1.4 +5 -1 xml-xerces/c/src/xercesc/dom/impl/DOMAttrImpl.hpp Index: DOMAttrImpl.hpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/dom/impl/DOMAttrImpl.hpp,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- DOMAttrImpl.hpp 4 Jul 2002 15:27:56 -0000 1.3 +++ DOMAttrImpl.hpp 17 Sep 2002 13:11:48 -0000 1.4 @@ -76,6 +76,7 @@ #include "DOMNodeImpl.hpp" #include "DOMDocumentImpl.hpp" #include <xercesc/dom/DOMAttr.hpp> +#include <xercesc/framework/XMLBuffer.hpp> class DOMElementImpl; @@ -106,6 +107,9 @@ // helper function for DOM Level 3 renameNode virtual DOMNode* rename(const XMLCh* namespaceURI, const XMLCh* name); + +private: + void getTextValue(DOMNode* node, XMLBuffer& buf) const; }; #endif
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]