国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > XML > 正文

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

2024-09-05 20:54:22
字體:
來源:轉載
供稿:網友

以下為引用的內容:

// 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();
}
}
}
}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 邵武市| 抚宁县| 文水县| 达日县| 平利县| 松原市| 林西县| 鄯善县| 南江县| 株洲市| 班玛县| 和政县| 新平| 禄劝| 宜城市| 上蔡县| 长春市| 镶黄旗| 元氏县| 砀山县| 大同县| 通化市| 汤阴县| 古浪县| 荣成市| 青神县| 休宁县| 华安县| 衡山县| 理塘县| 泽库县| 体育| 井陉县| 永德县| 渭源县| 新昌县| 广丰县| 云阳县| 天津市| 霍州市| 山西省|