[Expat-discuss] Expat-discuss Digest, Vol 83, Issue 1

Albrecht Fritzsche ali at mental.com
Thu Feb 22 14:09:13 CET 2007


expat-discuss-request at libexpat.org wrote:

> Date: Wed, 21 Feb 2007 16:27:15 -0800
> From: "Mandeep Ahuja" <ahuja at aksysnetworks.com>
> Subject: [Expat-discuss] Event callbacks for every Tag
> To: expat-discuss at libexpat.org
> Message-ID: <b566a6abe48e061a4bb44fa4d42569db at aksysnetworks.com>
> Content-Type: text/plain; charset="us-ascii"
> 
> 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


Hi Madeep,

the feature you are asking for is not part of expat. If you think about 
it it wouldn't even make sense - who knows, ie how can expat know, what 
tags you have in your application.

Thatswhy expat calls on every tag (regardless its name) *one* callback 
and passing to the name of the tag (plus the attributes). This is 
generic and works for every application.

To achieve what you want it is easy to add application-specific code to 
that on_stat_element handler such that for every tag name an 
application-specific callback will be called. (I am, for instance, using 
a STL map for the mapping from tag name to the callback

   std::map<string, std::pair<start_element_cb, end_element_cb> >

)

But that is nothing expat lib could do for you since, as said, this is 
application-specific.

Hope it helps
Ali



More information about the Expat-discuss mailing list