pugixml应用随笔
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应用随笔的更多相关文章
- AI人工智能系列随笔
初探 AI人工智能系列随笔:syntaxnet 初探(1)
- 【置顶】CoreCLR系列随笔
CoreCLR配置系列 在Windows上编译和调试CoreCLR GC探索系列 C++随笔:.NET CoreCLR之GC探索(1) C++随笔:.NET CoreCLR之GC探索(2) C++随笔 ...
- C++随笔:.NET CoreCLR之GC探索(4)
今天继续来 带大家讲解CoreCLR之GC,首先我们继续看这个GCSample,这篇文章是上一篇文章的继续,如果有不清楚的,还请翻到我写的上一篇随笔.下面我们继续: // Initialize fre ...
- C++随笔:从Hello World 探秘CoreCLR的内部(1)
紧接着上次的问题,上次的问题其实很简单,就是HelloWorld.exe运行失败,而本文的目的,就是成功调试HelloWorld这个控制台应用程序. 通过我的寻找,其实是一个名为TryRun的文件出了 ...
- ASP.NET MVC 系列随笔汇总[未完待续……]
ASP.NET MVC 系列随笔汇总[未完待续……] 为了方便大家浏览所以整理一下,有的系列篇幅中不是很全面以后会慢慢的补全的. 学前篇之: ASP.NET MVC学前篇之扩展方法.链式编程 ASP. ...
- 使用Beautiful Soup编写一个爬虫 系列随笔汇总
这几篇博文只是为了记录学习Beautiful Soup的过程,不仅方便自己以后查看,也许能帮到同样在学习这个技术的朋友.通过学习Beautiful Soup基础知识 完成了一个简单的爬虫服务:从all ...
- 利用Python进行数据分析 基础系列随笔汇总
一共 15 篇随笔,主要是为了记录数据分析过程中的一些小 demo,分享给其他需要的网友,更为了方便以后自己查看,15 篇随笔,每篇内容基本都是以一句说明加一段代码的方式, 保持简单小巧,看起来也清晰 ...
- 《高性能javascript》 领悟随笔之-------DOM编程篇(二)
<高性能javascript> 领悟随笔之-------DOM编程篇二 序:在javaSctipt中,ECMASCRIPT规定了它的语法,BOM实现了页面与浏览器的交互,而DOM则承载着整 ...
- 《高性能javascript》 领悟随笔之-------DOM编程篇
<高性能javascript> 领悟随笔之-------DOM编程篇一 序:在javaSctipt中,ECMASCRIPT规定了它的语法,BOM实现了页面与浏览器的交互,而DOM则承载着整 ...
随机推荐
- sprignAOP那些术语
那些AOP术语 初看这么多术语,一下子都不好接受,慢慢来,很快就会搞懂.通知.增强处理(Advice) 就是你想要的功能,也就是上说的安全.事物.日志等.你给先定义好,然后再想用的地方用一下.包含As ...
- 【转载】VUE的背景图引入
我现在的项目要将登录页面的背景引一图片做为背景图片,按原jsp中的写法,发现无法找到背景图片,最后从网上查资料,采用上面的写法,成功显示出背景图片,参考网址 https://blog.csdn.net ...
- dp的冗余(选数类)
我们先来看一个例题: 在一个长度为n的序列中选出任意个数的数,要求每m个数中至少一个被选,要求选的数之和最小化. 我们很容易想出用f[i][j]来表示前i个数选的最后一个数是j,也就有 for(int ...
- 循序渐进VUE+Element 前端应用开发(31)--- 系统的日志管理,包括登录日志、接口访问日志、实体变化历史日志
在一个系统的权限管理模块中,一般都需要跟踪一些具体的日志,ABP框架的系统的日志管理,包括登录日志.接口访问日志.实体变化历史日志,本篇随笔介绍ABP框架中这些日志的管理和界面处理. 1.系统登录日志 ...
- IDEA配置JRebel实现热部署
IDEA配置JRebel实现热部署 1.下载JRebel and XRebel for Intellij插件 2. 激活 请查看这个文章http://www.cicoding.cn/other/jre ...
- Mirai框架qq机器人教程
Mirai框架qq机器人教程 0.前言 1. 安装Java 2.安装Mirai启动器 3.下载IDEA或其他编译器 4.创建mirai-console插件项目 4.1 通过git创建 4.2 通过插件 ...
- JMeter如何设置语言为中文
一.现象 JMeter安装后,默认语言为英文,如下图所示: 对于英文水平一般的人来说,刚开始使用起来比较费劲(比如我),影响我工作效率.那么,怎么将英文改为中文呢? 二.解决方法 1.修改设置 点击菜 ...
- redis之集群二:哨兵
回顾 上一篇介绍了Redis的主从集群模式,这个集群模式配置很简单,只需要在Slave的节点上进行配置,Master主节点的配置不需要做任何更改.但是,我们发现这种集群模式当主节点宕机,主从无法自动切 ...
- Python机器学习笔记:奇异值分解(SVD)算法
完整代码及其数据,请移步小编的GitHub 传送门:请点击我 如果点击有误:https://github.com/LeBron-Jian/MachineLearningNote 奇异值分解(Singu ...
- 实现简易版德州扑克|学习麻瓜编程以项目为导向入门前端 HTML+CSS+JS
实现简易版德州扑克 1.先上达到网页效果图(简易版德州扑克) 网页分为发牌区和牌池,上面为发牌区,下面是牌池区 2. 代码实现 2.1 HTML和JS代码 ` <link rel="s ...