RapidXml使用

article/2025/9/13 8:48:11

vs2017
rapidxml-1.13

1 RapidXml使用

1.1 创建xml

#include <iostream>
#include "rapidxml/rapidxml.hpp"
#include "rapidxml/rapidxml_utils.hpp"
#include "rapidxml/rapidxml_print.hpp"using namespace rapidxml;void crateXml()
{xml_document<> doc;xml_node<>* rot = doc.allocate_node(rapidxml::node_pi, doc.allocate_string("xml version='1.0' encoding='utf-8'"));doc.append_node(rot);xml_node<>* node = doc.allocate_node(node_element, "config", "information");xml_node<>* color = doc.allocate_node(node_element, "color", NULL);doc.append_node(node);node->append_node(color);color->append_node(doc.allocate_node(node_element, "red", "0.1"));color->append_node(doc.allocate_node(node_element, "green", "0.1"));color->append_node(doc.allocate_node(node_element, "blue", "0.1"));color->append_node(doc.allocate_node(node_element, "alpha", "1.0"));xml_node<>* size = doc.allocate_node(node_element, "size", NULL);size->append_node(doc.allocate_node(node_element, "x", "640"));size->append_node(doc.allocate_node(node_element, "y", "480"));node->append_node(size);xml_node<>* mode = doc.allocate_node(rapidxml::node_element, "mode", "screen mode");mode->append_attribute(doc.allocate_attribute("fullscreen", "false"));node->append_node(mode);std::string text;rapidxml::print(std::back_inserter(text), doc, 0);std::cout << text << std::endl;std::ofstream out("config.xml");out << doc;
}int main()
{crateXml();system("PAUSE");return EXIT_SUCCESS;
}

输出文件config.xml:

<?xml version='1.0' encoding='utf-8' ?>
<config><color><red>0.1</red><green>0.1</green><blue>0.1</blue><alpha>1.0</alpha></color><size><x>640</x><y>480</y></size><mode fullscreen="false">screen mode</mode>
</config>

1.2 创建xml2

