|
给你一段C++的代码,就用微软的XML解析器
TreeSAXBuilder* ReadFromXMLFile(LPCTSTR szFileName, wstring& strRootEleName, int nCount)
{
CoInitializeEx(NULL, 0);
ISAXXMLReader *pRdr = NULL; //通过接口ISAXXMLReader创建一个解析器
HRESULT hr = CoCreateInstance(CLSID_SAXXMLReader, NULL, CLSCTX_INPROC_SERVER,
IID_ISAXXMLReader, (void **)&pRdr);
BOOL bRlt = false;
TreeSAXBuilder *pMc = new TreeSAXBuilder(strRootEleName, nCount);
if(!FAILED(hr))
{
hr = pRdr->putContentHandler(pMc); //在解析器中注册事件处理类
hr = pRdr->parseURL(szFileName);
if (SUCCEEDED(hr))
{
bRlt = TRUE;
}
else
{
wcout << _T("ParseWeatherInfo: parseURL Failed!") << endl;
}
pRdr->Release();
}
else
{
wcout << _T("ParseWeatherInfo: CoCreateInstance() Failed!") << endl;
}
CoUninitialize();
return pMc;
} |
|