• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            山寨:不是最好的,是最適合我們的!歡迎體驗山寨 中文版MSDN

            Blog @ Blog

            當華美的葉片落盡,生命的脈絡才歷歷可見。 -- 聶魯達

            常用鏈接

            統計

            積分與排名

            BBS

            Blog

            Web

            最新評論

            XML字符串的讀寫操作函數及示例程序[轉]

            // OpXML.cpp : Defines the entry point for the console application.

            //----------------------- Coded By Ronk --------------------------//
            //----------------------- 2005-07-17 --------------------------//


            #include 
            "stdafx.h"
            #include 
            <stdio.h>


            //---You must Setup the MSXML4.0 before using
            #import <msxml4.dll>
            using namespace MSXML2;

            void xmlread(char *ch1,char *ch2,char *ch3);//Read the xmlstr and Get the Text of the Element

            void xmlupdate(char *ch1,char *ch2,char *ch3);//Read the xmlstr and Update the Text of the Element

            int main(int argc, char* argv[])
            {
                
            char xmlstr[1024]="<inesmsg><msghead><version>LZD</version><root>ioio</root></msghead></inesmsg>";
                
            char strele[1024]="//version//";
                
            char textstr[1024]="NNYX";
                
            char value[1024];
                
                printf(
            "The xmlstr is :\n%s\n\n",xmlstr);
                
                xmlread(xmlstr,strele,value); 
            //befor Update
                printf("The Text of Element befor Update is: \n%s\n\n",value);
                
                xmlupdate(xmlstr,strele,textstr);
            //Change the Text of "<version>" with "NNYX"
                printf("The Updated xmlstr is :\n%s\n\n",xmlstr);
                
                xmlread(xmlstr,strele,value);
            //after Update
                printf("The Text of Element after Update is :\n%s\n\n",value);
                
                
            return 0;
            }

            void xmlread(char* msgstr,char* elestr,char *tex)
            {
                
            //Initialize
                CoInitialize(NULL);
                
                IXMLDOMDocumentPtr pXmlDoc;
                IXMLDOMNodePtr pXmlNode;
                
                HRESULT hr;
                hr 
            = pXmlDoc.CreateInstance(__uuidof(DOMDocument));
                
            if (FAILED(hr))
                {
                    printf(
            "Faild to Create XMLDom Instance !");
                    pXmlDoc
            =NULL;
                }
                
            else
                {
                    pXmlDoc 
            ->async = VARIANT_FALSE;
                    
                    
            //Load xmlmsg
                    _bstr_t xmlstr=(LPCSTR)msgstr;
                    
                    
            if (!(pXmlDoc->loadXML(msgstr)))
                    {
                        printf(
            "Failed to Load xmlstr:\n%s\n",(LPCSTR)pXmlDoc->parseError->Getreason());
                        pXmlDoc
            =NULL;
                    }
                    
            else
                    {
                        
            //Locate the Element
                        _bstr_t str=(LPCSTR)elestr;
                        pXmlNode 
            = pXmlDoc ->selectSingleNode(elestr);
                        
                        
            if(FAILED(pXmlNode))
                            printf(
            "Faild to Locate the Element \n%s\n",str);
                        
            else
                        {
                            
            //Read the Text of Element
                            strcpy(tex,(LPCSTR)pXmlNode ->text);
                            
                            
            //Realese
                            pXmlDoc.Release();
                            pXmlNode.Release();
                        }
                    }
                }
            }

            void xmlupdate(char *msgstr,char *elestr,char *upstr)
            {
                
            //---Initialize
                CoInitialize(NULL);
                
                IXMLDOMDocumentPtr pXmlDoc;
                IXMLDOMNodePtr pXmlNode;
                
                HRESULT hr;
                hr 
            = pXmlDoc.CreateInstance(__uuidof(DOMDocument));
                
            if (FAILED(hr))
                {
                    printf(
            "Faild to Create XMLDom Instance !");
                    pXmlDoc
            =NULL;
                }
                
            else
                {
                    pXmlDoc 
            ->async = VARIANT_FALSE;
                    
                    
            //Load xml str
                    _bstr_t xmlstr=(LPCSTR)msgstr;
                    
                    
            if (!(pXmlDoc->loadXML(msgstr)))
                    {
                        printf(
            "Failed to load xmlstr:\n%s\n",(LPCSTR)pXmlDoc->parseError->Getreason());
                        pXmlDoc
            =NULL;
                    }
                    
            else
                    {
                        
            //Located the Element
                        _bstr_t str=(LPCSTR)elestr;
                        pXmlNode 
            = pXmlDoc ->selectSingleNode(elestr);
                        
                        
            if (FAILED(pXmlNode))
                            printf(
            "Failed to Locate the Element \n%s\n",str);
                        
            else
                        {
                            
            //Update the Text of the Element
                            pXmlNode->text = upstr;
                            
                            
            //Get the New xmlstr
                            strcpy(msgstr,(LPCSTR)pXmlDoc->xml);
                            
                            
            //Realese
                            pXmlDoc.Release();
                            pXmlNode.Release();
                        }
                    }
                }
            }

            posted on 2009-06-22 18:01 isabc 閱讀(851) 評論(1)  編輯 收藏 引用

            評論

            # re: XML字符串的讀寫操作函數及示例程序[轉] 2011-03-17 17:32 buy an essay online

            Numbers of famous guys didn't have got cool writing skillfulness.  回復  更多評論   

            廣告信息(免費廣告聯系)

            中文版MSDN:
            歡迎體驗

            久久人人爽人人澡人人高潮AV | 91精品国产91久久久久福利| 久久婷婷五月综合国产尤物app| 久久人人爽人人爽人人片AV麻烦| 亚洲va中文字幕无码久久| 日本久久久久亚洲中字幕| 99热都是精品久久久久久| 亚洲天堂久久久| 嫩草影院久久国产精品| 欧美日韩精品久久免费| 久久综合综合久久97色| 亚洲国产成人精品91久久久| 久久国产亚洲高清观看| 久久青青草原精品国产软件| 国产∨亚洲V天堂无码久久久| 青青青青久久精品国产h久久精品五福影院1421 | 久久久精品久久久久特色影视| 久久久久久免费视频| 久久久无码精品午夜| 国产精品美女久久久| 伊人久久精品无码av一区| 亚洲欧美久久久久9999| 精品久久久久久国产免费了| 97久久精品无码一区二区| 久久夜色精品国产亚洲| 久久久免费观成人影院| 国内精品久久久久久久涩爱| 久久精品国产一区二区三区日韩| 久久人人爽人人爽人人片av高请| 人人狠狠综合久久亚洲| 久久国产精品免费| 狠狠久久综合伊人不卡| 欧美伊香蕉久久综合类网站| 99麻豆久久久国产精品免费| 久久婷婷五月综合97色 | 色综合久久夜色精品国产| 国产一区二区三精品久久久无广告| 国产精品岛国久久久久| 99久久精品费精品国产一区二区| 欧洲人妻丰满av无码久久不卡| 性做久久久久久久|