一、以rapidxml::node_declaration形式写xml文件第一行

 int write(void)
{
int ret = ; rapidxml::xml_document<> doc;
rapidxml::xml_node<> *declear = doc.allocate_node(rapidxml::node_declaration);
declear->append_attribute(doc.allocate_attribute("version", "1.0"));
declear->append_attribute(doc.allocate_attribute("encoding", "utf-8"));
doc.append_node(declear); rapidxml::xml_node<> *p_root_comment = doc.allocate_node(rapidxml::node_comment, NULL, "根节点注释");
doc.append_node(p_root_comment); rapidxml::xml_node<> *p_root = doc.allocate_node(rapidxml::node_element, "Root");
doc.append_node(p_root); p_root->append_node(doc.allocate_node(rapidxml::node_comment, NULL, "信息"));
rapidxml::xml_node<> *p_one_node = doc.allocate_node(rapidxml::node_element, "Information");
p_one_node->append_node(doc.allocate_node(rapidxml::node_comment, NULL, "姓名"));
p_one_node->append_node(doc.allocate_node(rapidxml::node_element, "Name", "Toney"));
p_one_node->append_node(doc.allocate_node(rapidxml::node_comment, NULL, "年龄"));
p_one_node->append_node(doc.allocate_node(rapidxml::node_element, "Age", ""));
p_one_node->append_node(doc.allocate_node(rapidxml::node_comment, NULL, "身份ID"));
p_one_node->append_node(doc.allocate_node(rapidxml::node_element, "ID", ""));
p_root->append_node(p_one_node); p_root->append_node(doc.allocate_node(rapidxml::node_comment, NULL, "成绩"));
rapidxml::xml_node<> *p_second_node = doc.allocate_node(rapidxml::node_element, "Score");
p_second_node->append_node(doc.allocate_node(rapidxml::node_comment, NULL, "语文"));
p_second_node->append_node(doc.allocate_node(rapidxml::node_element, "语文", ""));
p_second_node->append_node(doc.allocate_node(rapidxml::node_comment, NULL, "数学"));
p_second_node->append_node(doc.allocate_node(rapidxml::node_element, "数学", ""));
p_second_node->append_node(doc.allocate_node(rapidxml::node_comment, NULL, "英语"));
p_second_node->append_node(doc.allocate_node(rapidxml::node_element, "英语", ""));
p_root->append_node(p_second_node); std::string str_text;
str_text.clear();
rapidxml::print(std::back_inserter(str_text), doc);
doc.clear(); std::ofstream out("testInfor.xml");
out << str_text; std::cout << str_text.c_str() << std::endl; system("pause"); return ret;
}

运行结果:

rapidxml编写xml文件(er)的更多相关文章

  1. rapidxml编写xml文件(一)

    int writeXML(void) { rapidxml::xml_document<> doc; rapidxml::xml_node<> *rot = doc.alloc ...

  2. Hibernate.编写xml文件无自动提示信息

    Hibernate.编写xml文件无自动提示信息 注意: 配置 xxxx.hbm.xml 文件的自动提示.和配置 hibernate.cfg.xml 文件的提示,操作步骤是一样的.只是复制的文件内容. ...

  3. rapidxml读xml文件

    student.xml文件内容: int readXML(void) { rapidxml::file<> file("student.xml"); rapidxml: ...

  4. 使用Rapidxml读取xml文件

    现有xml文件如上,写在一个string中.需要获取节点上元素的类别和属性信息,并存储到结构体表中. 结构体如下: 得到的结果如下:

  5. 编写xml文件不当时会出现R文件找不到情况

    1,先检查xml文件是否报错,报错的话直接找到报错行. 2,xml文件若不报错,可能是文本值得格式输入错误 比如android:text=“<0.5km”,此时的小于号就会引发错误,导致R文件找 ...

  6. 编写xml文件的几个注意事项

    作者:朱金灿 来源:http://blog.csdn.net/clever101 xml注释的规范是这样的: <!-xml注释内容 --> 值得注意的是任何xml注释都必须放在<?x ...

  7. XML概念定义以及如何定义xml文件编写约束条件java解析xml DTD XML Schema JAXP java xml解析 dom4j 解析 xpath dom sax

    本文主要涉及:xml概念描述,xml的约束文件,dtd,xsd文件的定义使用,如何在xml中引用xsd文件,如何使用java解析xml,解析xml方式dom sax,dom4j解析xml文件 XML来 ...

  8. XML文件操作指南

    一.XML简介 XML的全名是eXtensible Markup Language(可以扩展的标记语言),它的语法类似HTML,都是用标签来描述数据.HTML的标签是固定的,我们只能使用.不能修改: ...

  9. Visual Studio中xml文件使用app.config、web.config等的智能提示的方法

    在.Net开发的过程中,有时我们需要使用Xml文件作为配置文件(基于某些情况的考虑),而不是app.config.web.config这种,但是我们在xml中配置时希望可以增加类似编辑app.conf ...

随机推荐

  1. JQ DOM元素 创建 添加 删除

    创建元素 // 创建元素节点 $('<p></p>'); // 创建属性节点 $('<p class="wow"></p>'); / ...

  2. IIS虚拟目录

    https://blog.csdn.net/mianyao1004/article/details/94036169

  3. Apache Kafka(九)- Kafka Consumer 消费行为

    1. Poll Messages 在Kafka Consumer 中消费messages时,使用的是poll模型,也就是主动去Kafka端取数据.其他消息管道也有的是push模型,也就是服务端向con ...

  4. Linux - cron - 基础

    概述 cron 相关的理解与使用 背景 最近实在没啥写的了 我写东西, 一般是是这些 看了书过后, 做一些系统的整理 比如之前的 docker 和 git 系列 遇到了实际问题, 解决过程也不是那么顺 ...

  5. Led Candle Light - Safe, Cost-Effective, Versatile, Realistic Flame Lighting

    Candles have been used to remove light for centuries, but it took hundreds of years to make better c ...

  6. MyBatis(6)——分页的实现

    分页的实现 a)通过mysql的分页查询语句: 说明:sql的分页语句格式为select * from aaa limit #{startIndex},#{pageSize} //---------- ...

  7. bitset 位运算

    1. 判断一个数是否是2的方幂n > 0 && ((n & (n - 1)) == 0 ) 解释((n & (n-1)) == 0): 如果A&B==0, ...

  8. CDH的坑之Deploy Client Configuration Failed

    Deploy Client Configuration Failed 1.问题描述 当使用CDH增添spark服务的时候,出现了以下错误: Faile to deploy client configu ...

  9. win7安装composer(PHPStudy环境)

    好句没写博客园了,因为现在的公司就是写代码啥的,没有什么新的东西,但是光写代码也学到不少东西,因为本身太菜了,最近让做一个pdf表单的功能,首先得安装php-pdftk,看GitHub里面用compo ...

  10. js处理文章详情页点击量统计

    具体需求:在文章管理系统中,需要统计文章详情页面的点击量,来体现该文章是否受用户欢迎,方便管理员调整日后编辑新文章时的内容方向. 解决方案:设置有过期时间的cookie 我们在访问文章详情页面时,拿到 ...