参考:http://blog.csdn.net/L_Andy/article/details/40615517

tinyxml官网:

http://www.grinninglizard.com/tinyxml/

官方文档:

http://www.grinninglizard.com/tinyxmldocs/index.html

github上文件下载地址:
https://sourceforge.net/projects/tinyxml/

TinyXML类:


TiXmlBase:整个TinyXML模型的基类。
TiXmlAttribute:对应于XML中的元素的属性。
TiXmlNode:对应于DOM结构中的节点。
TiXmlComment:对应于XML中的注释。<!--XXXXX.-->
TiXmlDeclaration:对应于XML中的申明部分,即<?versiong="1.0" ?>。
TiXmlDocument:对应于XML的整个文档。
TiXmlElement:对应于XML的元素。
TiXmlText:对应于XML的文字部分。
TiXmlUnknown:对应于XML的未知部分。
TiXmlHandler:定义了针对XML的一些操作。

使用:

XML:

<?xml version="1.0" encoding="UTF-8"?>
<phonebook>
<!--one item behalfs one contacted person.-->
<item>
<name>miaomaio</name>
<addr>Shaanxi Xi'an</addr>
<tel>13759911917</tel>
<email>miaomiao@home.com</email>
</item>
<item>
<name>gougou</name>
<addr>Liaoning Shenyang</addr>
<tel>15840330481</tel>
<email>gougou@home.com</email>
</item>
<!--more contacted persons.-->
</phonebook>

C++:

//______________________________________________________________________
// Read information from xml file. // define xml file path, as follow , we use relative path,
// but you can use absolute path also.
const char* filepath = "phonebookdata.xml";
TiXmlDocument doc(filepath);
bool loadOkay = doc.LoadFile();
// faile to load 'phonebookdata.xml'.
if (!loadOkay) {
printf( "Could not load test file %s. Error='%s'. Exiting.\n", filepath,doc.ErrorDesc() );
exit( );
} // get dom root of 'phonebookdata.xml', here root should be 'phonebook'.
TiXmlElement* root = doc.RootElement(); printf("_______________________________________\n\n");
printf(" contacted person information \n\n");
// trace every items below root.
for( TiXmlNode* item = root->FirstChild( "item" );
item;
item = item->NextSibling( "item" ) ) {
printf("_______________________________________\n"); // read name.
TiXmlNode* child = item->FirstChild();
const char* name = child->ToElement()->GetText();
if (name) {
printf("name:%s\n",name);
} else {
printf("name:\n");
} // read address.
child = item->IterateChildren(child);
const char* addr = child->ToElement()->GetText();
if (addr) {
printf("addr:%s\n",addr);
} else {
printf("addr:\n");
} // read telephone no.
child = item->IterateChildren(child);
const char* tel = child->ToElement()->GetText();
if (tel) {
printf("tel:%s\n",tel);
} else {
printf("tel:\n");
} // read e-mail.
child = item->IterateChildren(child);
const char* email = child->ToElement()->GetText();
if(email) {
printf("email:%s\n",email);
} else {
printf("email:\n");
} printf("\n"); }
//______________________________________________________________________ //______________________________________________________________________
// Add information to xml file and save it.
TiXmlElement* writeRoot = doc.RootElement();
TiXmlNode* newNode = new TiXmlElement("item"); const TiXmlNode* name4NewNode = new TiXmlElement("name");
newNode->InsertEndChild(*name4NewNode)->InsertEndChild(TiXmlText("pipi")); const TiXmlNode* addr4NewNode = new TiXmlElement("addr");
newNode->InsertEndChild(*addr4NewNode)->InsertEndChild(TiXmlText("Shaanxi Xianyang")); const TiXmlNode* tel4NewNode = new TiXmlElement("tel");
newNode->InsertEndChild(*tel4NewNode)->InsertEndChild(TiXmlText("")); const TiXmlNode* email4NewNode = new TiXmlElement("email");
newNode->InsertEndChild(*email4NewNode)->InsertEndChild(TiXmlText("pipi@home.com")); writeRoot->InsertEndChild(*newNode);
doc.SaveFile();
//______________________________________________________________________

