Jump to content
  • Advertisement
Sign in to follow this  

XML ,SAX and strong typed structure

This topic is 3177 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hy. I use sax for parsing an xml because i read only a little part of the xml , only 1/8 of all tag name ,and the xml sizes are arownd 200/300 mb. I create a class for each tag that i use and inherit it from a base class, The CBaseEntityIfc. When i find a xml node that rappresent any of my classes i'm instantiate the class and place the instance in a map<string, CBaseEntityIfc*>* m_pMap. The parser is like this:
	wchar_t __RPC_FAR *pwchNamespaceUri,
	int cchNamespaceUri,
	wchar_t __RPC_FAR *pwchLocalName,
	int cchLocalName,
	wchar_t __RPC_FAR *pwchRawName,
	int cchRawName,
	ISAXAttributes __RPC_FAR *pAttributes)
	// assume element does not have text
	hasText = false;
	// take the local name
	std::wstring localName(pwchLocalName);

	// test the element's name and take appropriate action
	if(localName.compare(L"IfcProject") == 0)
		string data1 =...
		string data2 =...
		pMap[localName]= new CIfcProject(data1,data2,pMap);
	if(localName.compare(L"IfcSIUnit") == 0)
		string data1 =...
		string data2 =...
		pMap[localName]= new IfcSIUnit(data1,data2,pMap);

now i have a map with parsed elements. The problem is that if i would navigate my objects i must navigate the map then i must use strings and these strings aren't related to the specific classes. For each class again i have some data and i would that this data is available to the user. My idea is to pass a map reference to each object and in the object i do somthing like:
class CIfcProject :
	public CBaseEntityIfc
	CIfcProject(string data1,string data2,map<string, CBaseEntityIfc*>* pMap,string ref1)
	   m_pMap = pMap;
           m_strIfcOwnerHistoryRef = ref1;
	virtual ~CIfcProject(void);
	CIfcOwnerHistory* getRefOwnerHistory(){return ((CIfcOwnerHistory*)(*m_pMap)[m_strIfcOwnerHistoryRef]);};
	string m_strIfcOwnerHistoryRef;
	map<string, CBaseEntityIfc*>* m_pMap;

all for can do this: ((CIfcProject*)(*cMap)["ifcproject"])->getRefOwnerHistory()->ecc...... My question is : is correct to encapsulate a pointer to the map in each ifc class? There are other method for create a strong typed structure ? Thanks

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!