Re: [xml] How to pass private data to custom ExternalEntityLoader?



On Fri, Nov 12, 2004 at 01:40:33PM -0500, Parag Chandra wrote:
Hi,

I need to install my own custom xmlExternalEntityLoader in my
application. I want this to be a member function, so I use the old hack
of making a pair of member functions, one of which is static, and then
having this static one cast some extra void* into an object of my type,
then using this object to call the non-static member function to do the
real work. This is the same approach I have taken when installing my own
error handler; however, it seems that xmlSetExternalEntityLoader() only
accepts a single function as an argument, unlike the
xmlTextReaderSetStructuredErrorHandler() which also accepts an arbitrary
void*. 

So I have added a 'void*  _private2' member to the _xmlParserCtxt
structure inside parser.h, as well as a xmlTextReaderCurrentParserCtxt()
function to xmlreader.h which will return the current parser in use by a
reader. Now I can pass a 'this' pointer in the _private2 member of this
context, and all seems to be working.

My question to the list is about the safety of this approach, and if
there is a better way to accomplish what I want. I'm using a slightly
modified v2.6.14. Thanks in advance. 

  safety wise, this should work, at least for errors generated during a
parser context work.
  To avoid modifying the library you should have ctxt->_private pointing
to a structure you alloacte and which contains all the fields you need.

Daniel

-- 
Daniel Veillard      | Red Hat Desktop team http://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]