最近寫了一篇讀寫xml的代碼,不知道為什么執(zhí)行到getNodeValue()出現(xiàn)漰潰:
void WriteXML() { MSXML2::IXMLDOMDocumentPtr pDoc;
MSXML2::IXMLDOMElementPtr xmlRoot ; pDoc.CreateInstance(__uuidof(MSXML2::DOMDocument30)); //創(chuàng)建元素并添加到文檔中
xmlRoot=pDoc->createElement((_bstr_t)(char*)"Order"); //設(shè)置屬性
xmlRoot->setAttribute("id","000104337"); pDoc->appendChild(xmlRoot); MSXML2::IXMLDOMElementPtr pNode; //添加“ProductId”元素
pNode=pDoc->createElement((_bstr_t)(char*)"ProductId"); pNode->Puttext("MAD"); xmlRoot->appendChild(pNode); pDoc->save("d://order.xml");
}
void CCXmlReadWriterView::ReadXML()
{ MSXML2::IXMLDOMDocumentPtr pDoc; pDoc.CreateInstance(_uuidof(MSXML2::DOMDocument)); pDoc->load("D:\\order.xml");
MSXML2::IXMLDOMElementPtr childNode; childNode = (MSXML2::IXMLDOMElementPtr)(pDoc->selectSingleNode("Order")); MSXML2::DOMNodeType nodeType;
childNode->get_nodeType(&nodeType); MSXML2::IXMLDOMNamedNodeMapPtr pAttrs = NULL;
MSXML2::IXMLDOMNodeListPtr nodeList; MSXML2::IXMLDOMNodePtr pAttrItem; childNode->get_attributes(&pAttrs); childNode->get_childNodes(&nodeList); long nCount, iCount; pAttrs->get_length(&nCount); //獲取節(jié)點屬性個數(shù) nodeList->get_length(&iCount); //獲取節(jié)點個數(shù) for(int i = 0; i < iCount; i++) //根據(jù)需要可以添加數(shù)據(jù)到ListControl中 { MSXML2::IXMLDOMNodePtr dd = nodeList->Getitem(i);
_bstr_t jj = ddd->GetnodeName(); _bstr_t bb = ddd->GetnodeValue(); //漰潰?。。。。。?/FONT> }
}
|
|