Re: Expat-discuss Digest, Vol 83, Issue 1

Albrecht Fritzsche <[email protected]>
Newsgroups gmane.text.xml.expat.general
Message-ID <[email protected]>
[email protected] wrote:

> Date: Wed, 21 Feb 2007 16:27:15 -0800
> From: "Mandeep Ahuja" <[email protected]>
> Subject: [Expat-discuss] Event callbacks for every Tag
> To: [email protected]
> Message-ID: <[email protected]>
> 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
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.