[Expat-discuss] newbie question
Ken MacLeod
ken@bitsko.slc.ut.us
24 Apr 2001 10:45:29 -0500
Thomas Vander Stichele <thomas@urgent.rug.ac.be> writes:
> a) is there a more elaborate example of expat use in another
> project? Preferably one that does something with the data inbetween
> start and end tags
I don't know of any examples off-hand, besides the included one and
the xml.com article linked to from the web site[1].
> b) the doc says that the data inbetween these tags can be spread
> over calls to *XML_CharacterDataHandler). Based on what is it
> spread ?
Although probably deterministic, it's also probably not worth delving
into. Expat spreads out a lot on whitespace and non-alphabetic
characters. You must always expect text to be spread out.
> What would be the best way to get all of the data inbetween tags in
> one buffer ? Allocate one in the start element callback, add this
> data in the character data handler callback, and use it in the end
> element and free it there as well ?
Yes.
> c) most handlers have a void *userData as a first argument; it's not
> very clear to me how this works. There are two functions that seem
> to have something to do with this, XML_SetUserData and
> *XML_GetUserData. But what do they do ? it's not entirely clear
> from the expat source code.
userData is a pointer to anything *you* want to store there and be
passed back to all of your handlers. This way you could have more
than one parser allocated, yet calling the same set of handlers -- the
userData can be used to distinguish the streams or hold
instance-specific information that you are gathering.
Use XML_SetUserData to assign that pointer to a parser instance, and
XML_GetUserData to get it back (if you ever need to).
-- Ken
[1] <http://expat.sourceforge.net/>