需求 : 重建一棵xml树, 在重建过程中对原来的标签进行一定的修改.

具体修改部分就不给出了, 这里只提供重建部分的代码

code :

/*************************************************************************
> File Name: rapidxml.cpp
> Author: hanhao
> Mail: hanhao@cisco.com
> Created Time: Tue 07 Nov 2017 06:37:05 AM GMT
************************************************************************/ #include<iostream>
#include<fstream>
#include"rapidxml/rapidxml.hpp"
#include"rapidxml/rapidxml_print.hpp"
#include"rapidxml/rapidxml_utils.hpp"
using namespace std;
using namespace rapidxml;
ofstream out("rapidxmloutlog.xml");
xml_document<> doc;
xml_document<> newdoc;
xml_node<> * new_cur;
xml_node<> * new_son; void handlenode(xml_node<> *node){
if(node->type() == node_cdata){
new_cur->append_node(newdoc.allocate_node(rapidxml::node_cdata, NULL, node->value()));
//catch cdata
}
if(node->type() == node_comment){
new_cur->append_node(newdoc.allocate_node(rapidxml::node_comment, NULL, node->value()));
//catch comment
}
if(node->type() == node_element){
new_son = newdoc.allocate_node(rapidxml::node_element, node->name(), node->value());
xml_attribute<> * attr = node -> first_attribute();
while(attr){
new_son->append_attribute(newdoc.allocate_attribute(attr->name(), attr->value()));
attr = attr -> next_attribute();
}
new_cur->append_node(new_son);
new_cur = new_son;
for(node = node -> first_node(); node != NULL; node = node -> next_sibling()){
handlenode(node);
}
new_cur = new_cur->parent();
//catch element
}
}
int main(){
xml_node<>* rot = newdoc.allocate_node(rapidxml::node_pi, newdoc.allocate_string("xml version='1.0' encoding='UTF-8'"));
newdoc.append_node(rot);
new_cur = newdoc.allocate_node(node_element, "han hao");
newdoc.append_node(new_cur);
//add header 4 new doc char xmldoc[] = "tahoe_call_ivr.xml";
file<> file(xmldoc);
doc.parse<parse_comment_nodes>(file.data());
//parse old doc for(xml_node<> *node = doc.first_node(); node != NULL; node = node->next_sibling()){
handlenode(node);
}
//rebuild new doc out<<newdoc<<endl;
return 0;
}

  

使用Rapidxml重建xml树的更多相关文章

  1. C#递归生成HTML树,C#递归生成xml树

    C#递归生成HTML树 public StringBuilder str = new StringBuilder();   //定义一个字符串 private void get_navigation_ ...

  2. C#操作Xml树的扩展类

    本文提供一个操作Xml树的扩展类,与将xml字符串直接映射成实体对象的使用方法,供大家参考,学习. 下面附上源码 using System; using System.Collections.Gene ...

  3. [BZOJ29957] 楼房重建 - 线段树

    2957: 楼房重建 Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 3294  Solved: 1554[Submit][Status][Discus ...

  4. rapidxml编写xml文件(er)

    一.以rapidxml::node_declaration形式写xml文件第一行 int write(void) { ; rapidxml::xml_document<> doc; rap ...

  5. rapidxml读xml文件

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

  6. rapidxml编写xml文件(一)

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

  7. bzoj 2957: 楼房重建 线段树

    2957: 楼房重建 Time Limit: 10 Sec  Memory Limit: 256 MB[Submit][Status][Discuss] Description 小A的楼房外有一大片施 ...

  8. 使用Rapidxml读取xml文件

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

  9. bzoj 2957 楼房重建 (线段树+思路)

    链接: https://www.lydsy.com/JudgeOnline/problem.php?id=2957 思路: 用分块可以很简单的过掉,但是这道题也可以用线段树写. 分类讨论左区间最大值对 ...

随机推荐

  1. 用tsc编译ts文件的时候报错,tsc : 无法加载文件,因为在此系统上禁止运行脚本;

    用tsc编译ts文件的时候报错,tsc : 无法加载文件,因为在此系统上禁止运行脚本:SecurityError 在vscode的控制台或者Windows PowerShell中用tsc命令编译ts文 ...

  2. {% csrf_token %} 原理和作用 (踩坑必看)

    本博客已暂停更新,请转自新博客 https://www.whbwiki.com/320.html 继续阅读 简介 在django中我们需要在templates的form中加入{%csrf_token% ...

  3. css 按钮悬停效霓虹灯特效

    css 按钮悬停效霓虹灯特效 <!DOCTYPE html> <html lang="en"> <head> <meta charset=

  4. mysql查询报错this is incompatible with sql_mode=only_full_group_by

    临时改法:select @@GLOBAL.sql_mode;查询当前mysql的模式去掉ONLY_FULL_GROUP_BY重新设置:set @@GLOBAL.sql_mode='STRICT_TRA ...

  5. 第12组 Alpha冲刺 (1/6)

    过去两天完成了哪些任务 文字描述 静态页面代码编写以及一些点击事件 展示GitHub当日代码/文档签入记录 接下来的计划 1.继续学习echarts 2.编写所需要的图表代码 还剩下哪些任务 1.图表 ...

  6. React-Router示例(重定向与withRouter)

    1.withRouter作用:把不是通过路由切换过来的组件中,将react-router 的 history.location.match 三个对象传入props对象上   默认情况下必须是经过路由匹 ...

  7. Redis的ACID属性

    事务是数据库的一个重要属性,有关事务的4个特性,原子性.一致性.隔离性.持久性,也就是ACID,这些属性既包含了对事务执行结果的要求,也有数据库在事务执行前后的数据状态变化的要求. Redis可以完全 ...

  8. [atAGC049F]Happy Sequence

    定义$L=2\cdot 10^{5}$,$g(x)=\sum_{i=1}^{n}|b_{i}-x|-|a_{i}-x|$,则合法当且仅当$\forall 0\le x\le L,g(x)\ge 0$, ...

  9. [cf997E]Good Subsegments

    一个区间为好区间当且仅当$\max_{l\le i\le r}a_{i}-\min_{l\le i\le r}a_{i}=r-l$,考虑固定右端点$r$,维护所有左端点$l$的上述式子左-右的值,那么 ...

  10. [loj3340]命运

    容斥,强制若干条链不重要,即有$2^{n-1-s}$种(其中$s$为这些链的并所覆盖的边数),暴力将选中的链打标记,时间复杂度$o(m^{2}2^{m}+n\log_{2}n)$(预处理出这$2m$个 ...