Demetrius Cassidy wrote:
"Johan Nilsson" wrote in message news:...
Well, something along the lines of this should work (caution: not
tested): ptree technologies; /* load xml */ for
(ptree::const_iterator iter = technologies.begin(); iter !=
technologies.end(); ++iter) { std::cout << "ID: " <<
(*iter).getstd::string("<xmlattr>.ID") << '\n' }
HTH // Johan
Unfortunally this does not work, *iter returns ptree::value_type, so
even if I could do
std::cout << "ID: " <<
(*iter).second.getstd::string("<xmlattr>.ID") << '\n',
it will throw "ptree_bad_path" because it can't find the key.
It will also throw with get("Technologies.Logistics") and
get_child(...).
I said I didn't test it - it required a little tweaking:
---
#include
#include
#include <sstream>
#include <iostream>
using namespace boost::property_tree;
std::stringstream data(
"<Technologies>"
" "
" <DisplayName>Damage Diagnostics</DisplayName>"
" <Cost>1500</Cost>"
" <Description>Increases repair ability by 10%</Description>"
" <RepairAbility>10</RepairAbility>"
" <Requires>Advanced Starship Repair</Requires>"
" <Category>Logistics</Category>"
" <Model>lrgbuilding0</Model>"
" <AIValue>30</AIValue>"
" </Logistics>"
" "
" <DisplayName>Basic Self-Repair</DisplayName>"
" <Cost>3000</Cost>"
" <Description>Increases repair ability by 10%</Description>"
" <RepairAbility>10</RepairAbility>"
" <Requires>Damage Diagnostics</Requires>"
" <Category>Logistics</Category>"
" <Model>controlgrav0</Model>"
" <AIValue>40</AIValue>"
" </Logistics>"
"</Technologies>");
ptree pt;
read_xml(data, pt);
ptree technologies = pt.get_child("Technologies");
for (ptree::const_iterator iter = technologies.begin(); iter !=
technologies.end(); ++iter)
{
std::string const & name = (*iter).first;
ptree const& logistics = (*iter).second;
std::cout << name << ": ID = " <<
logistics.getstd::string("<xmlattr>.ID") << '\n';
}
---
// Johan