#import "msxml4.dll" named_guids
using namespace MSXML2;
CoInitialize(NULL);
if (FAILED (CoCreateInstance(MSXML2::CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, MSXML2::IID_IXMLDOMDocument, reinterpret_cast<void**>(&m_pXMLDoc))))
return;
if (m_pXMLDoc->load( _bstr_t("DrisionTest.xml") ) == VARIANT_FALSE)
return;
if (SUCCEEDED(m_pXMLDoc->QueryInterface(MSXML2::IID_IXMLDOMNode, reinterpret_cast<void**>(&pNode))))
{
MSXML2::IXMLDOMNode *pRoot = NULL;
MSXML2::IXMLDOMNode *pNext = NULL;
MSXML2::IXMLDOMNode *pChild = NULL;
MSXML2::IXMLDOMNode *pListItem = NULL;
MSXML2::IXMLDOMNamedNodeMap *pNamedNodeMap = NULL;
CComVariant nodeVal;
CComBSTR cValue;
long listLength;
// 得到第一项
pNode->get_firstChild(&pRoot);
pRoot->get_firstChild(&pChild);
while (pChild && m_TotalPhoneNum < MAX_LINE_COUNT)
{
// 得到属性节点
pChild->get_attributes(&pNamedNodeMap);
// 属性个数
// pNamedNodeMap->get_length( &listLength );
// ...
pNamedNodeMap->get_item(0, &pListItem);
pListItem->get_nodeValue(&nodeVal);
cValue.Empty();
cValue.Append(nodeVal.bstrVal);
_tcscpy(m_LineInfo[m_TotalPhoneNum].szInnerNO, cValue);
pListItem->Release();
pListItem = NULL;
// ...
pNamedNodeMap->get_item(1, &pListItem);
pListItem->get_nodeValue(&nodeVal);
cValue.Empty();
cValue.Append(nodeVal.bstrVal);
_tcscpy(m_LineInfo[m_TotalPhoneNum].szOutLine, cValue);
pListItem->Release();
pListItem = NULL;
// 释放资源
pNamedNodeMap->Release();
pNamedNodeMap = NULL;
// 得到下一个节点
pChild->get_nextSibling(&pNext);
pChild->Release();
pChild = pNext;
m_TotalPhoneNum++;
}
pNode->Release();
pNode = NULL;
}
m_pXMLDoc->Release();
m_pXMLDoc = NULL;