C++:借助tinyxml2读取XML文件
// XMLT01.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
#include "tinyxml2.h"
using namespace std;
using namespace TinyXml2;
void ReadTest01XML()
{
XMLDocument doc;
doc.LoadFile("Test01.xml");
const char * content = doc.FirstChildElement("test")->GetText();
printf("%s\n",content);
}
void Printfln(const char * content, const char * name = "",const int n = 0, const char * notEqual1 = "", const char * notEqual2 = NULL)
{
for(int i = 0; i < n; i++)
{
printf(" ");
}
if(content != notEqual1 && content != notEqual2)
{
printf("%s: %s\n",name,content);
}
else
{
printf("%s: \n",name);
}
}
void ReadXML(const XMLElement *root)
{
if(NULL == root)
{
return;
}
static int flag = 0;
const char * rootName = NULL;
const char * rootContent = NULL;
const XMLAttribute * rootAttribute = NULL;
const char * rootAttributeName = NULL;
const char * rootAttributeValue = NULL;
rootName = root->Name();
rootContent = root->GetText();
rootAttribute = root->FirstAttribute();
if(NULL != rootAttribute)
{
rootAttributeName = rootAttribute->Name();
rootAttributeValue = rootAttribute->Value();
}
Printfln(rootContent,rootName,flag);
Printfln(rootAttributeValue,rootAttributeName,flag);
const XMLElement *child = root->FirstChildElement();
if(NULL != child)
{
flag++;
ReadXML(child);
}
const XMLElement * nextSibling = root->NextSiblingElement();
if(NULL != nextSibling)
{
ReadXML(nextSibling);
}
else
{
flag--;
return;
}
}
void ReadTest02XML()
{
XMLDocument doc;
doc.LoadFile("Test02.xml");
const XMLElement *root = doc.RootElement();
ReadXML(root);
system("pause");
}
int _tmain(int argc, _TCHAR* argv[])
{
ReadTest01XML();
ReadTest02XML();
return 0;
}
C++:借助tinyxml2读取XML文件的更多相关文章
- 用TinyXml2读取XML文件的一个简单Demo
废话少说直接上代码,需要的人自然一看便懂,对于第一次接触TinyXml2的人来说还是有帮助的. <?xml version="1.0"?> <Table name ...
- C#中常用的几种读取XML文件的方法
1.C#中常用的几种读取XML文件的方法:http://blog.csdn.net/tiemufeng1122/article/details/6723764/
- 读取xml文件报错:Invalid byte 2 of 2-byte UTF-8 sequence。
程序读取xml文件后,系统报“Invalid byte 2 of 2-byte UTF-8 sequence”错误,如何解决呢? 1.程序解析xml的时候,出现Invalid byte 2 of 2- ...
- C#读取XML文件的基类实现
刚到新单位,学习他们的源代码,代码里读写系统配置文件的XML代码比较老套,直接写在一个系统配置类里,没有进行类的拆分,造成类很庞大,同时,操作XML的读写操作都是使用SetAttribute和node ...
- C#读取XML文件的方法
先写一个xml文件: <?xml version="1.0" encoding="utf-8" ?> <bookste> <!-- ...
- Spring相关:jdom学习:读取xml文件
云课堂马士兵的spring2.5课程中提到的 用JDOM读取XML文件需先用org.jdom.input.SAXBuilder对象的build()方法创建Document对象,然后用Document类 ...
- 在C#中创建和读取XML文件
1.创建简单的XML文件 为了便于测试,我们首先创建控制台应用程序,项目命名为CreateXml,Program.cs代码如下: 这样会在C盘根目录下创建data2.xml文件,文件内容为 using ...
- Java获取路径方法&相对路径读取xml文件方法
(1).request.getRealPath("/");//不推荐使用获取工程的根路径 (2).request.getRealPath(request.getRequestURI ...
- python读取xml文件
关于python读取xml文章很多,但大多文章都是贴一个xml文件,然后再贴个处理文件的代码.这样并不利于初学者的学习,希望这篇文章可以更通俗易懂的教如何使用python 来读取xml 文件. 什么是 ...
随机推荐
- 【ES】elasticsearch学习笔记
ES学习 1 优势 1.1 简单 1.1.1 相比Solor配置部署等非常简单 1.2 高效 1.2.1 ES使用Netty作为内部RPC框架,Solor使用Jetty 1.3 插件化 1.3.1 E ...
- 应用程序在状态栏展示时间(C#)
private DispatcherTimer _timer; private void SetTimeElaspInStatusBar() { try { _timer = new Dispatch ...
- C# 使用Vici WinService组件来创建Windows服务
Vici WinService 是 Windows平台下使用C#开发的轻量级用于创建,删除服务的类库,您只需简单的几行代码即可实现多线程异步服务的创建,删除,运行 废话不多说,直接上代码 /***** ...
- Linux学习笔记之初级篇
第一部分:[安装注意环节] 第二部分:[常用命令小试] 第三部分:[oracle的安装]
- [Debug] Debug Node.js Application by using Chrome Dev tools
For example you have a server.js file, and you want to debug some problems; What you can do is: node ...
- 支持各种控件上/下拉刷新的android-pulltorefresh
android- pulltorefresh 一个强大的拉动刷新开源项目,支持各种控件下拉刷新,如ListView.ViewPager.WevView. ExpandableListView.Grid ...
- struts2学习笔记(3)---Action中訪问ServletAPI获取真实类型的Servlet元素
一.源码: struts.xml文件: <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE s ...
- this词法
1.示例代码 <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UT ...
- rxvt-unicode配置
我的urxvt配置文件如下 前缀可改为rxvt然后可以使用rxvt命令启动 -/.Xresources ! urxvt color set URxvt.multichar_encoding:utf-8 ...
- 27、ArrayList和LinkedList的区别
在Java的List类型集合中,ArrayList和LinkedList大概是最常用到的2个了,细看了一下它们的实现,发现区别还是很大的,这里简单的列一下个人比较关心的区别. 类声明 ArrayLis ...