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

  • Home
  • SEARCH
  • 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 6128559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:38:26+00:00 2026-05-23T16:38:26+00:00

So lets take a look onto a littel bit modified example code: #include <stdio.h>

  • 0

So lets take a look onto a littel bit modified example code:

#include <stdio.h>
#include <iostream>
#include <fstream>
#include <boost/foreach.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>

void load(const std::string &file_path)
{
    using boost::property_tree::ptree;
    ptree pt;
    std::ifstream script;
    script.open(file_path.c_str());
    read_xml(script, pt);
    BOOST_FOREACH(boost::property_tree::ptree::value_type &v,
                  config.get_child("config.servecies"))
    {
        std::cout
            << "First data: " << v.first.data() << std::endl
            << "Second data: " << v.second.data() << std::endl;
    }

}

I try it on with such xml:

<config>
    <servecies>
        <module>file</module>
        <module>Admin</module>
        <module>HR</module>
        <notModule>MyNotModule</notModule>
    </servecies>
</config>

it prints:

First data: module
Second data: file
First data: module
Second data: Admin
First data: module
Second data: HR
First data: notModule
Second data: MyNotModule

But when I try such json file (created from this xml via this web tool):

{
  "config": {
    "name": "myconfig",
    "servecies": {
      "module": [
        "file",
        "Admin",
        "HR"
      ],
      "notModule": "MyNotModule"
    }
  }
}

it prints:

First data: module
Second data:
First data: notModule
Second data: MyNotModule

How to make boost property_tree produce same results on JSON as it parses XML? How to find out if value_type is some sort of one dimentional array and iterate thru it?

  • 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-23T16:38:27+00:00Added an answer on May 23, 2026 at 4:38 pm

    How to make boost property_tree produce same results on JSON as it parses XML?

    Have Boost.PropertyTree output JSON. Then it will be able to input that JSON file.

    Boost.PropertyTree is used for storing properties. It is a way to save properties in human-readable formats, and restore those properties later.

    It is not a way to make a fast-and-dirty JSON/XML reader. It writes data in a specific format, and when it is given data to read, it expects that the data it is given is what it wrote. If you try to shove any old JSON down it, it will not necessarily return reasonable information. It writes valid JSON, but the structure of that JSON is specific to PropertyTree, and the reading code will expect that structure to exist.

    Side note: I don’t think that web tool is very good, since it added information to the JSON file that wasn’t present in the original XML.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Take a look at the first example of http://code.google.com/intl/sv-SE/appengine/docs/java/datastore/jdo/relationships.html (Owned One-to-One Relationships). I dont
I see this quite a bit with online apps. Lets take, for example, the
Hey guys, take a look at this, maybe you can help me. This code
Take a look at this awesome code from John P Bloch. What this code
This would be useful for consistently naming methods, for example let's take a look
Is it possible to generate comments for closing div tags, lets take this ex.
Let's take a web development environment, where developers checkout a project onto their local
Let's take the code int a, b, c; ... if ((a + b) >
Let's take example of a command example-command. I open terminal I write example-command in
Let's take an example. A file1 -file has a content file1, its own name.

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.