boost 遍历XML 取id值
xml数据格式如下:
<root>
<nodes>
<node>
<id>001</id>
<name>a</name>
</node>
<node>
<id>001</id>
<name>a</name>
</node>
<node>
<id>001</id>
<name>a</name>
</node>
</nodes>
</root>
boost遍历程序如下:
std::vector<std::string> usersid;
{
std::string alluserid;
bool ret = this->m_cc->UserGetAll(alluserid);
std::istringstream xmlusrid_str;
xmlusrid_str.str(alluserid);
boost::property_tree::ptree pt;
boost::property_tree::xml_parser::read_xml(xmlusrid_str, pt, boost::property_tree::xml_parser::trim_whitespace);
BOOST_AUTO(child, pt.get_child("message.users"));
for(BOOST_AUTO(pos, child.begin()); pos != child.end(); ++pos)
{
BOOST_AUTO(child_paths, pos->second.get_child(""));
std::cout << pos->second.get<std::string>("id")<< std::endl;
std::string tmp_id = pos->second.get<std::string>("id");
usersid.insert(usersid.end(),tmp_id);
}
}