boost-propertytree

Parsing XML File with Boost C++

橙三吉。 提交于 2019-12-08 08:21:25
问题 I have to parse one xml file using boost c++, I have written one test code which is working for this xml. a.xml <a> <modules> <module>abc</module> <module>def</module> <module>ghi</module> </modules> </a> Output is coming abc def ghi but for this a.xml file, my test code is not showing any output, 3 blank lines are coming as output. <a> <modules> <module value = "abc"/> <module value = "def"/> <module value = "abc"/> </modules> </a> here is the test code: #include <boost/property_tree/ptree

Does Boost Property Tree have methods for defining rules for the data to be parsed?

对着背影说爱祢 提交于 2019-12-08 07:29:11
问题 I have a project that will be using a single JSON file in order to describe the inner contents of the directory it is contained within. The Boost Property Tree library appears to be the best choice for a JSON parsing library. However, this JSON file (like many others) is expected to have a very particular layout, and so far I haven't found a good manner of expressing the rules in code. Does the Boost Property Tree library have any methods allowing the user to do any of the following?

c++ boost library - writing to ini file without overwriting?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-08 04:00:05
问题 im trying to write an ini file using boost library's ini parser and property tree. The file is written in stages - i mean every function writes a portion of it. At the end im left with only the last output instead of having everything written down. Sample code i use while writing: property_tree::ptree pt; string juncs=roadID; size_t pos = juncs.find_last_of("j"); string jstart = juncs.substr(0,pos); string jend = juncs.substr(pos,juncs.length()); pt.add(repID + ".startJunction", jstart); pt

Boost::property_tree: Using std::vector<> in XML parser to store multiple values in one key

一笑奈何 提交于 2019-12-08 03:31:02
问题 My question is related to this question: Boost property_tree: multiple values per key and to a question following that question: Boost property_tree: multiple values per key, on a template class. I am trying to parse an XML file in which multiple values are listed at a single key value using std::vector<> . The following code is what I have implemented so far: #include <boost/optional.hpp> #include <boost/property_tree/xml_parser.hpp> namespace boost { namespace property_tree { template

XML version and encoding from boost ptree

筅森魡賤 提交于 2019-12-07 23:34:27
I am using boost ptree to parse xml read_xml(stream, pt, trim_whitespace | no_comments); <?xml version="1.0" encoding="windows-1252"?> <rss> <channel>.....</channel> </rss> How to read the version and encoding of the xml : I tried the following std::string encoding = pt.get<std::string>("<xmlattr>.encoding", ""); which gives empty string. How to get the version and encoding of xml? sehe The processing instruction is not an XML element (in fact, it's... a processing instruction). Processing instructions do not have attributes in the <xmlattr> sense. You will note that there is no ptree node

where is boost property_tree::empty_ptree?

自古美人都是妖i 提交于 2019-12-07 06:05:47
问题 I'm using boots's property_tree library. I'm looking for a way to get a child node from a ptree object, but return an empty ptree if failed. I came across a nice example in property_tree/examples/empty_ptree_trick.cpp: void process_settings(const std::string &filename) { ptree pt; read_info(filename, pt); const ptree &settings = pt.get_child("settings", empty_ptree<ptree>()); std::cout << "\n Processing " << filename << std::endl; std::cout << " Setting 1 is " << settings.get("setting1", 0) <

c++ boost library - writing to ini file without overwriting?

假如想象 提交于 2019-12-07 03:11:27
im trying to write an ini file using boost library's ini parser and property tree. The file is written in stages - i mean every function writes a portion of it. At the end im left with only the last output instead of having everything written down. Sample code i use while writing: property_tree::ptree pt; string juncs=roadID; size_t pos = juncs.find_last_of("j"); string jstart = juncs.substr(0,pos); string jend = juncs.substr(pos,juncs.length()); pt.add(repID + ".startJunction", jstart); pt.add(repID + ".endJunction", jend); write_ini("Report.ini", pt); How can i use the write_ini function

Disable exception working for boost::smart_ptr but not for boost::property_tree

江枫思渺然 提交于 2019-12-06 13:50:16
问题 I'm using boost 1.57. I need to disable exception support in my not widely-used proprietary compiler. When I needed to use boost::smart_ptr , the following steps worked like a charm: Disabled C++11 support using the following user.hpp file (compiling with -DBOOST_USER_CONFIG="<user.hpp>" ): #define BOOST_HAS_NRVO #define BOOST_NO_COMPLETE_VALUE_INITIALIZATION #define BOOST_NO_CXX11_AUTO_DECLARATIONS #define BOOST_NO_CXX11_AUTO_MULTIDECLARATIONS #define BOOST_NO_CXX11_CHAR16_T #define BOOST_NO

Boost::property_tree: Using std::vector<> in XML parser to store multiple values in one key

狂风中的少年 提交于 2019-12-06 04:58:05
My question is related to this question: Boost property_tree: multiple values per key and to a question following that question: Boost property_tree: multiple values per key, on a template class . I am trying to parse an XML file in which multiple values are listed at a single key value using std::vector<> . The following code is what I have implemented so far: #include <boost/optional.hpp> #include <boost/property_tree/xml_parser.hpp> namespace boost { namespace property_tree { template<typename type> struct vector_xml_translator { boost::optional<std::vector<type> > get_value(const std:

Boost read_json and C++11

烂漫一生 提交于 2019-12-05 21:56:56
问题 I'm trying to parse JSON using Boost's property_tree parser and from C++11 code (my system is Debian Wheezy with gcc 4.7.2 and Boost 1.49). I tried the following code based on Serializing and deserializing json with boost: #include <map> #include <sstream> #include <boost/property_tree/ptree.hpp> #include <boost/property_tree/json_parser.hpp> using boost::property_tree::ptree; using boost::property_tree::read_json; using boost::property_tree::write_json; void example() { // Write json. ptree