Iterating over variables in an XML file using the Boost property tree

Can someone help me with iterating over the variables in the XML file I have using the boost property tree?

<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> 

Here is my code so far [it will not go past the first variable in 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; } } } } 
+4
source share

All Articles