• <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>

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

            Blog @ Blog

            當(dāng)華美的葉片落盡,生命的脈絡(luò)才歷歷可見。 -- 聶魯達(dá)

            常用鏈接

            統(tǒng)計(jì)

            積分與排名

            BBS

            Blog

            Web

            最新評(píng)論

            XML字符串的讀寫操作函數(shù)及示例程序[轉(zhuǎn)]

            // 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 閱讀(861) 評(píng)論(1)  編輯 收藏 引用

            評(píng)論

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

            Numbers of famous guys didn't have got cool writing skillfulness.  回復(fù)  更多評(píng)論   


            只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            廣告信息(免費(fèi)廣告聯(lián)系)

            中文版MSDN:
            歡迎體驗(yàn)

            麻豆久久| 久久噜噜电影你懂的| 国内精品伊人久久久久妇| 久久婷婷五月综合国产尤物app| 久久WWW免费人成一看片| 亚洲一区二区三区日本久久九| 伊人精品久久久久7777| 久久99毛片免费观看不卡| 天天影视色香欲综合久久| 久久国产精品久久| 亚洲中文字幕无码久久2017| 久久久WWW成人免费毛片| 国产日产久久高清欧美一区| 久久精品一区二区三区AV| 久久嫩草影院免费看夜色| 久久精品免费观看| 99蜜桃臀久久久欧美精品网站| 国产精品激情综合久久| 久久精品国产亚洲av水果派| 久久人妻无码中文字幕| 久久久久国产视频电影| 亚洲欧美日韩精品久久| 国产精品久久久久久搜索| 久久亚洲欧美国产精品| 亚洲AV无一区二区三区久久| 欧美日韩精品久久久免费观看| 日韩一区二区久久久久久| 国产精品一区二区久久精品| 国内精品伊人久久久久av一坑 | 精品国产91久久久久久久a| 久久香蕉超碰97国产精品| 99久久精品国产一区二区| 亚洲日本va中文字幕久久| 无码国内精品久久综合88| 久久精品国产2020| 亚洲国产精品久久电影欧美| 99蜜桃臀久久久欧美精品网站| 欧美一区二区三区久久综合| 久久综合狠狠综合久久综合88| 亚洲AV无码久久精品色欲| 亚洲精品乱码久久久久久蜜桃不卡 |