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.
精彩评论