Re: [xml] Using xmlSAXHandler
- From: Henning Follmann <h follmann gmx de>
- To: xml gnome org
- Subject: Re: [xml] Using xmlSAXHandler
- Date: Mon, 8 Apr 2002 20:23:53 -0400
On Thu, Apr 04, 2002 at 07:44:36AM -0800, Raghu Sampath wrote:
Hi,
I would like to use the xmlSAXHandler of the libxml2
package. I am not sure of how to override the
xmlSAXHandler class. Here's a sample of the code,
struct XMLSAXHandler : public xmlSAXHandler
{
void startDocument(void * user_data)
{
cout<<"this is the start of the document"<<endl;
}
void endDocument(void * user_data)
{
cout<<"This is the end of the document"<<endl;
}
}
Can you provide me with some sample code? How do the
startDocument and endDocument callbacks work?
Though a structure is in some way a class with default public members,
this isn't really a SAX framework. It is SAX like.
void
startDoc(void * ctxt)
{
printf("Start document\n");
}
void
endDoc(void * ctxt)
{
printf("End document\n");
}
...
xmlSaxHandler sax;
xmlParserCtxtPtr ctxt;
...
sax.startDocument=startDoc;
sax.endDocument=endDoc;
ctxt = xmlCreatePushParserCtxt ( &sax,
&myData, /* whatever it is */
NULL,
0,
NULL);
/* now feed with stream */
while (n=fread(Buffer, sizeof(char), 10, input)){
xmlParseChunk( ctxt, Buffer, n, 0);
}
/* to get an endDocument event we have to send EOF */
Buffer[0]=EOF;
xmlParseChunk( ctxt, Buffer, 10, 0);
Of course you can build an OO interface on top of it, but there is
already one:
http://lusis.org/~ari/xml++/
This might help.
Cheers,
Henning
--
Henning Follmann | hfollmann itcfollmann com
it consulting | http://www.itcfollmann.com
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]