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 Sylvain Duval <du...@jouve.fr> on 2004/04/13 15:14:18 UTC

Memory question

Hi all,

Small question about memory management :

When I do a setAttribute like this on a DOMElement :

XMLCh* Name;
chName = XMLString::transcode("synchro");
	
XMLCh* chValue;
chValue = XMLString::transcode("attValue");
	
((DOMElement*)pNode)->setAttribute(chName, chValue);	
	
Do I have to release the XMLCh* or this memory will be used in the DOM tree 
in memory?

XMLString::release(&chName);	???
XMLString::release(&chValue);	???

Thanks for your help.

Sylvain.


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


Re: Weird getFirstChild() node behavior

Posted by Sylvain Duval <du...@jouve.fr>.
Hi Monica,

The values of nodeName, nodeValue, and attributes vary according to the 
node type as follows:
http://xml.apache.org/xerces-c/apiDocs/classDOMNode.html#z229_0
(Look at Detailed Description)

For a DOMText getNodeName return #Text but getNodeValue return the Text.

Sylvain.

At 14:57 13/04/04 -0700, you wrote:
>Hi all,
>
>I have a simple XML string: <d><id>1</id></d>
>After parsing this string, I wrote a function to
>traverse this DOM tree to get the node name/pairs.
>I'm running into a weird problem when I try to get the
>node name of <d>'s child (which is "id"):
>
>Note: In the following code, the current node being
>processed is <d>.
>
>(1) This piece of code works, and the print out is
>"id":
>DOMNodeList *children = node->getChildNodes();
>cout <<
>XMLString::transcode((children->item(1))->getNodeName())
><< endl;
>
>(2) This code does not work, and the print out is
>"#text":
>cout <<
>XMLString::transcode((node->getFirstChild())->getNodeName())
><< endl;
>
>Does anyone know why the "getFirstChild()" function
>does not return the expected results?  Is this a bug?
>
>Thanks for your time and help.
>
>Regards,
>Monica
>
>
>
>
>
>__________________________________
>Do you Yahoo!?
>Yahoo! Tax Center - File online by April 15th
>http://taxes.yahoo.com/filing.html
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
>For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


Weird getFirstChild() node behavior

Posted by Monica Lau <ml...@yahoo.com>.
Hi all,

I have a simple XML string: <d><id>1</id></d>
After parsing this string, I wrote a function to
traverse this DOM tree to get the node name/pairs. 
I'm running into a weird problem when I try to get the
node name of <d>'s child (which is "id"):

Note: In the following code, the current node being
processed is <d>.

(1) This piece of code works, and the print out is
"id":
DOMNodeList *children = node->getChildNodes();
cout <<
XMLString::transcode((children->item(1))->getNodeName())
<< endl;

(2) This code does not work, and the print out is
"#text":
cout <<
XMLString::transcode((node->getFirstChild())->getNodeName())
<< endl;

Does anyone know why the "getFirstChild()" function
does not return the expected results?  Is this a bug?

Thanks for your time and help.

Regards,
Monica



	
		
__________________________________
Do you Yahoo!?
Yahoo! Tax Center - File online by April 15th
http://taxes.yahoo.com/filing.html

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


Re: Memory question

Posted by Gareth Reakes <ga...@parthenoncomputing.com>.
Hi,

> When I do a DOMNode* pnodetoRelease = pNode->removeChild(*it);
>
> Is the pnodetoRelease still released when I call the DOMDocument release
> method  or it is really orphaned?

It is still released.

Gareth


-- 
Gareth Reakes, Managing Director      Parthenon Computing
+44-1865-811184                  http://www.parthcomp.com

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


Re: Memory question

Posted by Sylvain Duval <du...@jouve.fr>.
Thanks, so you mean Xerces internally reallocate new buffers...

Other question about removeChild ... just to be sure ...

When I do a DOMNode* pnodetoRelease = pNode->removeChild(*it);

Is the pnodetoRelease still released when I call the DOMDocument release 
method  or it is really orphaned?


At 14:51 13/04/04 +0100, you wrote:
>Hi,
>         you have to delete it.
>
>Gareth
>
>On Tue, 13 Apr 2004, Sylvain Duval wrote:
>
> > Hi all,
> >
> > Small question about memory management :
> >
> > When I do a setAttribute like this on a DOMElement :
> >
> > XMLCh* Name;
> > chName = XMLString::transcode("synchro");
> >
> > XMLCh* chValue;
> > chValue = XMLString::transcode("attValue");
> >
> > ((DOMElement*)pNode)->setAttribute(chName, chValue);
> >
> > Do I have to release the XMLCh* or this memory will be used in the DOM tree
> > in memory?
> >
> > XMLString::release(&chName);  ???
> > XMLString::release(&chValue); ???
> >
> > Thanks for your help.
> >
> > Sylvain.
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
> > For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
> >
> >
>
>--
>Gareth Reakes, Managing Director            +44-1865-811184
>Parthenon Computing                http://www.parthcomp.com
>
>
>
>
>---------------------------------------------------------------------
>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


Re: Memory question

Posted by Nedelcho Stanev <ne...@lta-bg.com>.
yep
you need to release it

decho
----- Original Message -----
From: "Sylvain Duval" <du...@jouve.fr>
To: <xe...@xml.apache.org>
Sent: Tuesday, April 13, 2004 4:14 PM
Subject: Memory question


> Hi all,
>
> Small question about memory management :
>
> When I do a setAttribute like this on a DOMElement :
>
> XMLCh* Name;
> chName = XMLString::transcode("synchro");
>
> XMLCh* chValue;
> chValue = XMLString::transcode("attValue");
>
> ((DOMElement*)pNode)->setAttribute(chName, chValue);
>
> Do I have to release the XMLCh* or this memory will be used in the DOM
tree
> in memory?
>
> XMLString::release(&chName); ???
> XMLString::release(&chValue); ???
>
> Thanks for your help.
>
> Sylvain.
>
>
> ---------------------------------------------------------------------
> 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


Re: Memory question

Posted by Gareth Reakes <pa...@parthenoncomputing.com>.
Hi,
	you have to delete it.

Gareth

On Tue, 13 Apr 2004, Sylvain Duval wrote:

> Hi all,
>
> Small question about memory management :
>
> When I do a setAttribute like this on a DOMElement :
>
> XMLCh* Name;
> chName = XMLString::transcode("synchro");
>
> XMLCh* chValue;
> chValue = XMLString::transcode("attValue");
>
> ((DOMElement*)pNode)->setAttribute(chName, chValue);
>
> Do I have to release the XMLCh* or this memory will be used in the DOM tree
> in memory?
>
> XMLString::release(&chName);	???
> XMLString::release(&chValue);	???
>
> Thanks for your help.
>
> Sylvain.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
>
>

-- 
Gareth Reakes, Managing Director            +44-1865-811184
Parthenon Computing                http://www.parthcomp.com




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