[Expat-discuss] Expat and C++ ?

Ben Allison benski at nullsoft.com
Thu May 25 18:03:04 CEST 2006


Use a pointer to your object as the user data when you create the parser.

e.g.

if (parser)
{
   XML_ParserReset(parser, 0);
   XML_SetUserData(parser, this); // give our object pointer as context
   XML_SetElementHandler(parser, DStartTag, DEndTag); // set the tag 
callbacks
   XML_SetCharacterDataHandler(parser, DTextHandler); // set the text 
callbacks
}


then just create stub functions to call back into your class

e.g.

void XMLCALL DStartTag(void *data, const XML_Char *name, const XML_Char 
**atts)
{
   ((XMLReader *)data)->StartTag(name, atts);
}

-Ben Allison

David Smoot wrote on 5/25/2006, 11:48 AM:

 > I have poked in the archives and have found some but not all my answers.
 >
 > I started trying to use expat in a class with member methods as parsers.
 > This did not work obviously and it was explained here:
 > 
http://mail.libexpat.org/pipermail/expat-discuss/2002-November/000770.html
 >
 >
 > But on the homepage of libexpat.org it states that one of the changes in
 > Expat 2.0 is: "Fixed headers for use from C++."
 >
 > Does this mean I can use member methods as parsers?
 >
 > If so, are there any examples?
 >
 > Thank you,
 > David Smoot
 > _______________________________________________
 > Expat-discuss mailing list
 > Expat-discuss at libexpat.org
 > http://mail.libexpat.org/mailman/listinfo/expat-discuss
 >




More information about the Expat-discuss mailing list