You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by David Hoffer <da...@iserv.net> on 2002/11/23 01:13:57 UTC

DOM buffer allocation question

Where is the buffer(string) allocated which is returned by the XMLCh pointer
of the getNodeValue() function?  Do I have to provide my own buffer, like I
do below, to copy the contents of the returned string into?  Or could I just
return the XMLCh pointer from my GetElementValue() method?

BOOL CDOMParser::GetElementValue(const XMLCh* wszTagName, CString&
strTagValue, const DOMElement* pParentDOMElement)
{
	ASSERT(pParentDOMElement);
	if (pParentDOMElement)
	{
		DOMNodeList* pDOMNodeList =
pParentDOMElement->getElementsByTagNameNS(NULL, wszTagName);
		if (!pDOMNodeList || pDOMNodeList->getLength() < 1)
			return FALSE;

		DOMNode* pDOMNode = pDOMNodeList->item(0);
		if (pDOMNode)
		{
			DOMNode* pChildNode = pDOMNode->getFirstChild();
			if (pChildNode)
			{
				// What is the scope of the buffer(string) returned by this pointer?  Do
I have
				// to copy this into my buffer which is passed in by reference?
				XMLCh* wsz = pChildNode->getNodeValue();
				strTagValue = wsz;
			}
		}

		return TRUE;
	}

	return FALSE;
}



---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


Re: DOM buffer allocation question

Posted by Tinny Ng <tn...@ca.ibm.com>.
The node value pointer (wsz in your code) should remain valid until you
release the node or setting the node's node value to something else or
delete the document.   See
http://xml.apache.org/xerces-c/program-dom.html#XMLCh for details.

Tinny


----- Original Message -----
From: "David Hoffer" <da...@iserv.net>
To: "Xerces-C-Dev@Xml.Apache.Org" <xe...@xml.apache.org>
Sent: Friday, November 22, 2002 7:13 PM
Subject: DOM buffer allocation question


> Where is the buffer(string) allocated which is returned by the XMLCh
pointer
> of the getNodeValue() function?  Do I have to provide my own buffer, like
I
> do below, to copy the contents of the returned string into?  Or could I
just
> return the XMLCh pointer from my GetElementValue() method?
>
> BOOL CDOMParser::GetElementValue(const XMLCh* wszTagName, CString&
> strTagValue, const DOMElement* pParentDOMElement)
> {
> ASSERT(pParentDOMElement);
> if (pParentDOMElement)
> {
> DOMNodeList* pDOMNodeList =
> pParentDOMElement->getElementsByTagNameNS(NULL, wszTagName);
> if (!pDOMNodeList || pDOMNodeList->getLength() < 1)
> return FALSE;
>
> DOMNode* pDOMNode = pDOMNodeList->item(0);
> if (pDOMNode)
> {
> DOMNode* pChildNode = pDOMNode->getFirstChild();
> if (pChildNode)
> {
> // What is the scope of the buffer(string) returned by this pointer?  Do
> I have
> // to copy this into my buffer which is passed in by reference?
> XMLCh* wsz = pChildNode->getNodeValue();
> strTagValue = wsz;
> }
> }
>
> return TRUE;
> }
>
> return FALSE;
> }
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org