문제

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 my 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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top