Reading xml with boost
Hi!
I am using property tree from boost to parse an xml-file.
It was working finu until I meet this:
<charging_functions>
<function cs_type="fast">
<breakpoint>
<battery_level>0</battery_level>
<charging_time>0.0</charging_time>
</breakpoint>
<breakpoint>
<battery_level>13600</battery_level>
<charging_time>0.31</charging_time>
</breakpoint>
<breakpoint>
<battery_level>15200</battery_level>
<charging_time>0.39</charging_time>
</breakpoint>
<breakpoint>
<battery_level>16000</battery_level>
<charging_time>0.51</charging_time>
</breakpoint>
</function>
</charging_functions>
I wanted to read each breakpoint and I did this:
boost::property_tree::ptree pt;
read_xml("test.xml", pt);
BOOST_FOREACH(boost::property_tree::ptree::value_type & v, pt.get_child("charging_functions.function")) {
double t = v.second.get<double>("charging_time");
double y = v.second.get<double>("battery_level");
}
I get the error: ERROR: No such node (charging_time)
However, if I remove "cs_type="fast"" from the <function cs_type="fast"> part, then it works fine.
Anybody know what I am doing wrong?
Thanks!
Posted Oct 17, 2021, 2:04 PM UTC
16