使用Boost属性树迭代XML文件中的变量

时间:2011-06-02 19:07:28

标签: c++ boost boost-propertytree

有没有人可以帮助我使用boost属性树迭代我已经获得的XML文件中的变量?

<HLSL>
  <Constants>
    <Constant name ="myObject">
      <Variable name ="matWorld" class ="matrix" type="float" rows="4" cols="4"/>
      <Variable name ="vObjectPosition" class ="vector" type="float" rows="1" cols="3"/>
      <Variable name ="arrayIndex" class ="scalar" type="int" rows="0" cols="0"/>
    </Constant>
  </Constants>
</HLSL>

到目前为止,这是我的代码[它不会超过XML中的第一个变量]

void CFxCompiler::LoadShader(const string& headerName, const string& asmName)
{
    using std::vector;

    // Create an empty property tree object
    iptree pt;

    // Load the XML file into the property tree. If reading fails
    // (cannot open file, parse error), an exception is thrown.
    read_xml(headerName, pt);

    iptree &itorLevel = pt.get_child("HLSL");
    iptree &constLevel = itorLevel.get_child("Constants");
    BOOST_FOREACH(iptree::value_type& constant, constLevel.get_child("Constant"))
    {   
        BOOST_FOREACH(iptree::value_type& constAttrib, constLevel.get_child("Constant.<xmlattr>"))
        {
            std::string bufferName = constAttrib.second.get<std::string>("");
            CConstantFormatPtr pConstFormat = make_shared<CConstantFormat>(bufferName, 0);

            // Populate the variables
            iptree &varLevel = constLevel.get_child("Constant.Variable");
            BOOST_FOREACH(iptree::value_type& variable, varLevel.get_child("") )
            {
                std::string attribute = variable.first;
                BOOST_FOREACH(iptree::value_type& variableAttrib, varLevel.get_child( attribute.c_str() ))
                {
                    //CConstantElementDesc desc = BuildConstantVariable(variableAttrib);
                    int pause = 1;
                }
            }

        }
     }

0 个答案:

没有答案