3

I have the following structure of an xml file

<?xml version="1.0" encoding="UTF-8"?>
<section name="pvf">
    <section name="p1">
        <item value="92.31335795746914" key="x"/>
        <item value="-746.7962776760924" key="y"/>
        <item value="400.1902893301479" key="z"/>
        <item value="1" key="u1"/>
        <item value="7" key="type"/>
        <item value="Inlet 2" key="value"/>
    </section>
</section>

I like to read the x, y and z values into an std::array<float,3> point

I could itaterate over all items with

for (const auto &v : subtree.get_child(""))

and than

if (item.get<std::string>("<xmlattr>.key") == "x") {
    point[0] = item.get<float>"<xmlattr>.value");
}

and likewise for y and z.

Is there a more elegant way to read this?

Can I use the notation

m_level = pt.get("p1.x", 0);

like in the boost documentation

schorsch312
  • 5,553
  • 5
  • 28
  • 57

0 Answers0