小编gro*_*999的帖子

使用Boost解析XML属性

我想与您分享我在尝试使用Boost库(版本1.52.0)处理C++中XML元素的某些属性时遇到的问题.给出以下代码:

#define ATTR_SET ".<xmlattr>"
#define XML_PATH1 "./pets.xml"

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

using namespace std;
using namespace boost;
using namespace boost::property_tree;

const ptree& empty_ptree(){
    static ptree t;
    return t;
}

int main() {
    ptree tree;
    read_xml(XML_PATH1, tree);
    const ptree & formats = tree.get_child("pets", empty_ptree());
    BOOST_FOREACH(const ptree::value_type & f, formats){
        string at = f.first + ATTR_SET;
        const ptree & attributes = formats.get_child(at, empty_ptree());
        cout << "Extracting attributes from " << at << ":" << endl;
        BOOST_FOREACH(const …
Run Code Online (Sandbox Code Playgroud)

c++ xml boost boost-propertytree

17
推荐指数
1
解决办法
3万
查看次数

标签 统计

boost ×1

boost-propertytree ×1

c++ ×1

xml ×1