Re: Expat and C++ ?

"Ben Allison" <[email protected]>
Newsgroups gmane.text.xml.expat.general
Message-ID <[email protected]>
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
 > [email protected]
 > http://mail.libexpat.org/mailman/listinfo/expat-discuss
 >
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.