Skip to content
Snippets Groups Projects
Commit b975a32d authored by Alberto Massari's avatar Alberto Massari
Browse files

Use the DOMDocument's pool to allocate the return value of getWholeText (XERCESC-1949)

git-svn-id: https://svn.apache.org/repos/asf/xerces/c/trunk@1027994 13f79535-47bb-0310-9956-ffa450edef68
parent 62481f34
No related branches found
No related tags found
No related merge requests found
......@@ -135,7 +135,12 @@ bool DOMCDATASectionImpl::getIsElementContentWhitespace() const
const XMLCh* DOMCDATASectionImpl::getWholeText() const
{
DOMDocument *doc = getOwnerDocument();
DOMTreeWalker* pWalker=doc->createTreeWalker(doc->getDocumentElement(), DOMNodeFilter::SHOW_ALL, NULL, true);
if (!doc) {
throw DOMException(DOMException::NOT_SUPPORTED_ERR, 0, GetDOMNodeMemoryManager);
return 0;
}
DOMNode* root=doc->getDocumentElement();
DOMTreeWalker* pWalker=doc->createTreeWalker(root!=NULL?root:(DOMNode*)this, DOMNodeFilter::SHOW_ALL, NULL, true);
pWalker->setCurrentNode((DOMNode*)this);
// Logically-adjacent text nodes are Text or CDATASection nodes that can be visited sequentially in document order or in
// reversed document order without entering, exiting, or passing over Element, Comment, or ProcessingInstruction nodes.
......@@ -156,7 +161,7 @@ const XMLCh* DOMCDATASectionImpl::getWholeText() const
}
pWalker->release();
XMLCh* wholeString = (XMLCh*) (GetDOMNodeMemoryManager->allocate((buff.getLen()+1)*sizeof(XMLCh)));
XMLCh* wholeString = (XMLCh*)((DOMDocumentImpl*)doc)->allocate((buff.getLen()+1) * sizeof(XMLCh));
XMLString::copyString(wholeString, buff.getRawBuffer());
return wholeString;
}
......
......@@ -145,7 +145,12 @@ bool DOMTextImpl::getIsElementContentWhitespace() const
const XMLCh* DOMTextImpl::getWholeText() const
{
DOMDocument *doc = getOwnerDocument();
DOMTreeWalker* pWalker=doc->createTreeWalker(doc->getDocumentElement(), DOMNodeFilter::SHOW_ALL, NULL, true);
if (!doc) {
throw DOMException(DOMException::NOT_SUPPORTED_ERR, 0, GetDOMNodeMemoryManager);
return 0;
}
DOMNode* root=doc->getDocumentElement();
DOMTreeWalker* pWalker=doc->createTreeWalker(root!=NULL?root:(DOMNode*)this, DOMNodeFilter::SHOW_ALL, NULL, true);
pWalker->setCurrentNode((DOMNode*)this);
// Logically-adjacent text nodes are Text or CDATASection nodes that can be visited sequentially in document order or in
// reversed document order without entering, exiting, or passing over Element, Comment, or ProcessingInstruction nodes.
......@@ -166,7 +171,7 @@ const XMLCh* DOMTextImpl::getWholeText() const
}
pWalker->release();
XMLCh* wholeString = (XMLCh*) (GetDOMNodeMemoryManager->allocate((buff.getLen()+1)*sizeof(XMLCh)));
XMLCh* wholeString = (XMLCh*)((DOMDocumentImpl*)doc)->allocate((buff.getLen()+1) * sizeof(XMLCh));
XMLString::copyString(wholeString, buff.getRawBuffer());
return wholeString;
}
......
......@@ -378,6 +378,11 @@ int main (int argC, char *argV[])
XERCES_STD_QUALIFIER cout << "getElementsByTagName didn't return a valid DOMNodeList." << XERCES_STD_QUALIFIER endl;
else if(list->item(0)!=doc->getDocumentElement())
XERCES_STD_QUALIFIER cout << "getElementsByTagName didn't find the root element." << XERCES_STD_QUALIFIER endl;
DOMTreeWalker* pWalker=doc->createTreeWalker(doc->getDocumentElement(), DOMNodeFilter::SHOW_TEXT, NULL, true);
DOMText* textNode=(DOMText*)pWalker->nextNode();
pWalker->release();
const XMLCh* txt=(textNode!=NULL?textNode->getWholeText():NULL);
}
sax2parser->parse(xmlFile);
saxParser->parse(xmlFile);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment