Sign in to follow this  
giugio

XML ,SAX and strong typed structure

Recommended Posts

giugio    246
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:
HRESULT STDMETHODCALLTYPE SAXStore::startElement( 
	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);
	}
	ecc...........

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
{
public:
	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]);};
	
protected:
	
private:
	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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this