I'm using boost::property_tree
. The documentation is very vague and overall unhelpful for the most part. Looking at the source/examples didn't help that much, either.
What I'm wondering is the following:
<VGHL>
<StringTable>
<Language>EN</Language>
<DataPath>..\\Data\\Resources\\Strings\\stringtable.bst</DataPath>
</StringTable>
</VGHL>
How can I iterate over all the elements at the current level? If I do this:
read_xml(fin, bifPropTree);
VGHL::String tablePath;
BOOST_FOREACH(boost::property_tree::wiptree::value_type &v,
bifPropTree.get_child(L"VGHL.StringTable"))
{
m_StringTable->ParseEntry(v.second, tablePath);
}
In ParseEntry
I try this:
VGHL::String langName = stringTree.get<VGHL::String>(L"StringTable.Language");
Results in an exception (not doesn't exist). I've also tried this:
VGHL::String langName = stringTree.get<VGHL::String>(L"Language");
Same problem.
From my understanding when I call ParseEntry
I am passing a reference to the tree at that node.
Is there any way to deal with this, when I have multiple entries of StringTable
using property tree?
I've not used the property tree, but probably will as it looks nifty. A few quick observations though:
Should not the template parameter of get be the same as the return type?
VGHL::String langName = stringTree.get(...);
But this is most likely not a problem here, as this would have resulted in compile-time error.
Not sure if L"VGHL.StringTable.Language" argument works?
ParseEntry receives a reference to each of the children nodes of the current level. So, you cannot ask the values using the node name, because you already have a child node. The node name is stored in v.first.
You can iterate over all the elements at a given level using get_child to select the level and then BOOST_FOREACH to iterate. Each iterator will be a pair representing the name of the node and the node data:
This code would print:
If you do not want to iterate, you can select the node level and then look for the nodes using their name:
This code would print: