boost::xml_parser 处理xml
---------debug_settings.xml--------
[html]
--------main.cpp--------
[html]
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
static const string str_node_name[] = {"id","name","accout"};
struct xmlStageDetail
{
string id;
string name;
string accout;
};
int load(const char* filename,vector
{
xmlStageDetail xml_stage_detail;
using boost::property_tree::ptree;
ptree pt;
ptree root;
try
{
read_xml(filename, pt);
cout <<"获取数据" <
root = pt.get_child("root");
}
catch (std::exception& e)
{
std::cout <<"Error: " <
return -1;
}
cout <<"root的长度:" <
int ita = pt.get
string cattr = pt.get
cout <<"root.strage.id:" <
for (ptree::iterator itr = root.begin();itr!=root.end();itr++)
{
ptree strage = itr->second;
string ssv = strage.data();
string sattr = strage.get
int iattr = strage.get
float fattr = strage.get
boost::trim
cout <
for (int i = 0;i<3;i++)
{
ptree pt;
string str_value;
try
{
pt = strage.get_child(str_node_name[i]);
str_value = pt.data();
cout <
}
catch (std::exception& e)
{
cout<
return -1;
}
switch (i)
{
case 0:
xml_stage_detail.id = str_value;
break;
case 1:
xml_stage_detail.name = str_value;
break;
case 2:
xml_stage_detail.accout = str_value;
break;
}
}
m_xml_detail->push_back(xml_stage_detail);
}
return 0;
}
int main()
{
vector
try
{
load("debug_settings.xml",&m_xml_detail);
std::cout <<"Success\n";
}
catch (std::exception &e)
{
std::cout <<"Error: " <
return -1;
}
return 0;
}
运行结果如下: