为什么读XML时没有报错但也没有显示
编译和运行都没有错,但是也没有显示数据
错那了,为什么???
#import "C:\Windows\system32\msxml4.dll"
....................
MSXML2::IXMLDOMDocumentPtr pDoc;
::CoInitialize(NULL);
HRESULT hr = pDoc.CreateInstance(__uuidof(MSXML2::DOMDocument30));
if(!SUCCEEDED(hr))
{
MessageBox(_T("失败"));
}
pDoc->load("d:\\ddt.xml");
MSXML2::IXMLDOMElementPtr childNode ;
childNode = (MSXML2::IXMLDOMElementPtr)(pDoc->selectSingleNode("//title"));
//得到节点类型
MSXML2::DOMNodeType nodeType;
childNode->get_nodeType(&nodeType);
//节点名称
BSTR var;
CString name;
childNode->get_nodeName(&var);
name = (char*)(_bstr_t)var;
//节点值
VARIANT varVal;
childNode->get_nodeTypedValue(&varVal);
CString strValue = (_bstr_t)varVal;
//节点属性,放在链表中
MSXML2::IXMLDOMNamedNodeMapPtr pAttrs = NULL;
MSXML2::IXMLDOMNodePtr pAttrItem;
childNode->get_attributes(&pAttrs);
long nCount ;
//发现nCount为0,为什么???????
pAttrs->get_length(&nCount);
for(int i = 0 ; i < nCount ; i++)
{
pAttrs->get_item(i,&pAttrItem);
//我们可以通过函数get_nodeName,get_nodeTypedValue得到属性名和属性值
//也可以直接得到
CString strAttrName =(_bstr_t)pAttrItem->nodeName;
CString strAttrValue = (_bstr_t)pAttrItem->nodeTypedValue;
MessageBox(strAttrName);
}
谢谢:)