【问题标题】:boost::property_tree XML issueboost::property_tree XML 问题
【发布时间】:2020-01-15 00:23:22
【问题描述】:

我正在努力从以下 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'。当然,我需要对第二个值进行第二次迭代,但对于第一次,我需要了解如何访问这些值。

【问题讨论】:

    标签: c++ xml boost


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-07
      • 2013-03-03
      • 1970-01-01
      • 2018-04-11
      • 2023-03-21
      • 2013-09-24
      • 2012-12-13
      相关资源
      最近更新 更多