桌面日程安排软件-智能五笔输入法下载
2023年4月5日发(作者:lenovog450)
C++中rapidxml⽤法
解析xml是第三⽅库很多,例如:tingxml,这次学习⼀下rapidxml,rapidxml是⼀个快速的xml库,⽐tinyxml快了50-100倍。
这个库源码⼀共只有四个⽂件分别是:
测试demo:
#include
#include""
#include"rapidxml_"
#include"rapidxml_"
usingnamespacerapidxml;
intCreateXml()
{
rapidxml::xml_document<>doc;
rapidxml::xml_node<>*rot=te_node(rapidxml::node_pi,te_string("xmlversion='1.0'encoding='utf-8'"));
_node(rot);
rapidxml::xml_node<>*node=te_node(rapidxml::node_element,"config","information");
_node(node);
rapidxml::xml_node<>*color=te_node(rapidxml::node_element,"color",NULL);
node->append_node(color);
color->append_node(te_node(rapidxml::node_element,"red","0.1"));
color->append_node(te_node(rapidxml::node_element,"green","0.1"));
color->append_node(te_node(rapidxml::node_element,"blue","0.1"));
color->append_node(te_node(rapidxml::node_element,"alpha","1.0"));
rapidxml::xml_node<>*size=te_node(rapidxml::node_element,"size",NULL);
size->append_node(te_node(rapidxml::node_element,"x","640"));
size->append_node(te_node(rapidxml::node_element,"y","480"));
node->append_node(size);
rapidxml::xml_node<>*mode=te_node(rapidxml::node_element,"mode","screenmode");
mode->append_attribute(te_attribute("fullscreen","false"));
node->append_node(mode);
std::stringtext;
rapidxml::print(std::back_inserter(text),doc,0);
std::cout<
std::ofstreamout("");
out<
return0;
}
//读取并修改
intReadAndChangeXml()
{
rapidxml::file<>fdoc("");
std::cout<<()<
rapidxml::xml_document<>doc;
<0>(());
std::cout<<()<
//!获取根节点
rapidxml::xml_node<>*root=_node();
std::cout<
//!获取根节点第⼀个节点
rapidxml::xml_node<>*node1=root->first_node();
std::cout<
rapidxml::xml_node<>*node11=node1->first_node();
std::cout<
std::cout<
//!修改之后再次保存
rapidxml::xml_node<>*size=root->first_node("size");
size->append_node(te_node(rapidxml::node_element,"w","1"));
size->append_node(te_node(rapidxml::node_element,"h","1"));
std::stringtext;
rapidxml::print(std::back_inserter(text),doc,0);
std::cout<
std::ofstreamout("../config/");
out<
return0;
}
voidcreatexml()
{
xml_document<>doc;
xml_node<>*root=te_node(node_pi,te_string("xmlversion='1.0'encoding='utf-8'"));
_node(root);
xml_node<>*node=te_node(node_element,"config","information");
_node(node);
xml_node<>*color=te_node(node_element,"color",NULL);
node->append_node(color);
color->append_node(te_node(node_element,"red","0.1"));
color->append_node(te_node(node_element,"green","0.1"));
color->append_node(te_node(node_element,"blue","0.1"));
color->append_node(te_node(node_element,"alpha","0.1"));
xml_node<>*size=te_node(node_element,"size",NULL);
node->append_node(size);
size->append_node(te_node(node_element,"x","640"));
size->append_node(te_node(node_element,"y","500"));
xml_node<>*mode=te_node(rapidxml::node_element,"mode","screenmode");
mode->append_attribute(te_attribute("fullscreen","false"));
node->append_node(mode);
std::stringtext;
rapidxml::print(std::back_inserter(text),doc,0);
std::cout<
std::ofstreamout("");
out<
}
voidreadAndChangexml()
{
file<>fdoc("");
xml_document<>doc;
std::cout<<()<
//<0>(());//修改节点值不会保存到⽂件中
std::cout<<"///"<
std::cout<<()<
//获取根节点
xml_node<>*root=_node();
std::cout<
//!获取根节点第⼀个节点
xml_node<>*node1=root->first_node();
std::cout<
xml_node<>*size=root->first_node("size");
xml_node<>*x=size->first_node("x");
x->value("540");
std::cout<
std::stringtext;
print(std::back_inserter(text),doc,0);
std::cout<
std::ofstreamout("");
out<
}
intmain()
{
//createxml();
readAndChangexml();
//CreateXml();
//system("pause");
return0;
}
更多推荐
rapidxml
发布评论