Re: [xml] knowing when cur is still valid?



On Fri, Aug 02, 2002 at 04:29:36PM -0700, Rick Jones wrote:
I was perusing the tree documentation, and came across a number of
entries such as this:

<excerpt>
xmlAddChild ()

xmlNodePtr  xmlAddChild                     (xmlNodePtr parent,
                                             xmlNodePtr cur);

Add a new node to parent, at the end of the child (or property) list
merging adjacent TEXT nodes (in which case cur is freed) If the new node
was already inserted in a document it is first unlinked from its
existing context. If the new node is ATTRIBUTE, it is added into
properties instead of children. If there is an attribute with equal
name, it is first destroyed.

parent : the parent node
cur : the child node
Returns : the child or NULL in case of error.
</excerpt>

I've naievely assumed that cur would be an xmlNodePtr I have allocated
and filled-in with everything of interest. If cur is possibly freed by
xmlAddChild, how will I know whether or not it is still OK to access or
free cur?

  if the xmlNodePtr returned is different than cur, then it means that
you cannot access cur anymore (you don't need to free it either).

Daniel

-- 
Daniel Veillard      | Red Hat Network https://rhn.redhat.com/
veillard redhat com  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]