[原][库][c++]tinyxml使用小结的更多相关文章

  1. TinyXML用法小结

    TinyXML用法小结 1.      介绍 Tinyxml的官方网址:http://www.grinninglizard.com 官方介绍文档:http://www.grinninglizard.c ...

  2. TinyXML用法小结2

    参考:http://www.cnblogs.com/hgwang/p/5833638.html TinyXML用法小结 1.      介绍 Tinyxml的官方网址:http://www.grinn ...

  3. [原][源码][tinyxml][opencv]按照规格剪切所有的图片

    源码: #include <iostream> #include <fstream> #include <opencv2/core/core.hpp> #inclu ...

  4. [库][c++]tinyxml2使用小结

    参考:http://blog.csdn.net/educast/article/details/12908455 1.配置TinyXML2 去这里把项目弄下来,然后解压,我们之需要里面的tinyxml ...

  5. Android 屏幕适配(二)增强版百分比布局库(percent-support-lib)

    转载请标明出处: http://blog.csdn.net/lmj623565791/article/details/46767825: 本文出自:[张鸿洋的博客] 一 概述 上周一我们发布了Andr ...

  6. rpmdb出问题,重建rpmdb库

    1.备份原库 tar cvzf rpmdb-backup.tar.gz /var/lib/rpm 2.删除rpmdb库 rm -f /var/lib/rpm/__db.00* 3.重建库 rpm -- ...

  7. (原)C++解析XML生成类对象_v1.0 函数指针

    要写一个xml解析,解析后获得到的数据变成各个类的对象. 解析有现成的库,使用tinyxml,但是解析出来的类库如何变成各个类的对象, 例如一下这个xml, <musics> <mu ...

  8. 开源TinyXML 最简单的新手教程

    TinyXML它是基于一个非常受欢迎的现在DOM型号XML解析器,简单易用且小巧玲珑,很适合存储简单数据.配置文件. 该项目属于开源项目,在sourceforge上边的链接是:http://sourc ...

  9. Android 增强版百分比布局库 为了适配而扩展

    转载请标明出处: http://blog.csdn.net/lmj623565791/article/details/46767825: 本文出自:[张鸿洋的博客] 一 概述 上周一我们发布了Andr ...

随机推荐

  1. Lintcode: Insert Node in a Binary Search Tree

    Given a binary search tree and a new tree node, insert the node into the tree. You should keep the t ...

  2. cocos代码研究(5)Action学习笔记

    理论部分 Action类也是cocos核心基础类之一,在游戏中起着非常重要的作用,继承自Ref,被 FiniteTimeAction(有限时间动作), Follow , 以及 Speed 继承. 有限 ...

  3. java常用功能

    1.复制文件 private void fileChannelCopy(File source, File target) throws IOException { FileInputStream f ...

  4. OS X 下动态库的引用

    foo.c #include <stdio.h> void foo(void) { printf("foo.\n"); } main.c #include <st ...

  5. linux常用命令:find命令之xargs

    在使用 find命令的-exec选项处理匹配到的文件时, find命令将所有匹配到的文件一起传递给exec执行.但有些系统对能够传递给exec的命令长度有限制,这样在find命令运行几分钟之后,就会出 ...

  6. python excel操作 练习-#操作单列 #操作A到C列 #操作1到3行 #指定一个范围遍历所有行和列 #获取所有行 #获取所有列

    ##操作单列#操作A到C列#操作1到3行#指定一个范围遍历所有行和列#获取所有行#获取所有列 #coding=utf-8 from openpyxl import Workbook wb=Workbo ...

  7. SpringMVC中controller返回图片(转)

    本文转自:http://blog.csdn.net/u011637069/article/details/51112187 SpringMVC中controller通过返回ModelAndView然后 ...

  8. C++提供了四个转换运算符

    const_cast <new_type> (expression) static_cast <new_type> (expression) reinterpret_cast ...

  9. Git 的安装步骤

    Git 的安装步骤 一.下载Git Git 的官网:https://git-scm.com/ 在 Git 的官网中点击Downloads,进入如下页面: 选择对应的操作系统,以博主为例,点击Windo ...

  10. Adobe漏洞攻击

    Adobe漏洞攻击 windows ip 开启msfconsole 进入攻击模块 设置攻击载荷payload 设置相关参数 确定需要修改的参数 exploit生成5303.pdf 将pdf复制到靶机里 ...