博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
tinyxml
阅读量:3528 次
发布时间:2019-05-20

本文共 1690 字,大约阅读时间需要 5 分钟。

Welcome to MyApp
Thank you for using MyApp

制作一个快递查询的软件,需要处理XML数据,系统的学习下XML

#include 
#include "tinyxml.h"#pragma comment(lib, "tinyxml.lib")using namespace std;void CreateXml(string XmlFile){ TiXmlDocument *doc = new TiXmlDocument; TiXmlDeclaration *dec = new TiXmlDeclaration("1.0", "", ""); doc->LinkEndChild(dec); TiXmlElement *root = new TiXmlElement("MyApp"); doc->LinkEndChild(root); TiXmlElement *mess = new TiXmlElement("Messages"); root->LinkEndChild(mess); TiXmlElement *welc = new TiXmlElement("Welcome"); mess->LinkEndChild(welc); TiXmlText *welctext = new TiXmlText("Welcome to MyApp"); welc->LinkEndChild(welctext); TiXmlElement *fare = new TiXmlElement("Farewell"); mess->LinkEndChild(fare); TiXmlText *faretext = new TiXmlText("Thank you for using MyApp"); fare->LinkEndChild(faretext); TiXmlElement *wind = new TiXmlElement("Windows"); root->LinkEndChild(wind); TiXmlElement *win = new TiXmlElement("Window"); wind->LinkEndChild(win); win->SetAttribute("name", "MainFrame"); win->SetAttribute("x", "5"); win->SetAttribute("y", "15"); win->SetAttribute("w", "400"); win->SetAttribute("h", "250"); TiXmlElement *conn = new TiXmlElement("Connection"); root->LinkEndChild(conn); conn->SetAttribute("ip", "192.168.0.1"); conn->SetAttribute("timeout", "123.456000"); doc->SaveFile(XmlFile.c_str());}void ReadXml(string XmlFile){ TiXmlDocument *doc = new TiXmlDocument; doc->LoadFile(XmlFile.c_str()); doc->Print();}int main(void){ string XmlFile("text.xml"); CreateXml(XmlFile); ReadXml(XmlFile); return 0;}

使用STL版本则需要

#define TIXML_USE_STL

#pragma comment(lib, "tinyxmlSTL.lib")

你可能感兴趣的文章