问题描述
使用以下 xml 消息格式,我试图读取键“邮政编码”的值。即“90952”
<list>
<address>
<key>Name</key>
<string>Alice Smith</string>
<key>state</key>
<string>CA</string>
<key>zip code</key>
<string>90952</string>
</address>
</list>
我正在尝试如下所示。有人可以帮助我如何进行此操作以获取邮政编码的值并将其存储到字符串中:
#include <iostream>
#include <boost/property_tree/xml_parser.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/foreach.hpp>
using namespace std;
const std::string XML_PATH1 = "C://Project//JSONSampleApp//test1.xml";
int main()
{
boost::property_tree::ptree pt1;
boost::property_tree::read_xml(XML_PATH1,pt1);
BOOST_FOREACH(boost::property_tree::ptree::value_type const& node,pt1.get_child("list"))
{
if (node.first == "address")
{
std::string test1 = node.second.get<std::string>("key");
}
}
return 0;
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)