Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7004073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:09:08+00:00 2026-05-27T21:09:08+00:00

I have the following XML file and I want to store it using the

  • 0

I have the following XML file and I want to store it using the below structures.

the data structs:

    struct transitions
    {
     string oldstate;
     string event;
     string newstate;
    };

    struct XML_Diagram
    {
     string diag_name;
     string diag_defaultstate;
     list<string> diag_states;
     list<string> diag_events;
     list<transitions> diag_transitions;
    };

the xml file:

    <diagram>
      <diagname>DiagaX</diagname>
      <states>
         <state>A</state>
         .............       
      </states>
      <events>
          <event>ev1</event>
          .................
      </events>
      <defaultstate>A</defaultstate>
      <transitions>
          <transition>
              <oldstate>A</oldstate>
              <event>ev1</event>
              <newstate>B</newstate>
          </transition>
          <transition>
              <oldstate>B</oldstate>
              <event>ev2</event>
              <newstate>C</newstate>
          </transition>
          .........................
      </transitions>
    </diagram>

It is clear to me how can I to access diagram.states .
I can do it with the folowing code:

    using boost::property_tree::ptree;
    ptree pt;

    // Get diagram states
    BOOST_FOREACH(ptree::value_type &v, pt.get_child("diagram.states"))
    {
       diag_states.push_back(v.second.data());
    }

What is not clear to me is how can I access the data from at the level diagram.transitions.transition ?

My problem is that I could not find any examples in the documentation on how to parse more complex xml files with several levels.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T21:09:09+00:00Added an answer on May 27, 2026 at 9:09 pm

    This useful utility function traverses and pretty-prints an entire property tree:

    using boost::property_tree::ptree;
    
    std::string q(const std::string& s) { return "\"" + s + "\""; }
    
    void print_tree(const ptree& pt, int level)
    {
        const std::string sep(2 * level, ' ');
        BOOST_FOREACH(const ptree::value_type &v, pt) {
            std::cout
                << sep
                << q(v.first) << " : " << q(v.second.data()) << "\n";
            print_tree(v.second, level + 1);
        }
    }
    
    void print_tree(const ptree& pt) { print_tree(pt, 0); }
    

    The v.second values are trees themselves that can be accessed with the usual get methods. The transitions
    can for example be accessed and printed like this:

    using std::string;
    
    void print_transitions(const ptree& pt)
    {
        BOOST_FOREACH(
            const ptree::value_type &v,
            pt.get_child("diagram.transitions"))
        {
            const ptree& child = v.second;
            std::cout
                << "Event "
                << child.get<string>("event")
                << " in state "
                << child.get<string>("oldstate")
                << " leads to state "
                << child.get<string>("newstate")
                << "\n";
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following xml file: <xfa:data> <form1> <Page1> <Page2> <contractInfo> ... </contractInfo> <paymentInfo>
I have the following contents in my XML file: <items> <item id=1><content><![CDATA[<p>string</p>]]></content></item> </items> I
i have a XML File i want to insert data from that XML file
I want to read xml file which looks like the following ... I have
I have the following xml file and want to parse it into an .aspx
Suppose I have the following XML file, and I want to use PowerShell (version
I have the following XML file : <?xml version=1.0?> <Table69> </Table69> And want to
I have an XML file and I want to retrieve data from it so
I have the following XML file with page nodes which I want to read
I have the following XML file (below) and i'd like to get a hook

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.