boost::property_tree XML issue



我正在努力从以下XML结构中获取值:

<ActionMaps version="1" optionsVersion="2" rebindVersion="2" profileName="full_export">
<CustomisationUIHeader label="full_export" description="" image="">
<devices>
<keyboard instance="1"/>
<mouse instance="1"/>
</devices>
<categories>
<category label="@ui_CCSpaceFlight"/>
<category label="@ui_CGLightControllerDesc"/>
<category label="@ui_CCFPS"/>
<category label="@ui_CCEVA"/>
<category label="@ui_CGOpticalTracking"/>
<category label="@ui_CGInteraction"/>
</categories>
</CustomisationUIHeader>
<options type="keyboard" instance="1" Product="Tastatur {6F1D2B61-D5A0-11CF-BFC7-444553540000}">
<flight_move_yaw exponent="1.5"/>
</options>
<modifiers />
<actionmap name="spaceship_general">
<action name="v_close_all_doors">
<rebind input="kb1_0"/>
</action>
<action name="v_cooler_throttle_down">
<rebind input="kb1_6"/>
</action>
<action name="v_cooler_throttle_up">
<rebind input="kb1_5"/>
</action>
<action name="v_eject">
<rebind input="kb1_1"/>
</action> 
...

我使用的代码是

const std::string XML_PATH = std::string(fqn_file.mb_str());
boost::property_tree::ptree pt1;
boost::property_tree::read_xml( XML_PATH, pt1  );
// Traverse property tree example
BOOST_FOREACH(boost::property_tree::ptree::value_type const& node,
pt1.get_child( "ActionMaps.actionmap" ) ) {
boost::property_tree::ptree subtree = node.second;
if ( node.first == "actionmap" ) {
BOOST_FOREACH(boost::property_tree::ptree::value_type const& v,
subtree.get_child( "" ) ) {
std::string label = v.first;
if ( label != "<xmlattr>" ) {
std::string value = subtree.get<std::string>( label );
wxString m_value(value);
std::cout << label << ":  " << value << std::endl;
wxString m_label(label);
wxLogMessage("DEBUG -> Label = " + m_label + " Value = " + value);
}
}
}
}

如果我选择'action''label'值为空,这似乎是正常的。但是我如何从操作中访问名称(@name(并从重新绑定访问输入(@input(?

我希望得到例如'v_close_all_doors''kb1_0'值对。当然,我需要对第二个值进行第二次迭代,但对于第一次,我需要了解如何访问这些值。

我放弃了boost::p roperty_tree,因为它似乎只设计用于处理简单的XML结构。使用 RapidXML 取得更多进展

最新更新