// 创建对象
CoInitialize(NULL); // 初始化COM
// 创建解析器实例
CComPtr<IXMLDOMDocument> spXMLDOM;
BSTR bstrItemText;
// long value;
CString strbuf;
HRESULT hr=spXMLDOM.CoCreateInstance (_uuidof(DOMDocument));
spXMLDOM->put_async(VARIANT_FALSE);
spXMLDOM->put_validateOnParse(VARIANT_FALSE);
spXMLDOM->put_resolveExternals(VARIANT_FALSE);
spXMLDOM->put_preserveWhiteSpace(VARIANT_TRUE);
_bstr_t path = _bstr_t(xmlPath);
// 装载XML文档。
hr=spXMLDOM->load(path);
// 1、读取里面全部文本
spXMLDOM->get_text(&bstrItemText); // new
strbuf = bstrItemText; // new
// 2、读取一个节点
_bstr_t bstrSS("paragraph");
CComPtr<IXMLDOMNodeList> spParagraphs;
spParagraphs=spXMLDOM->getElementsByTagName(bstrSS); //搜索"Paragrah"
//是否正确的得到了指向IDOMNodeList的指针。
hr = spParagraphs->get_length(&value); //得到所包含的NODE节点的个数
if(SUCCEEDED(hr))
...{
spParagraphs->reset();
for(int ii=0; ii<value; ii++)
...{
CComPtr<IXMLDOMNode> spParagraph;
//得到具体的一个NODE节点
// hr = spParagraphs->get_item(ii,&spParagraph);
spParagraph = spParagraphs->nextNode();
if(SUCCEEDED(hr))
...{
spParagraph->get_text(&bstrItemText); //得到该节点相关的文本信息
strbuf += bstrItemText;
strbuf += " ";
}
}
}