0

我有一个这样的 XML 文件:

 <shape name="rightellipsoid" type="instance" id="eggBase">
    <transform name="xform1">
      <translate>2.5 1.5 -4.0</translate>
      <rotate axis="X">90.0</rotate>
      <scale>1.0 0.5 1.5</scale>
      <rotate axis="Y">95.0</rotate>
    </transform>
  </shape>

我可以使用以下方法检索 translate 和 scale 的值:

boost::optional<Vector3D> scale = v.second.get_optional<Vector3D>("scale");

注意:Vector3D 是我的数据类型

但是如果我对我的旋转节点做同样的事情,它总是返回第一个值。如何获得第二个旋转节点的值?

4

1 回答 1

1

尝试这样的事情:

std::string rotate_x, rotate_y;
boost::property_tree::ptree pt;

BOOST_FOREACH( ptree::value_type const& val, pt.get_child("shape.transform") ) 
{
    if(val.first == "rotate") 
    {
        std::string temp = val.second.get_child("<xmlattr>.axis").data();

        if(temp == "X") rotate_x = val.second.data();
        if(temp == "Y") rotate_y = val.second.data();
    }
}
于 2013-11-07T09:18:56.410 回答