boost::property_tree XML issue
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 取得更多进展
相关文章:
- Seg Fault Issue C++ (file IO / getline)
- Cppcheck生成xml转储文件
- 如何在pugixml中获取节点的内部XML
- 如何使用tinyxml2从XML加载父实体和子实体
- boost xml parsingl将xml的路径作为变量发送
- C++RapidXml-使用first_node()遍历以修改XML文件中节点的值
- 使用 Tinyxml 在 xml 中添加一个子子项
- 增强基于 XML class_id的反序列化
- 在 c++ 中使用 vtd-xml 时,如何摆脱 EOFException?
- Issue with WriteProcessMemory
- 防止在C++中选择错误文件时提升 xml 解析器崩溃
- c++ 读取 xml 文件的内容
- std::partition segfault issue
- 删除 XML 文件中的子节点C++
- 使用 RapidXML 更新C++中的 XML 节点和属性值
- 在Cmake构建CmakeList.txt中读取/解析XML文件
- 从 XML 中读取未指定结构的每个数据成员
- VSCode C/C++ Intellisense issue: Undefined identifiers (Linu
- XML to XML XSLT transformation. MSXML in VBScript
- boost::property_tree XML issue