Parsing XML Attributes with Boost

后端 未结 3 2017
北恋
北恋 2020-12-08 15:56

I would like to share with you an issue I\'m having while trying to process some attributes from XML elements in C++ with Boost libraries (version 1.52.0). Given the followi

3条回答
  •  [愿得一人]
    2020-12-08 16:59

    File to be parsed, pets.xml

    
        
            
             
        
        
             
        
        
            
            
        
    
    

    code:

    // DemoPropertyTree.cpp : Defines the entry point for the console application.
    //Prerequisite boost library
    
    #include "stdafx.h"
    #include 
    #include 
    #include 
    #include
    using namespace std;
    using namespace boost;
    using namespace boost::property_tree;
    
    void processPet(ptree subtree)
    {
        BOOST_FOREACH(ptree::value_type petChild,subtree.get_child(""))
        {
            //processing attributes of element pet
            if(petChild.first=="")
            {
                BOOST_FOREACH(ptree::value_type petAttr,petChild.second.get_child(""))
                {
                    cout<")
                    {
                        BOOST_FOREACH(ptree::value_type somethingAttr,somethingChild.second.get_child(""))
                        {
                            cout<")
            {
                BOOST_FOREACH(ptree::value_type birdsAttr,birdsChild.second.get_child(""))
                {
                    cout<")
                    {
                        BOOST_FOREACH(ptree::value_type birdAttr,birdChild.second.get_child(""))
                        {
                            cout<

    The output is shown here: output

提交回复
热议问题