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


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

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. 

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