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

Date view Thread view Subject view Author view

From: Jordan Henderson (jhenderson@daynt1.daas.dla.mil)
Date: Thu Jul 13 2000 - 10:30:32 EDT


> -----Original Message-----
> From: Daniel Veillard [mailto:Daniel.Veillard@w3.org]
> Sent: Thursday, July 13, 2000 9:33 AM
> To: xml@rpmfind.net
> Subject: Re: [xml] Get a property for read-only purpose
>
>
>
> 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.
>

Another way might be to copy the property value into a user supplied
buffer. If this were supported, let's call it CopyProp, I'd expect that
a length would be passed in and some kind of status returned to indicate
truncation.

Not sure if it would be better to copy the partial string in case
of truncation or not. I'm leaning toward not copying the partial
string. It could lead to sloppy programming where users would use
CopyProp without checking of status.

One implementation of this idea would be for HasProp to return
the buffer size needed, (-1 if doesn't exist, or perhaps keep the
existence return separate from the buffer size return might be
cleaner), and implement GetProp using a HasProp/malloc/CopyProp sequence.

This might be more trouble than it's worth. An API _can_ have
too many options. Just thinking out loud...

> 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
>

----
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