当前位置: 首页 > wzjs >正文

福建省建设局网站抖音关键词排名查询工具

福建省建设局网站,抖音关键词排名查询工具,东莞网站建设是什么意思,陕西省住房和城乡建设部网站2023年10月11日,周三下午 目录 RapidXML的官网使用rapidXML读取XML文件中的元素的属性和值此次要读取的XML文件:ReadExample.xml用于读取此XML文件的C代码运行结果使用rapidXML创建XML文件用于创建XML文件的C代码 如果上面的代码无法运行运行结果​编辑…

2023年10月11日,周三下午


目录

  • RapidXML的官网
  • 使用rapidXML读取XML文件中的元素的属性和值
  • 此次要读取的XML文件:ReadExample.xml
  • 用于读取此XML文件的C++代码
  • 运行结果
  • 使用rapidXML创建XML文件
  • 用于创建XML文件的C++代码
  •  如果上面的代码无法运行
  • 运行结果
  • ​编辑 

RapidXML的官网

https://rapidxml.sourceforge.net/

RapidXML只有头文件,不需要编译和配置。


使用rapidXML读取XML文件中的元素的属性和值

此次要读取的XML文件:ReadExample.xml

<?xml version="1.0" encoding="UTF-8"?> <!-- XML声明,指定版本和编码 --> 
<root> <!-- 根元素 --> <Connector connectionTimeout="20000" maxParameterCount="1000" port="8088" protocol="HTTP/1.1" redirectPort="8443"/><!--子元素Connector--><book> <!-- 子元素book --><name>C++ Primer</name><author>Stanley B. Lippman</author><price>59.00</price></book> <book><name>Head First Java</name><author>Kathy Sierra</author><price>35.99</price></book> 
</root>

用于读取此XML文件的C++代码

#include "rapidxml.hpp"
#include <iostream>
#include <fstream>int main() {rapidxml::xml_document<> doc;// 打开XML文件std::ifstream file("ReadExample.xml");if (!file) {std::cerr << "Failed to open the XML file." << std::endl;return 1;}// 读取XML文件内容到内存std::string xml_contents((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());file.close();// 解析XML文档doc.parse<rapidxml::parse_default>(&xml_contents[0]);// 获取根元素rapidxml::xml_node<>* root = doc.first_node("root");// 遍历子元素bookfor (rapidxml::xml_node<>* book = root->first_node("book"); book; book = book->next_sibling("book")) {// 获取书名rapidxml::xml_node<>* name = book->first_node("name");if (name) {std::cout << "Book Name: " << name->value() << std::endl;}// 获取作者rapidxml::xml_node<>* author = book->first_node("author");if (author) {std::cout << "Author: " << author->value() << std::endl;}// 获取价格rapidxml::xml_node<>* price = book->first_node("price");if (price) {std::cout << "Price: " << price->value() << std::endl;}std::cout << std::endl;}// 获取Connector元素的属性rapidxml::xml_node<>* connector = root->first_node("Connector");if (connector) {std::cout << "Connector Attributes:" << std::endl;for (rapidxml::xml_attribute<>* attr = connector->first_attribute(); attr; attr = attr->next_attribute()) {std::cout << "Attribute Name: " << attr->name() << ", Value: " << attr->value() << std::endl;}}return 0;
}

运行结果

使用rapidXML创建XML文件

用于创建XML文件的C++代码

#include "rapidxml.hpp"
#include "rapidxml_print.hpp" // 用于格式化输出XML
#include <iostream>
#include <fstream>int main() {rapidxml::xml_document<> doc;// 创建根元素rapidxml::xml_node<>* root = doc.allocate_node(rapidxml::node_element, "root");doc.append_node(root);// 创建一个元素bookrapidxml::xml_node<>* book = doc.allocate_node(rapidxml::node_element, "book");root->append_node(book);// 创建book元素的子元素rapidxml::xml_node<>* name = doc.allocate_node(rapidxml::node_element, "name", "C++ Primer");book->append_node(name);rapidxml::xml_node<>* author = doc.allocate_node(rapidxml::node_element, "author", "Stanley B. Lippman");book->append_node(author);rapidxml::xml_node<>* price = doc.allocate_node(rapidxml::node_element, "price", "59.00");book->append_node(price);// 创建第二个book元素book = doc.allocate_node(rapidxml::node_element, "book");root->append_node(book);name = doc.allocate_node(rapidxml::node_element, "name", "Head First Java");book->append_node(name);author = doc.allocate_node(rapidxml::node_element, "author", "Kathy Sierra");book->append_node(author);price = doc.allocate_node(rapidxml::node_element, "price", "35.99");book->append_node(price);// 输出XML到文件std::ofstream file("created.xml");file << doc;file.close();return 0;
}

 如果上面的代码无法运行

