1.   修改元素值 second_node.set_value("miller");不对

  必须second_node.first_child().set_value("miller");

2. 小例子

#include <iostream>
#include "pugixml.hpp"
#include <stdio.h>

using namespace std;
using namespace pugi;


cout << "Hello world!" << endl; xml_document agentdoc;
agentdoc.load_file("agent.xml");
xml_node root_node = agentdoc.child("root");
xml_node first_node = root_node.child("thrift");
xml_node second_node = first_node.child("switch"); cout<<"first name : "<<first_node.name()<<endl;
cout<<"second name : "<<second_node.name()<<endl;
cout<<"second value : "<<second_node.child_value()<<endl; 此处不能用value

// Note: For <node>text</node> node.value() does not return "text"! Use child_value() or text() methods to access text inside nodes. // second_node.first_child().value();
second_node.first_child().set_value("qinbin");
cout<<"second value 执行完 : "<<second_node.child_value()<<endl; agentdoc.save_file("agent.xml");

3.

pugixml的三个文件,可以只include头文件pugixml.hpp,CPP文件不用放到项目中,

方法是,在pugiconfig.hpp中:

// Uncomment this to switch to header-only version
#define PUGIXML_HEADER_ONLY
#include "pugixml.cpp"

将这两行的注释去掉就可以了。

另外,如果项目使用的是Unicode设置,则可以在pugiconfig.hpp中:

// Uncomment this to enable wchar_t mode
#define PUGIXML_WCHAR_MODE

将wchar模式打开即可。

4.一开始新生成xml时,second_node.text().set(var.data());

5.官网文档  http://pugixml.googlecode.com/svn/tags/latest/docs/quickstart.html#quickstart.main.modify 不翻墙不知道能不能打开

pugi::xml_node node = doc.child("node");

// change node name
std::cout << node.set_name("notnode");
std::cout << ", new node name: " << node.name() << std::endl; // change comment text
std::cout << doc.last_child().set_value("useless comment");
std::cout << ", new comment text: " << doc.last_child().value() << std::endl; // we can't change value of the element or name of the comment 见第一条
std::cout << node.set_value("1") << ", " << doc.last_child().set_name("2") << std::endl;
pugi::xml_attribute attr = node.attribute("id"); // change attribute name/value
std::cout << attr.set_name("key") << ", " << attr.set_value("345");
std::cout << ", new attribute: " << attr.name() << "=" << attr.value() << std::endl; // we can use numbers or booleans
attr.set_value(1.234);
std::cout << "new attribute value: " << attr.value() << std::endl; // we can also use assignment operators for more concise code
attr = true;
std::cout << "final attribute value: " << attr.value() << std::endl;
This is an example of adding new attributes/nodes to the document (samples/modify_add.cpp):

// add node with some name
pugi::xml_node node = doc.append_child("node"); // add description node with text child
pugi::xml_node descr = node.append_child("description");
descr.append_child(pugi::node_pcdata).set_value("Simple node"); // add param node before the description
pugi::xml_node param = node.insert_child_before("param", descr); // add attributes to param node
param.append_attribute("name") = "version";
param.append_attribute("value") = 1.1;
param.insert_attribute_after("type", param.attribute("name")) = "float";
This is an example of removing attributes/nodes from the document (samples/modify_remove.cpp):

// remove description node with the whole subtree
pugi::xml_node node = doc.child("node");
node.remove_child("description"); // remove id attribute
pugi::xml_node param = node.child("param");
param.remove_attribute("value"); // we can also remove nodes/attributes by handles
pugi::xml_attribute id = param.attribute("name");
param.remove_attribute(id);

简单入门:http://blog.csdn.net/yukin_xue/article/details/7540011

6.头文件 添加encoding

 pugi::xml_document doc;
pugi::xml_node decl = doc.prepend_child(pugi::node_declaration);
decl.append_attribute("version") = "1.0";
decl.append_attribute("encoding") = "UTF-8";

