Boost logo

Boost Users :

Subject: [Boost-users] [propertytree] more beginners questions
From: Dietmar Hummel (hummel_at_[hidden])
Date: 2010-08-21 12:01:25


Hi!

I have some more questions regarding property tree (for parsing xml) and
maybe someone could help me.
Lets assume we have the following xml file to read:

<a>
<b>
<c><d>1</d></c>
<c><d>2</d></c>
<c><d>3</d></c>
<x></x>
</b>
</a>

Now, my idea was to parse all the c-nodes by calling a specific function
for each of them. Something like this...

void parseDNode( const boost::property_tree::ptree& v )
{
    //...
}

void parseCNode( const boost::property_tree::ptree::value_type& v )
{
    parseDNode( v.second.get_child( "d" ) );
}

void load( const std::string& filename )
{
    boost::property_tree::ptree pt;
    boost::property_tree::read_xml(filename, pt);
    BOOST_FOREACH( boost::property_tree::ptree::value_type &v,
pt.get_child( "a.b.c" ) )
    {
        parseCNode( v );
    }
}

----
Now I have several questions for this:
1. The code doesn't work as expected, it just handles the first one of 
the c nodes
2. The function parseCNode() also doesn't work. I assumed that v is a 
reference to the c node where I have to claim the d-node by get_child. 
But it seems v is already pointing to d?
3. I don't understand why BOOST_FOREACH is working with value_type here. 
As far as I see, get_child returns a self_type which should be a ptree? 
See also the different parameter lists for parseCNode and parseDNode...
Thanks in advance....
Regards
Dietmar

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net