[Expat-discuss] Event callbacks for every Tag
Régis St-Gelais (Laubrass)
regis.st-gelais at laubrass.com
Thu Feb 22 13:54:23 CET 2007
----- Original Message -----
From: Mukesh Kumar
To: Régis St-Gelais (Laubrass)
Sent: Thursday, February 22, 2007 7:36 AM
Subject: RE: [Expat-discuss] Event callbacks for every Tag
>You mean user defined functions or r u talking about performance or can you
>tell me whether you are able to parse the xml file or not ?
Mukesh,
If I understood correctly your question was:
can I call a different function for each tag ?
Here is a more detailed sample code:
static void XMLhndl_ElementEnd(void *userData, const char *strElement);
static void XMLhndl_ElementEnd_Tag1(void *userData, const char *strElement);
static void XMLhndl_ElementEnd_Tag2(void *userData, const char *strElement);
static void XMLhndl_ElementEnd(void *userData, const char *strElement) //
This is tha callback called by expat
{
if (strcmp(strElement,"TAG1")==0)
{
XMLhndl_ElementEnd_Tag1(userData,strElement); // Call your own fonction
when TAG1 is found
return;
}
if (strcmp(strElement,"TAG2")==0)
{
XMLhndl_ElementEnd_Tag2(userData,strElement); // Call your own fonction
when TAG2 is found
return;
}
}
static void XMLhndl_ElementEnd_Tag1(void *userData, const char *strElement)
{
// do some thing with tag 1 data
}
static void XMLhndl_ElementEnd_Tag2(void *userData, const char *strElement)
{
// do some thing with tag 2 data
}
If this does not do what you want, then I don't undestand your question.
Regis St-Gelais
www.laubrass.com
-----Original Message-----
From: expat-discuss-bounces at libexpat.org
[mailto:expat-discuss-bounces at libexpat.org] On Behalf Of Régis St-Gelais
(Laubrass)
Sent: Thursday, February 22, 2007 5:51 PM
To: Mandeep Ahuja; expat-discuss at libexpat.org
Subject: Re: [Expat-discuss] Event callbacks for every Tag
----- Original Message -----
From: Mandeep Ahuja
To: expat-discuss at libexpat.org
Sent: Wednesday, February 21, 2007 7:27 PM
Subject: [Expat-discuss] Event callbacks for every Tag
> Hi, I am new user of the expat library. My application requires different
> code to be run on different xml tags when they are found and on the fly. I
> have learned expat is event >driven, but only one function is calledback
> on every tag found (endElement). My question is, can expat callback
> different functions based on tag found, meaning a unique >callback for
> every tag. Is that possible?
> Please help me out
>
>You can do something like that:
>In the unic element_end callback, you multiplex your different callbacks
>based on the tag.
>
> {
> if (strcmp(strElement,"TAG1")==0)
> {
> // call your callback for TAG1 here
> return;
> }
>
> if (strcmp(strElement,"TAG2")==0)
> {
> // call your callback for TAG2 here
> return;
> }
>
>}
>Regis St-Gelais
>www.laubrass.com
More information about the Expat-discuss
mailing list