pugixml应用随笔的更多相关文章

  1. AI人工智能系列随笔

    初探 AI人工智能系列随笔:syntaxnet 初探(1)

  2. 【置顶】CoreCLR系列随笔

    CoreCLR配置系列 在Windows上编译和调试CoreCLR GC探索系列 C++随笔:.NET CoreCLR之GC探索(1) C++随笔:.NET CoreCLR之GC探索(2) C++随笔 ...

  3. C++随笔:.NET CoreCLR之GC探索(4)

    今天继续来 带大家讲解CoreCLR之GC,首先我们继续看这个GCSample,这篇文章是上一篇文章的继续,如果有不清楚的,还请翻到我写的上一篇随笔.下面我们继续: // Initialize fre ...

  4. C++随笔:从Hello World 探秘CoreCLR的内部(1)

    紧接着上次的问题,上次的问题其实很简单,就是HelloWorld.exe运行失败,而本文的目的,就是成功调试HelloWorld这个控制台应用程序. 通过我的寻找,其实是一个名为TryRun的文件出了 ...

  5. ASP.NET MVC 系列随笔汇总[未完待续……]

    ASP.NET MVC 系列随笔汇总[未完待续……] 为了方便大家浏览所以整理一下,有的系列篇幅中不是很全面以后会慢慢的补全的. 学前篇之: ASP.NET MVC学前篇之扩展方法.链式编程 ASP. ...

  6. 使用Beautiful Soup编写一个爬虫 系列随笔汇总

    这几篇博文只是为了记录学习Beautiful Soup的过程,不仅方便自己以后查看,也许能帮到同样在学习这个技术的朋友.通过学习Beautiful Soup基础知识 完成了一个简单的爬虫服务:从all ...

  7. 利用Python进行数据分析 基础系列随笔汇总

    一共 15 篇随笔,主要是为了记录数据分析过程中的一些小 demo,分享给其他需要的网友,更为了方便以后自己查看,15 篇随笔,每篇内容基本都是以一句说明加一段代码的方式, 保持简单小巧,看起来也清晰 ...

  8. 《高性能javascript》 领悟随笔之-------DOM编程篇(二)

    <高性能javascript> 领悟随笔之-------DOM编程篇二 序:在javaSctipt中,ECMASCRIPT规定了它的语法,BOM实现了页面与浏览器的交互,而DOM则承载着整 ...

  9. 《高性能javascript》 领悟随笔之-------DOM编程篇

    <高性能javascript> 领悟随笔之-------DOM编程篇一 序:在javaSctipt中,ECMASCRIPT规定了它的语法,BOM实现了页面与浏览器的交互,而DOM则承载着整 ...

随机推荐

  1. jstat gcutil

    QQA: jstat gcutil 的输出是什么意思 当 Java 程序有性能问题时,尤其是响应时间有突然变化时,最好第一时间查看 GC 的状态.一般用 jstat -gcutil <pid&g ...

  2. 出现org.apache.ibatis.binding.BindingException异常

    出现绑定式异常 查看target文件夹里面再mapper中,发现运行时缺少xml文件 解决办法 1.将xml文件复制到target中Mapper文件夹下面. 2.将xml放到resource目录下 3 ...

  3. mysql 应用 持续更新

    1.安装方法 贴出,my.ini # MySQL Server Instance Configuration File # -------------------------------------- ...

  4. SonarQube学习(五)- SonarQube之自定义规则使用

    一.前言 古人云:"欲速则不达",最近真的是深有体会.学习也是如此,不是一件着急的事,越是着急越不会. 就拿SonarQube来说吧,去年年末就想学来着,但是想着想着就搁置了,有时 ...

  5. maven依赖与传递性依赖

    目录 依赖范围 传递性依赖 依赖调节 可选依赖 本文主要是针对<maven实战>书中关键知识点的学习记录,未免有纰漏或描述不到之处,建议购买阅读原书 首先贴出一个pom常见的一些元素释义 ...

  6. Hive Query生命周期 —— 钩子(Hook)函数篇

    无论你通过哪种方式连接Hive(如Hive Cli.HiveServer2),一个HQL语句都要经过Driver的解析和执行,主要涉及HQL解析.编译.优化器处理.执行器执行四个方面. 以Hive目前 ...

  7. MySQL的CURD 增删改查

    添加 insert 语法: 单条:insert into 表名('字段1', '字段2', ...) values('值1', '值2', ...) 多条:insert into 表名('字段1', ...

  8. 【Oracle】查看oracle表空间大小及增加表空间的几种方法

    在oracle中表空间是必不可少的.但是怎么查看表空间呢 简单的查看方式是: SQL> select tablespace_name from dba_tablespaces; 想要查看表空间对 ...

  9. 【高并发】ReadWriteLock怎么和缓存扯上关系了?!

    写在前面 在实际工作中,有一种非常普遍的并发场景:那就是读多写少的场景.在这种场景下,为了优化程序的性能,我们经常使用缓存来提高应用的访问性能.因为缓存非常适合使用在读多写少的场景中.而在并发场景中, ...

  10. 前端面试之JavaScript中的闭包!

    前端面试之JavaScript中的闭包! 闭包 闭包( closure )指有权访问另一个函数作用域中变量的函数. ----- JavaScript 高级程序设计 闭包其实可以理解为是一个函数 简单理 ...