//<![CDATA[
Sys.WebForms.PageRequestManager._initialize('AjaxHolder$scriptmanager1', document.getElementById('Form1'));
Sys.WebForms.PageRequestManager.getInstance()._updateControls(['tAjaxHolder$UpdatePanel1'], [], [], 90);
//]]>
簡單的VC 操作XML 檔案的的方法
首先建立一個XML檔案,我的機器軟體configuration如下:Windows xp professional sp2IE 6.0( 無關緊要)VS 2003------------------------------------------------------------------------------------------------------#import <msxml3.dll> //I have no idea why msxl4 cannot be used //in my PC, may be something on personal //discriminationusing namespace MSXML2;///the same to above///-----------------------------------------------------------------------------------建立檔案 int CreateXMLFile(char * xml_file_name){ // create an xml file named xml_file_name comtemporily // if the return val is "0",it means that creation // if failed ::CoInitialize(NULL);// this item must be included //it is fatal ,else it will failed //then at last “::CoUninitialize();”//matched MSXML2::IXMLDOMDocumentPtr pDoc; HRESULT hr = pDoc.CreateInstance(__uuidof(DOMDocument30));// //<msxml3.dll> version is 3.0 if(!(SUCCEEDED(hr)))//faild { return 0; } MSXML2::IXMLDOMElementPtr pPolicy=pDoc->createElement("Local"); pDoc->appendChild(pPolicy); { // the brackets including 1,2,3 can show the //tree structure of the xml file // nodes //1 MSXML2::IXMLDOMElementPtr pPolicyType; pPolicyType=pDoc->createElement("North"); pPolicyType->Puttext("Piking"); pPolicy->appendChild(pPolicyType); pPolicyType=pDoc->createElement("South"); pPolicy->appendChild(pPolicyType); {//2.1 MSXML2::IXMLDOMElementPtr pControlType; pControlType=pDoc->createElement("Shanghai"); pControlType->Puttext("Xujiahui"); pPolicyType->appendChild(pControlType); pControlType.Release(); }//end 2.1 pPolicyType=pDoc->createElement("East"); pPolicy->appendChild(pPolicyType); {//2.2 MSXML2::IXMLDOMElementPtr pProcessType; pProcessType=pDoc->createElement("Heilongjiang"); pProcessType->Puttext("harbin,Qiqihar"); pPolicyType->appendChild(pProcessType); pProcessType=pDoc->createElement("Liaoning"); pProcessType->Puttext("ShenYang,Dalian"); pPolicyType->appendChild(pProcessType); pProcessType.Release(); }//end 2.2 _variant_t varXml(xml_file_name); pDoc->save(varXml); //save the file pPolicy.Release(); pPolicyType.Release(); }//end 1 pDoc.Release(); ::CoUninitialize(); //necessary it same as new and delete return 1; } 產生的檔案如下。。<Location><North> Pingking</North><South> <Shanghai>Xujiahui</Shanghai></South><East> <Heilongjiang>harbin,qiqihar</Heilongjiang> <Liaoning>Shenyang,Dalian</Liaoning></East>-----------------------------------------------------------------------------------------尋找值訪問結點時,如果要讀<North>的值,就直接把”North”寫進去,返回的就是Pingking了,要訪問<Shanghai>要代入”South\\Shanghai”, 這個和註冊表分健值很像char* GetValueFromXml( char* nodeName){// get the value of certain node named nodeName // from the xml file // the return value 0 represent failure char* nodeValue=NULL; ::CoInitialize(NULL); MSXML2::IXMLDOMDocumentPtr pDoc; HRESULT hr = pDoc.CreateInstance(__uuidof(DOMDocument30)); if(!(SUCCEEDED(hr))) { return nodeValue; } hr=pDoc->load("book.xml"); if(!SUCCEEDED(hr)) { MSXML2::IXMLDOMElementPtr pPolicyNode=pDoc->GetdocumentElement(); MSXML2::IXMLDOMElementPtr pSelectNode=pPolicyNode->selectSingleNode(nodeName); nodeValue = _com_util::ConvertBSTRToString(pSelectNode->text); pPolicyNode.Release(); pSelectNode.Release(); } pDoc.Release(); ::CoUninitialize(); return nodeValue; }--------------------------------------------------------------------------------修改XML 檔案中的某一個結點的值存取方法同上int modify(const char* nodeName,char* nodeValue)//前者為結點名,後者為結點的字串值。{// modify the value of node named as nodeName // the new value is nodeValue // if the xml file is not existed then return // 0 ::CoInitialize(NULL); MSXML2::IXMLDOMDocumentPtr pDoc; HRESULT hr = pDoc.CreateInstance(__uuidof(DOMDocument30)); int rtval=0; if(!(SUCCEEDED(hr))) { rtval=0; return rtval; } hr=pDoc->load("book.xml");// 檔案名稱。 if(!SUCCEEDED(hr)) { MSXML2::IXMLDOMElementPtr pPolicyNode=pDoc->GetdocumentElement(); MSXML2::IXMLDOMElementPtr 二pSelectNode=pPolicyNode->selectSingleNode(nodeName); pSelectNode->Puttext(nodeValue); pDoc->save("book.xml"); pPolicyNode.Release(); pSelectNode.Release(); rtval=1; } pDoc.Release(); ::CoUninitialize(); return rtval; } -------------------------------------------------------------------------------------------------刪去結點
這個就是一個什麼remove 的成員函數就搞定了,和尋找的差不多,先找到要刪的結點,就行了。。當然刪後要儲存了,這一點不同,想必都知道。。