2

I load a boost::property_tree::ptree from an XML-file, that looks somewhat like this:

<bla>
   <foo>
       <element id="1" type="..." path="..."/>
       <element id="2" type="..." path="..."/>
       <element id="3" type="..." path="..."/>
       <otherelement/>
   </foo>
</bla>

I load that into a property-tree with read_xml. Now I want to build a vector containing structs, that resemble the element-tags. I can do the following:

BOOST_FOREACH(ptree::value_type& node, tree.get_child("bla.foo"))
{
    if (node.first == "element")
    {
                 ...
    }
}

So far it's good, but I have problems to get the data in the element. node.second should contain that, but how do I access it properly? node.second.get("xmlattr.type") don't work.

Mnementh
  • 50,487
  • 48
  • 148
  • 202

1 Answers1

0

After using the Google-Fu in the right way, I found an answer myself in this blogentry. The correct way is node.second.get<std::string>("<xmlattr>.type"). Except I got the xmlattr-thing wrong, the way to avoid the compiler-error I got is the use of the template-syntax.

Mnementh
  • 50,487
  • 48
  • 148
  • 202