开发者

C++ Expat and XML parsing

开发者 https://www.devze.com 2023-04-01 17:16 出处:网络
I am new to using expat. I am trying to figure out how XML_SetUserData is intended to do. In my case, I have a list of class A objects and I need to populate this list as I parse the XML stream.

I am new to using expat. I am trying to figure out how XML_SetUserData is intended to do. In my case, I have a list of class A objects and I need to populate this list as I parse the XML stream.

So far, I was planning on using a singleton to represent this single list. Is the XML_SetUserData to eliminate the need for m开发者_运维知识库y list being a singleton?


Yes, it does. Just pass XML_SetUserData a pointer to whatever struct or class holds the necessary state, and cast it back from (void*) inside your handler.

A useful trick is to define a base class with static callback member functions that forward calls from expat to virtual member functions. In this scenario, XML_SetUserData provides a convenient mechanism to pass the this pointer through to the static callbacks.

0

精彩评论

暂无评论...
验证码 换一张
取 消