Re: [xml] avoiding unnecessary copying with xmlreader

On Fri, Jul 04, 2003 at 01:18:28AM +0100, Graham Bennett wrote:
I would like to be able to avoid the copy and get at the string pointer
directly.  I realise this pointer would have a very limited lifetime
before it is invalidated by the next call to libxml, but that is not a
problem for me as I will copy it immediately.  Also there may be some
cases where a copy is unavoidable and that is ok. 

Does anyone know of a way to achieve this cleanly with the current 

  The only way would be to get a pointer to the current node and access
the structure directly:
  xmlNodePtr      xmlTextReaderCurrentNode        (xmlTextReaderPtr reader);
then dereference xmlNodePtr to access the string values directly.

If not, might I suggest that some kind of api be provided for
this.  I would envisage a set of 'internal' functions which actually do
the work of the current functions, and then wrapper functions which
simply xmlStrdup the result of the internal function and return it to
the user.
My code could then call the internal functions directly, but
the main api would remain the same.

  Hum, no, exported function can be considered internal, so that will be
an API extension, no matter what. 

I suppose another option would be
to make the xmlStrdup function called in these functions pluggable in a
similar way to the alloc/free functions.  I could then simply replace
the functions with noops.

  not good at all IMHO, you change the behaviour of a function, I far far
prefer adding a new function with the properly documented behaviour.

Any thoughts appreciated,

  Can you check the option of directly accessing the underlying temporary
node ? If this does not work, then extending the API is the only solution
I'm afraid, and not all existing xmlTextReaderPtr based API would be 
available without that string copy, sometimes the data doesn't exists as a 
already available string.


Daniel Veillard      | Red Hat Network
veillard redhat com  | libxml GNOME XML XSLT toolkit | Rpmfind RPM search engine

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