boost读取xml
来源:互联网 发布:眼部干纹 知乎 编辑:程序博客网 时间:2024/05/22 05:21
1. include
#include <boost/property_tree/ptree.hpp> #include <boost/property_tree/xml_parser.hpp> #include <boost/foreach.hpp> using namespace boost::property_tree;
2. Source code
bool load(){ptree pt; try{read_xml("CPublishCommonCfg.xml",pt); ptree child = pt.get_child("Publish"); BOOST_FOREACH(ptree::value_type &service, child){ ServiceInfoPtr service_info(new ServiceInfo());service_info->service_name = service.first.data();std::map<std::string,std::string> map;if (!service.second.empty()) {BOOST_FOREACH(ptree::value_type &model, service.second){std::string type = model.first.data();transform(type.begin(),type.end(),type.begin(), ::tolower);<span style="white-space:pre"></span>if(type == "in"){service_info->in_queue = model.second.data();}else if(type == "model"){std::string name;std::string out;if(!model.second.empty()){BOOST_FOREACH(ptree::value_type &leaf, model.second){std::string type = leaf.first.data();transform(type.begin(),type.end(),type.begin(), ::tolower);if(type == "name"){name = leaf.second.data();}else if(type == "out"){out = leaf.second.data();}else{LOGGER_ERROR("Leaf type config error: must be model");}}if(!name.empty()&&!out.empty()){service_info->out_queue_map[name] = out;}}} }}else{LOGGER_WARN("service node can't be a leaf");}service_conf_.push_back(service_info);} }catch (std::exception const& ex){LOGGER_ERROR("Can't init settings: "<<ex.what());}return true;}
3.xml
<Publish> <Service> <In>CQ.SDBUS.CSwap.PublishQueue.Quote</In> <Model1> <Name>A</Name> <Out>QUEUE1</Out> </Model1> <Model2> <Name>B</Name> <Out>QUEUE2</Out> </Model2> <Model3> <Name>C</Name> <Out>QUEUE3</Out> </Model3> </Service><Publish>
0 0
- Boost读取XML配置文件
- boost::xml_parser 读取xml
- boost读取xml文件
- boost读取xml
- 使用boost读取XML文件
- c++使用boost读取xml文件
- 使用boost库读取XML文件
- boost::property_tree读取解析.xml文件
- boost xml
- boost xml
- boost xml
- Easier XML With Boost
- boost 读写 XML 文件
- boost解析xml文件
- BOOST XML解析
- boost库读写xml
- 读取XML
- 读取XML
- json格式和中的转义字符
- web开发自适应
- Jmeter接口测试(附件上传)
- 基于深度学习的图像语义分析及其应用
- hdoj ASCII码排序
- boost读取xml
- 选择排序与冒泡排序
- HDU 1142(单源最短路,记忆DFS)
- Leetcode: Binary Tree Longest Consecutive Sequence
- 关于HttpClient的总结
- 引导页面的现实
- OC基础
- Zend Studio 导入项目:某些项目因位于工作空间目录而被隐藏
- U3D开发项目总结