property tree修改xml文件内容

#include<iostream>
#include<fstream>
#include<iomanip>
#include<vector>
#include<boost/property_tree/ptree.hpp>
#include<boost/property_tree/xml_parser.hpp>
#include<boost/foreach.hpp>
#include<string>


void handle_monitor(std::string a, std::string b, std::string c,std::string d);
void recure(boost::property_tree::ptree &pt);

int main()
{
std::string input = "1000";
std::string input1 = "8000";
std::string input2 = "aaa";
std::string input3 = "/public/proc/traderaaa";
std::string input4 = "/public/proc/monitoraaa";
handle_monitor(input, input1, input3,input4);
}
void handle_monitor1(std::string a, std::string b, std::string c,std::string d){
std::string filename = "H:\\config\\acsymonitor.xml";
boost::property_tree::ptree pt;
boost::property_tree::xml_parser::read_xml(filename, pt);
pt.put("config.subport", a);                       //修改xml节点里面的内容
pt.put("config.swebport", b);
pt.put("root.tradernode", c);
pt.put("root.monitornode", d);


recure(pt);
boost::property_tree::xml_parser::xml_writer_settings<boost::property_tree::ptree::key_type> settings('\t',1,"GB2312");
boost::property_tree::xml_parser::write_xml("H:\\config\\acsymonitor.xml", pt,std::locale(),settings);
}
void recure(boost::property_tree::ptree &pt)             //递归遍历xml里面的节点
{
for (auto &m : pt)
{
if (m.second.get_value<std::string>().find("\n\t") != -1)
{
m.second.put_value("");
}
std::cout << m.first << " , " << m.second.get_value<std::string>() << std::endl;
recure(m.second);
}


}
/*****************xml文件******************/
<config>
<subport>10004</subport>
<swebdir>D:\Project\server\src\web</swebdir>
<database>E:\trade\config\all_cnfut_db_gy.dat</database>
<filenameURL>H:\tesrt</filenameURL>
<logURL>E:\trade\log\trade_log_acsy001.log</logURL>
<swebport>8007</swebport>
<distbin>D:\Project\tradesrc\bin\Debug</distbin>
</config>
<root>
<peer>
<url>tcpconnector://127.0.0.1:10048</url>
</peer>
<tradernode>/public/proc/traderywj2</tradernode>
<monitornode>/public/proc/monitorywj2</monitornode>
</root>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值