如果你也遇到了如下这样的错误

那么可以按照下面这两篇文章来创建一个rapidxml_ext.hpp文件

c++ - RapidXML:无法打印 - 编译时错误 - IT工具网 (coder.work)

c++ - RapidXML: Unable to print - Compile-time Error - Stack Overflow 

rapidxml_ext.hpp文件的代码如下 

//rapidxml_ext.hpp
#pragma once#include "rapidxml.hpp"// Adding declarations to make it compatible with gcc 4.7 and greater
// See https://stackoverflow.com/a/55408678
namespace rapidxml {namespace internal {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_attributes(OutIt out, const xml_node<Ch>* node, int flags);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_element_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);}
}#include "rapidxml_print.hpp"

 然后在原来的代码的基础上,引入头文件rapidxml_ext.hpp

注意头文件的顺序,rapidxml_ext.hpp的引入必须先于rapidxml_print.hpp

改正的代码后如下

#include "rapidxml.hpp"
#include "rapidxml_ext.hpp"  //只多了这一行
#include "rapidxml_print.hpp" // 用于格式化输出XML
#include <iostream>
#include <fstream>int main() {rapidxml::xml_document<> doc;// 创建根元素rapidxml::xml_node<>* root = doc.allocate_node(rapidxml::node_element, "root");doc.append_node(root);// 创建一个元素bookrapidxml::xml_node<>* book = doc.allocate_node(rapidxml::node_element, "book");root->append_node(book);// 创建book元素的子元素rapidxml::xml_node<>* name = doc.allocate_node(rapidxml::node_element, "name", "C++ Primer");book->append_node(name);rapidxml::xml_node<>* author = doc.allocate_node(rapidxml::node_element, "author", "Stanley B. Lippman");book->append_node(author);rapidxml::xml_node<>* price = doc.allocate_node(rapidxml::node_element, "price", "59.00");book->append_node(price);// 创建第二个book元素book = doc.allocate_node(rapidxml::node_element, "book");root->append_node(book);name = doc.allocate_node(rapidxml::node_element, "name", "Head First Java");book->append_node(name);author = doc.allocate_node(rapidxml::node_element, "author", "Kathy Sierra");book->append_node(author);price = doc.allocate_node(rapidxml::node_element, "price", "35.99");book->append_node(price);// 输出XML到文件std::ofstream file("created.xml");file << doc;file.close();return 0;
}

运行结果

 

 

http://www.dtcms.com/wzjs/68621.html

相关文章:

  • 定制营销型网站外链工具xg
  • 柳州哪家公司做网站好网络销售推广是做什么的具体
  • 怎样创建基本的网站菏泽seo
  • 移动网站制作百度关键词数据
  • 上海app开发网站建设天津seo建站
  • 北京做网站哪家好谷歌推广开户
  • 广州一网通注册公司优化设计数学
  • 淮南网云小镇最新动态济南seo关键词优化方案
  • 广州玩的地方有哪些地方网站关键字排名优化
  • 上海 餐饮网站建设 会员系统快速排名推荐
  • 做电影网站还能赚钱海外seo
  • dede做招聘网站企业营销战略
  • 清河做网站哪里好友链购买有效果吗
  • 网站ip过万网络营销项目策划方案
  • led网站建设免费的网站推广平台
  • 网站开发藏语seo推广主要做什么的
  • 世界羽联最新排名南京百度网站快速优化
  • html网站源码下载厦门seo搜索引擎优化
  • 网站开发公司电话网络营销策划方案ppt模板
  • 昆明市住房和城乡建设局门户网站谷歌商店下载安装
  • 专门做继电器的网站网站优化关键词排名
  • 有哪些做婚品的网站合肥网站关键词优化公司
  • 上海自适应网站建设seo点击排名软件哪家好
  • 淘宝客怎么做直播网站吗苹果要做搜索引擎
  • 怎样做网站域名注册优化网站排名解析推广
  • 长沙做网站哪家好最近新闻报道
  • 做网站江西上海seo公司哪家好
  • 代做网站怎么进行域名备案河南省人民政府
  • 这么联系做网站推广谷歌浏览器下载电脑版
  • 贞丰县住房和城乡建设局网站成品短视频app下载有哪些软件