c++访问XML

bool r_flag=false; try { CoInitialize(NULL); IXMLHTTPRequestPtr xmlrequest; //定义变量 xmlrequest.CreateInstance("MSXML2.XMLHTTP"); xmlrequest->open(_bstr_t("POST"),_bstr_t(strUrl),_variant_t("false")); xmlrequest->setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xmlrequest->send(strpostData); BSTR bstrbody; xmlrequest->get_responseText(&bstrbody); _bstr_t bstrtbody(bstrbody); CGlobalStruct::DataRecord tmpDataRecord; IXMLDOMDocumentPtr pDoc; IXMLDOMNodeListPtr pNoteList,pSecNoteList; IXMLDOMNodePtr pNode,pChildNote,pSecChildNote; HRESULT hr = pDoc.CreateInstance(__uuidof(DOMDocument)); pDoc->loadXML(bstrtbody); cout<<static_cast <char*>(pDoc->xml); pNode=pDoc->selectSingleNode("you9/status"); if(!strcmp((LPCSTR)_bstr_t(pNode->text),"RESULT_00")||!strcmp((LPCSTR)_bstr_t(pNode->text),"RESULT_0")) { pNode=pDoc->selectSingleNode("you9"); pNoteList=pNode->GetchildNodes(); *iCow=pNoteList->length-1; for(int i=1;i<pNoteList->length;i++) { pChildNote=pNoteList->Getitem(i); pSecNoteList=pChildNote->GetchildNodes(); *iCol=pSecNoteList->length; for(int j=0;j<pSecNoteList->length;j++) { pSecChildNote=pSecNoteList->Getitem(j); sprintf(tmpDataRecord.recordfieldname,"%s",(LPCSTR)_bstr_t(pSecChildNote->GetnodeName())); tmpDataRecord.recordfieldtype=3; sprintf(tmpDataRecord.recorddata,"%s",(LPCSTR)_bstr_t(pSecChildNote->text)); pVect->push_back(tmpDataRecord); } } r_flag=true; } else { sprintf(tmpDataRecord.recordfieldname,"%s","MESSAGE"); tmpDataRecord.recordfieldtype=3; ReadValue((char *)_bstr_t(pNode->text),retMessage[0],256); sprintf(tmpDataRecord.recorddata,"%s",retMessage); pVect->push_back(tmpDataRecord); r_flag=false; } pNoteList.Release(); pSecNoteList.Release(); pNode.Release(); pChildNote.Release(); pSecChildNote.Release(); pDoc.Release(); xmlrequest.Release(); CoUninitialize(); } catch (...) { } return r_flag; 

 

你可能感兴趣的:(c++访问XML)