关于MSXML的使用
问题1:如何取得xml的第一行,即
<?xml version="1.0" encoding="gb2312" ?>
比如我想取version,该怎么取?(请不要用文件读取的方式,我想知道MSXML是不是本身就支持,
因为它用createProcessingInstruction来写,为什么没有取:()
问题2:使用MSXML要注意哪些资源要释放??
以下是我的代码,为什么 RELEASE(pDoc)加上了,Debug的时候可以看到有例外.
而RELEASE(pSubNode)加上了,就直接出错了。这两行注释掉,就什么问题没有。
请问这些资源要释放么??
#define RELEASE(pInterface) \
{\
pInterface->Release();\
pInterface = NULL;\
}\
void xml()
{
// 读取xml代码需要放在try块,因为建立com可能会产生exception
try{
CoInitialize(NULL); // 初始化com组件,
MSXML::IXMLDOMDocumentPtr pDoc;
// 创建一个com进程
HRESULT hr = pDoc.CreateInstance(__uuidof(MSXML::DOMDocument));
if(!SUCCEEDED(hr))
{
AfxMessageBox("failure");
}
pDoc->load("rss.xml");
MSXML::IXMLDOMNodeListPtr pNodeList = NULL;
pNodeList = pDoc->selectNodes("rss/channel/item");
MSXML::IXMLDOMNodePtr pSubNode;
CString strTemp;
for(int i=0; i<pNodeList->Getlength(); i++)
{
pSubNode=pNodeList->nextNode()->selectSingleNode("title");
_bstr_t strRequestType=pSubNode->Gettext();
strTemp=strRequestType.operator char *();
AfxMessageBox(strTemp);
}
//RELEASE(pSubNode);
//RELEASE(pDoc);
}catch(...)
{
AfxMessageBox(_T("Exception occurred"));
}
CoUninitialize();
}