boost-propertytree

Parsing XML Attributes with Boost

断了今生、忘了曾经 提交于 2019-11-27 01:36:58
问题 I would like to share with you an issue I'm having while trying to process some attributes from XML elements in C++ with Boost libraries (version 1.52.0). Given the following code: #define ATTR_SET ".<xmlattr>" #define XML_PATH1 "./pets.xml" #include <iostream> #include <string> #include <boost/foreach.hpp> #include <boost/property_tree/ptree.hpp> #include <boost/property_tree/xml_parser.hpp> using namespace std; using namespace boost; using namespace boost::property_tree; const ptree& empty

Add xml-stylesheet processing instructions to boost property_tree

左心房为你撑大大i 提交于 2019-11-26 22:10:46
问题 I am using boost/property_tree to create an XML file. Unfortunately I cannot figure out how to add xml-stylesheet processing instructions to the file. Desirable output: <?xml version="1.0" encoding="utf-8"?> <-- This is added automatically <?xml-stylesheet type="text/xsl" href="report.xsl"?> <-- How to add this line <report> ... </report> Is that possible with boost/property_tree/ptree? 回答1: It appears that boost/property_tree xml writer doesn't have a support for xml stylesheets processing

How to expand environment variables in .ini files using Boost

我的未来我决定 提交于 2019-11-26 18:35:24
问题 I have a INI file like [Section1] Value1 = /home/%USER%/Desktop Value2 = /home/%USER%/%SOME_ENV%/Test and want to parse it using Boost. I tried using Boost property_tree like boost::property_tree::ptree pt; boost::property_tree::ini_parser::read_ini("config.ini", pt); std::cout << pt.get<std::string>("Section1.Value1") << std::endl; std::cout << pt.get<std::string>("Section1.Value2") << std::endl; But it didn't expand the environment variable. Output looks like /home/%USER%/Desktop /home/

boost::property_tree XML pretty printing

不羁的心 提交于 2019-11-26 18:01:11
问题 I'm using boost::property_tree to read and write XML configuration files in my application. But when I write the file the output looks kind of ugly with lots of empty lines in the file. The problem is that it's supposed to be edited by humans too so I'd like to get a better output. As an example I wrote a small test program : #include <boost/property_tree/ptree.hpp> #include <boost/property_tree/xml_parser.hpp> int main( void ) { using boost::property_tree::ptree; ptree pt; // reading file

Why does Boost property tree write_json save everything as string? Is it possible to change that?

谁说我不能喝 提交于 2019-11-26 15:15:08
问题 I'm trying to serialize using boost property tree write_json, it saves everything as strings, it's not that data are wrong, but I need to cast them explicitly every time and I want to use them somewhere else. (like in python or other C++ json (non boost) library) here is some sample code and what I get depending on locale: boost::property_tree::ptree root, arr, elem1, elem2; elem1.put<int>("key0", 0); elem1.put<bool>("key1", true); elem2.put<float>("key2", 2.2f); elem2.put<double>("key3", 3.3