天天减肥网,内容丰富有趣,生活中的好帮手!
天天减肥网 > XML字符串的读写操作函数及示例程序

XML字符串的读写操作函数及示例程序

时间:2023-04-04 03:12:34

相关推荐

XML字符串的读写操作函数及示例程序

下面是个XML字符串的读写操作函数及示例程序教程,撑握了其技术要点,学起来就简单多了。赶紧跟着小编一起来看看吧!

以下为引用的内容:

// OpXML.cpp : Defines the entry point for the consoleapplication.

//

//----------------------- Coded By Ronk --------------------------//

//----------------------- -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]="inesmsgmsgheadversionLZD/versionrootioio/root/msghead/inesmsg";

char strele[1024]="//version//";

char textstr[1024]="NNYX";

char value[1024];

printf("The xmlstr is :%s",xmlstr);

xmlread(xmlstr,strele,value); //befor Update

printf("The Text of Element befor Update is: %s",value);

xmlupdate(xmlstr,strele,textstr);//Change the Text of "version" with "NNYX"

printf("The Updated xmlstr is :%s",xmlstr);

xmlread(xmlstr,strele,value);//after Update

printf("The Text of Element after Update is :%s",value);

return 0;

}

void xmlread(char* msgstr,char* elestr,char *tex)

{

//Initialize

CoInitialize(NULL);

IXMLDOMDocumentPtr pXmlDoc;

IXMLDOMNodePtr pXmlNode;

HRESULT hr;

hr = (());

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 %",()());

pXmlDoc=NULL;

}

else

{

//Locate the Element

_bstr_t str=(LPCSTR)elestr;

pXmlNode = pXmlDoc -selectSingleNode(elestr);

if(FAILED(pXmlNode))

printf("Faild to Locate the Element %s",str);

else

{

//Read the Text of Element

strcpy(tex,(LPCSTR)pXmlNode -text);

//Realese

();

();

}

}

}

}

void xmlupdate(char *msgstr,char *elestr,char *upstr)

{

//---Initialize

CoInitialize(NULL);

IXMLDOMDocumentPtr pXmlDoc;

IXMLDOMNodePtr pXmlNode;

HRESULT hr;

hr = (());

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 %",()());

pXmlDoc=NULL;

}

else

{

//Located the Element

_bstr_t str=(LPCSTR)elestr;

pXmlNode = pXmlDoc -selectSingleNode(elestr);

if (FAILED(pXmlNode))

printf("Failed to Locate the Element %s",str);

else

{

//Update the Text of the Element

pXmlNode-text = upstr;

//Get the New xmlstr

strcpy(msgstr,(LPCSTR)pXmlDoc-xml);

//Realese

();

();

}

}

}

}

如果觉得《XML字符串的读写操作函数及示例程序》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。