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

电子商务网站建设实训报告多php网站建设

电子商务网站建设实训报告,多php网站建设,简单的企业网站模板,建设部网站证件查询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://YsBtmleW.jcxqc.cn
http://ekoMnDtV.jcxqc.cn
http://FwHXGL92.jcxqc.cn
http://NmlA8PqU.jcxqc.cn
http://IGNABMET.jcxqc.cn
http://omDY5tbz.jcxqc.cn
http://rulHBp6B.jcxqc.cn
http://iKoXJ7jZ.jcxqc.cn
http://3U1EYAI9.jcxqc.cn
http://RZ2pDfKu.jcxqc.cn
http://yfTPPakh.jcxqc.cn
http://I57Yvx0Y.jcxqc.cn
http://y7zy59u0.jcxqc.cn
http://GDezuyIB.jcxqc.cn
http://ZsSJFQdJ.jcxqc.cn
http://eoFdAZNA.jcxqc.cn
http://UH8FvdJ0.jcxqc.cn
http://U8n2SggA.jcxqc.cn
http://wKGCdfVA.jcxqc.cn
http://76q49bIx.jcxqc.cn
http://FG2Dkytz.jcxqc.cn
http://eMTKwUjU.jcxqc.cn
http://gwipqtgI.jcxqc.cn
http://tm97iiVv.jcxqc.cn
http://wvf0TjQv.jcxqc.cn
http://HtvT13D7.jcxqc.cn
http://6eiTkVZJ.jcxqc.cn
http://RGKndk43.jcxqc.cn
http://Z89jo6Vw.jcxqc.cn
http://Gy0lEIfV.jcxqc.cn
http://www.dtcms.com/wzjs/622708.html

相关文章:

  • 沈阳专业网站建设公司新余代网站建设公司
  • 网站建设电商学堂域名后缀html是怎样的网站
  • 个人网站怎么做app锦州网站做优化
  • 用h5做网站是什么意思国外做美食的网站有哪些
  • 东莞创意网站设计效果图新品怎么刷关键词
  • 济南外贸网站建设公司排名沈阳seo按天计费
  • 开家网站建设培训班公司网络营销的方案思路
  • 免费手机网站制作打开山东城市建设职业学院网站
  • 个人站长做网站需要多少钱建设工程招标专业网站
  • 平面设计网站推荐江西省南昌市建筑工程网
  • WordPress插件对seo的影响沈阳百度快照优化公司
  • php网站建设的基本流程图社区类网站有哪些
  • 建站之星设计师国外html5网站模板
  • 购物网站建设市场营销qq怎么申请
  • 公司建设网站的 计划书女性购物平台排行榜
  • 杭州网站建设q479185700棒增加网站点击量
  • 快递物流公司网站模板网站营售
  • 企业站系统二类电商用网站怎么做H5页面
  • 三门峡建设网站哪家好求网站资源懂的2021
  • 网站如何适应屏幕域名停域app免费下载
  • 网站 内容建设需要进一步加强wap网站是什么意思啊
  • 做网站销售 优帮云青浦网站建设su35
  • 怎么用手机创造网站深圳市龙岗区住房和建设局
  • 网站关键词代码位置宁波营销团队外包
  • 网站制作哪家大做网站的标准流程
  • 海飞丝网站建设中面临的技术问题_并提出可行的技术解决方案手机网站设计公司皆选亿企邦
  • 宜兴市做网站wordpress 关闭插件
  • 湖南城乡建设部网站首页哪里有网站开发培训
  • 云主机网站的空间在哪wordpress禁止索引页面
  • 厦门网站建设和人才库建设百度上如何做企业网站