void createXml2()
{xml_document<> doc; //是解析器char a[] = "<top>"//假设单独传, 就不能加上xml的头部信息,//否则会报错"<name>tangqiang</name>""<age>22</age>""</top>";char* p = a;doc.parse<0>(p);xml_node<>* node = doc.first_node();//去顶级结点std::cout << (node->name()) << std::endl;node = node->first_node();while (node) {std::cout << node->name() << ":" << node->value() << std::endl;//name() value()返回的字符串不会去掉首尾的空白字符node = node->next_sibling();}std::ofstream out("test.xml");//ofstream 默认时,假设文件存在则会覆盖原来的内容,不存在则会新建out << doc;//doc 这样输出时在目标文件里不会有xml 头信息---<?xml version='1.0' encoding='utf-8' >out.close();}

输出文件test.xml:

<top><name>tangqiang</name><age>22</age>
</top>

1.3 读取xml

void readXml()
{file<> fdoc("config.xml");std::cout << fdoc.data() << std::endl;xml_document<> doc;doc.parse<0>(fdoc.data());std::cout << doc.name() << std::endl;//! 获取根节点xml_node<>* root = doc.first_node();std::cout << root->name() << std::endl;//! 获取根节点第一个节点xml_node<>* node1 = root->first_node();std::cout << node1->name() << std::endl;xml_node<>* node11 = node1->first_node();std::cout << node11->name() << std::endl;std::cout << node11->value() << std::endl;//! 加入之后再次保存//须要说明的是rapidxml明显有一个bug//那就是append_node(doc.allocate_node(node_element,"h","0"));的时候并不考虑该对象是否存在!xml_node<>* size = root->first_node("size");size->append_node(doc.allocate_node(node_element, "w", "0"));size->append_node(doc.allocate_node(node_element, "h", "0"));std::string text;rapidxml::print(std::back_inserter(text), doc, 0);std::cout << text << std::endl;std::ofstream out("config.xml");out << doc;}

输出文件config.xml:

<config><color><red>0.1</red><green>0.1</green><blue>0.1</blue><alpha>1.0</alpha></color><size><x>640</x><y>480</y><w>0</w><h>0</h></size><mode fullscreen="false">screen mode</mode>
</config>

1.4 删除节点

void removeNode()
{file<> fdoc("config.xml");xml_document<> doc;doc.parse<0>(fdoc.data());std::string text;rapidxml::print(std::back_inserter(text), doc, 0);std::cout << text << std::endl;xml_node<>* root = doc.first_node();xml_node<>* sec = root->first_node();root->remove_node(sec); //移除根节点下的sec结点(包含该结点下全部结点)text = "删除一个节点\r\n";rapidxml::print(std::back_inserter(text), doc, 0);std::cout << text << std::endl;root->remove_all_nodes(); //移除根节点下全部结点text = "删除全部节点\r\n";rapidxml::print(std::back_inserter(text), doc, 0);std::cout << text << std::endl;std::ofstream out("test.xml");out << doc;}

输出文件test.xml:

<config><color><red>0.1</red><green>0.1</green><blue>0.1</blue><alpha>1.0</alpha></color><size><x>640</x><y>480</y><w>0</w><h>0</h></size><mode fullscreen="false">screen mode</mode>
</config>删除一个节点<config><size><x>640</x><y>480</y><w>0</w><h>0</h></size><mode fullscreen="false">screen mode</mode>
</config>删除全部节点<config/>

2 问题记录

2.1 错误 C3861 “print_children”: 找不到标识符

在这里插入图片描述
解决方法:
在print_node函数处,rapidxml_print.hpp 104行,前置声明调用到的函数

template<class OutIt, class Ch>
inline OutIt print_children(OutIt out, const xml_node<Ch>* node, int flags, int indent);template<class OutIt, class Ch>
inline OutIt print_element_node(OutIt out, const xml_node<Ch>* node, int flags, int indent);template<class OutIt, class Ch>
inline OutIt print_data_node(OutIt out, const xml_node<Ch>* node, int flags, int indent);template<class OutIt, class Ch>
inline OutIt print_cdata_node(OutIt out, const xml_node<Ch>* node, int flags, int indent);template<class OutIt, class Ch>
inline OutIt print_declaration_node(OutIt out, const xml_node<Ch>* node, int flags, int indent);template<class OutIt, class Ch>
inline OutIt print_comment_node(OutIt out, const xml_node<Ch>* node, int flags, int indent);template<class OutIt, class Ch>
inline OutIt print_doctype_node(OutIt out, const xml_node<Ch>* node, int flags, int indent);template<class OutIt, class Ch>
inline OutIt print_pi_node(OutIt out, const xml_node<Ch>* node, int flags, int indent);

原文连接: https://www.cnblogs.com/rainbow70626/p/10386131.html


http://chatgpt.dhexx.cn/article/iS9CvVPb.shtml

相关文章

使用rapidxml解析xml

rapidxml是一个由C模板实现的高效率xml解析库&#xff0c;号称解析速度比tinyxml快50倍&#xff08;忽悠&#xff09;&#xff0c;并作为boost::property的内置解析库&#xff1a; 其独立版本的官网&#xff1a;http://rapidxml.sourceforge.net/ 使用rapidxml的方法tinyxml极其…

RapidXml读取并修改XML文件

RapidXml读取并修改XML文件 RapidXml介绍RapidXml读取与修改xml文件 RapidXml介绍 RapidXml尝试创建最快的XML解析器&#xff0c;同时保留可用性&#xff0c;可移植性和合理的W3C兼容性。它是一个用现代C 编写的原位解析器&#xff0c;解析速度接近strlen在同一数据上执行的函数…

c++开源库rapidxml介绍与示例

官方地址&#xff1a;http://rapidxml.sourceforge.net/ 官方手册&#xff1a;http://rapidxml.sourceforge.net/manual.html 也可以在github上下载到别人上传的rapidxml:https://github.com/dwd/rapidxml 1.头文件 一般我们用到的头文件只有这三个 #include "rapidx…

Ubuntu 18.04 LDAP认证

将ubuntu配置为通过ldap认证&#xff0c;使其成为ldap client&#xff0c;系统版本ubuntu 18.04。 一 软件安装 apt-get install ldap-utils libpam-ldap libnss-ldap nslcd配置1 配置2 配置3 配置4 配置5 配置6 配置7 配置8 配置8 二 认证方式中添加Ldap #auth-client-conf…

LDAP认证服务器

1.要准备的环境与软件(这里测试环境是Centos6.0-64位系统) alfresco-community-4.2.c-installer-linux-x64.bin (注: alfresco是一个免费开源系统&#xff0c;可以自己去下载) apache-tomcat-7.0.42.tar db-4.5.20.tar jdk-6u45-linux-x64.bin openldap-stable-20100219.tar ph…

Jumpserver部署+Ldap认证

内容导航 &#xff08;一&#xff09;jumpserver快速部署1&#xff0c;部署内容2&#xff0c;附上安装脚本3&#xff0c;解决github无法连接4&#xff0c;修改配置 &#xff08;二&#xff09;使用jumpserver1&#xff0c;登录信息2&#xff0c;添加主机3&#xff0c;web终端登…

SVN使用LDAP认证

前言 SVN架构 用户访问SVN服务器分为两个部分&#xff1a;认证与授权。 SVN内置了有认证与授权机制&#xff0c;其认证是通过SVN仓库内的passwd文件提供&#xff0c;但它是明文、静态的&#xff0c;不方便且安全性低。 SVN还支持外部的认证&#xff0c;比如SASL&#xff0c;…

ldap 认证 java_Java实现LDAP认证(上)

Baidu脑残&#xff0c;把原来的空间改得不伦不类。所以把一些技术的东西挪到这里。 我找到两种方法&#xff0c;大同小异&#xff0c;第一种是通过Spring&#xff0c;适合已经采用Spring的项目。 一般来说用户名和密码都是保存在数据库中。现在有这个需求&#xff0c;用户名和密…

Harbor 整合ldap认证

前提&#xff1a; ldap服务器已经安装&#xff1a;OpenLDAP安装部署 harbor服务器已经安装&#xff1a;Harbro v1.8.0部署 一、ldap组织结构 1、登录信息 2、查看用户信息 二、harbor配置 1、使用默认密码登录&#xff0c;admin/Harbor12345 2、认证模式 3、测试ldap服务器…

ldap认证 java_Java实现LDAP认证(上) | 学步园

Baidu脑残&#xff0c;把原来的空间改得不伦不类。所以把一些技术的东西挪到这里。 我找到两种方法&#xff0c;大同小异&#xff0c;第一种是通过Spring&#xff0c;适合已经采用Spring的项目。 一般来说用户名和密码都是保存在数据库中。现在有这个需求&#xff0c;用户名和密…

Zabbix 整合ldap认证

前提&#xff1a; zabbix部署完成&#xff1a;CentOS7.3 64位&#xff0c;搭建Zabbix3.4 ldap部署完成&#xff1a;OpenLDAP安装部署 一、LDAP服务端 1、ldap登录信息 2、查看ldap组织架构 3、添加zabbix默认用户Admin 二、Zabbix网页端 1、使用zabbix默认管理员用户登录 …

linux+配置ldap认证,Linux LDAP 认证配置

Linux通过LDAP方式&#xff0c;使用windows AD帐户登录linux shell&#xff0c;这个想法很cool吧。之前配置过一次&#xff0c;但过了太久忘记了&#xff0c;因此&#xff0c;今天把配 Linux通过LDAP方式&#xff0c;使用windows AD帐户登录linux shell&#xff0c;这个想法很c…

JumpServer 整合ldap认证

前提&#xff1a; ldap服务器已经安装&#xff1a;OpenLDAP安装部署 一、JumpServer安装 官网安装地址安装部署 - JumpServer 文档 1、一键部署 #系统版本 [rootlocalhost ~]# cat /etc/redhat-release CentOS Linux release 7.6.1810 (Core) #默认会安装到 /opt/jumpser…

linux samba 配置ldap认证,Samba集成Ldap认证

Samba集成Ldap认证 1.基础安装 yum -y install samba-common samba samba-client smbldap-tools openldap-clients nss-pam-ldapd 2.配置authconfig-tui 执行命令 "authconfig-tui" 验证配置 # getent passwd zhangsan:x:6460:18650:zhangsan:/home/zhangsan:/bin/…

SVN集成LDAP认证

如何将 LDAP 的认证&#xff0c;集成到 SVN 中。集成的办法&#xff0c;目前是有两种&#xff1a;一种是 SVN 直接通过 SVN 端口直接访问的&#xff0c;通过 SASL 实现 LDAP 的认证&#xff1b;另一种是 SVN 通过 Apache 进行 HTTP 访问的用户&#xff0c;通过配置 Apache &…

zabbix配置ldap认证

zabbix配置ldap认证 环境&#xff1a; centos6.6 zabbix3.0.3 域控服务器&#xff1a;windows-active server 2008 需求&#xff1a; 公司越来越大&#xff0c;人越来越多&#xff0c;配置人员的账号密码很麻烦。 为了集中管理&#xff0c;整合公司的用户密码&#xff0c…

LDAP认证-ldap介绍

OpenLDAP简介 LDAP 全称轻量级目录访问协议&#xff0c;是一个运行在 TCP/IP 上的目录访问协议。LDAP实现 提供被称为目录服务的信息服务&#xff0c;可以看做是一张特殊的数据库系统。可以有效的 解决众多网络服务的用户账户问题&#xff0c;规定了统一的身份信息数据库、身份…

LDAP认证

注&#xff1a;本文由网络公开资料整理而来&#xff0c;如有错误&#xff0c;欢迎指正。 LDAP&#xff08;Lightweight Directory Access Protocol&#xff09;是目录服务&#xff08;DAP&#xff09;在TCP/IP上的实现&#xff0c;它是对X.500目录协议的移植&#xff0c;但是简…

BlazeDS简单介绍

BlazeDS 是一个基于服务器的 Java 远程控制 (remoting) 和 Web 消息传递 (messaging) 技术&#xff0c;以LGPL&#xff08;Lesser GNU Public License&#xff09;公共许可证书发布。它能够使得后端的 Java 应用程序和运行在浏览器上的 Adobe Flex 应用程序相互通信。在Java应用…

关于BLAS的简单介绍

BLAS(Basic Linear Algebra Subprograms基础线性代数程序集)是进行向量和矩阵等基本线性代数操作的事实上的数值库。这些程序最早在1979年发布&#xff0c;是LAPACK(Linear Algebra PACKage)的一部分&#xff0c;便于建立功能更强的数值程序包。BLAS库在高性能计算中被广泛应用…