Re: [xml] Get a property for read-only purpose

Date view Thread view Subject view Author view

From: Daniel Veillard (Daniel.Veillard@w3.org)
Date: Thu Jul 13 2000 - 09:33:24 EDT


On Thu, Jul 13, 2000 at 09:21:10AM -0400, rcx195@us.ibm.com wrote:
>
> Thanks Daniel for adding the xmlHasProp function. It is helpful.
>
> Now there are two functions that can be used:
> 1. xmlGetProp for geting the value of a property. Caller must release the
> memory.
> 2. xmlHasProp for checking whether a node contains a property. This
> function does not allocate memory, but caller can not
> know the value of the property by calling the function.

  yep,

> Is it possible that the value of a property is returned without allocating
> memory for it? This could be useful if the caller only wants to read the
> value and does not want new memory to be allocated for storing the value of
> the property.

  no, for the simple reason that a property value may be built using
entities references, which need to be kept in the DOM to be able to
save them back. This mean that there is no garantee that the string returned
by xmlGetProp() ever existed in memory before being given back to the
caller.
  I agree that in most case this string exists (content of the text
node child of the attribute node), but since this won't work 100% of the
time this seems had to change the API if it may fail. There is also
the problem that this string may change or be deallocated due to changes
in the document structure, and returning a pointer without copy exposes
the chances of crashing the client code due to an invalid reference.

Daniel

-- 
Daniel.Veillard@w3.org | W3C, INRIA Rhone-Alpes  | Today's Bookmarks :
Tel : +33 476 615 257  | 655, avenue de l'Europe | Linux XML libxml WWW
Fax : +33 476 615 207  | 38330 Montbonnot FRANCE | Gnome rpm2html rpmfind
 http://www.w3.org/People/all#veillard%40w3.org  | RPM badminton Kaffe
----
Message from the list xml@xmlsoft.org
Archived at : http://xmlsoft.org/messages/
to unsubscribe: echo "unsubscribe xml" | mail  majordomo@xmlsoft.org


Date view Thread view Subject view Author view

This archive was generated by hypermail 2b29 : Wed Aug 02 2000 - 12:30:22 EDT