The World’s Largest Online Community for Developers

'; c++ - boost::property_tree XML issue - LavOzs.Com

I am fighting with getting values from the following XML structure:

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

The code I am using is

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

If I go for 'action' or 'label' the values are empty which seems to be normal. But how I can access name (@name) from action and input (@input) from rebind?

I expect to get e.g. the pair of values 'v_close_all_doors' and 'kb1_0'. Of course I need a second iteration for the second value but for the first I need to understand how to access these values.

I gave up with boost::property_tree as its seems to be designed to handle simple XML structures only. Made more progress using RapidXML

What characters do I need to escape in XML documents?
How do I parse XML in Python?
How to use Boost in Visual Studio 2010
How do I comment out a block of tags in XML?
What does <![CDATA[]]> in XML mean?
Updating XML file using Boost property_tree
How do you parse and process HTML/XML in PHP?
boost::property_tree XML pretty printing
How to install Boost on Ubuntu
iterate over boost::property_tree XML