boost-propertytree

boost ptree access first element with no path name

一笑奈何 提交于 2019-12-24 10:07:15
问题 I am using boost library to manipulate a JSON string and I would like to access to a first element. I was wondering if there where some convenient way to access a first element of ptree with no path name. I do this, but I got no value : namespace pt = boost::property_tree; pt::ptree pt2; string json = "\"ok\""; istringstream is(json); try { pt::read_json(is, pt2); cout << pt2.get_child("").equal_range("").first->first.data() << endl; } catch (std::exception const& e) { cerr << e.what() <<

property tree put/erase with const iterator, or how to convert const_iterator to iterator

感情迁移 提交于 2019-12-24 03:55:14
问题 I am using boost 1.55.0 on ubuntu 12.04lts with clang 3.4. I have a boost::property_tree::ptree whose xml input looks like: <root> <persons> <person> <name>dad</name> <age>43</age> </person> <person> <name>me</name> <age>4</age> </person> </persons> </root> So I have a list of nodes with the same tag. To read them I iterate over the tree, and depending on a condition I want to erase a node. This looks like: boost::property_tree::ptree pt; boost::property_tree::read_xml(inputFileName, pt);

Boost Property Tree: Remove attribute from a node

让人想犯罪 __ 提交于 2019-12-23 03:16:16
问题 I have the following XML file: <?xml version="1.0" encoding="utf-8"?> <gexf> <graph> <nodes> <node id="0" label="0" start="0" end="25"/> <node id="1" label="1" start="1"/> <node id="2" label="2" start="2"/> ... </nodes> <edges> <edge id="0" source="0" target="1" start="7" end="19"/> <edge id="1" source="0" target="2" start="8" end="20"/> ... </edges> </graph> </gexf> I want to remove the start and end attributes from the edge with source="0" and target="1" . The way I've tried to do this is

no end of line in boost property tree xml writer output

不羁的心 提交于 2019-12-21 09:22:05
问题 Consider the following code using boost::property_tree: #include <boost/property_tree/ptree.hpp> #include <boost/property_tree/xml_parser.hpp> using namespace boost::property_tree; int main() { ptree model_tree; model_tree.add("calibrated", "true"); model_tree.add("model.<xmlattr>.label", "label"); model_tree.add("model.activity.<xmlattr>.type", "fixed"); write_xml("test.xml", model_tree); } By compiling and executing the program I get the following output: <?xml version="1.0" encoding="utf-8

How to iterate over XML structure in boost::property_tree

老子叫甜甜 提交于 2019-12-21 04:23:16
问题 I have an XML structure along the lines of: <root> <SomeElement> <AnotherElement> <ElementIWant x="1" y="1"/> </AnotherElement> </SomeElement> <SomeElement> <AnotherElement> <ElementIWant x="1" y="1"/> <ElementIWant x="2" y="1"/> <ElementIWant x="3" y="1"/> </AnotherElement> </SomeElement> </root> Which is being read into a boost::property_tree , There are 1..Many <SomeElement> s, and then at an arbitrary depth within that element there could be 1..Many <ElementIWant> s Is there a way to

How to copy subtree from Boost.PropertyTree

耗尽温柔 提交于 2019-12-20 07:17:45
问题 I have some boost::property_tree::ptree . I need tree with removing some elements with certain tag name. For example, xml for source ptree is the following: <?xml version="1.0" encoding="utf-8"?> <document> <B atr="one" atr1="something"> <to_remove attr="two">10</to_remove> </B> <to_remove> <C>value</C> <D>other value</D> </to_remove> <E>nothing</E> </document> And I'd like to get ptree with xml like the following: <?xml version="1.0" encoding="utf-8"?> <document> <B atr="one" atr1="something

how to get boost json to use the correct data types

大兔子大兔子 提交于 2019-12-20 02:06:06
问题 When I put_value using an int, it gets written as a string. Does anyone know how to get it to print as an int? #include <iostream> #include <boost/property_tree/ptree.hpp> #include <boost/property_tree/json_parser.hpp> using boost::property_tree::ptree; using namespace std; int main(int argc, char* argv[]) { ptree node; node.put("string", "text here"); node.put("int", 1);//outputs as "1" and should be 1 write_json(cout, node, false);//{"string":"text here","int":"1"} return 0; } 回答1: The

how to get boost json to use the correct data types

妖精的绣舞 提交于 2019-12-20 02:05:52
问题 When I put_value using an int, it gets written as a string. Does anyone know how to get it to print as an int? #include <iostream> #include <boost/property_tree/ptree.hpp> #include <boost/property_tree/json_parser.hpp> using boost::property_tree::ptree; using namespace std; int main(int argc, char* argv[]) { ptree node; node.put("string", "text here"); node.put("int", 1);//outputs as "1" and should be 1 write_json(cout, node, false);//{"string":"text here","int":"1"} return 0; } 回答1: The

How to get enum from boost::property_tree?

情到浓时终转凉″ 提交于 2019-12-19 09:06:40
问题 How do I get an enum from a boost::property_tree ? This is my "non-working" example. config.xml <root> <fooEnum>EMISSION::EMIT1</fooEnum> <fooDouble>42</fooDouble> </root> main.cpp #include <iostream> #include <boost/property_tree/ptree.hpp> #include <boost/property_tree/xml_parser.hpp> int main() { enum class EMISSION { EMIT1, EMIT2 } ; enum EMISSION myEmission; //Initialize the XML file into property_tree boost::property_tree::ptree pt; read_xml("config.xml", pt); //test enum (SUCCESS)

Boost property tree issue when converting to Unicode

社会主义新天地 提交于 2019-12-19 07:52:46
问题 Ok, first off I'm not a C++ developer by nature; I've managed to put some stuff together and it works fine, but I'm sure through the eyes of an expert it looks like garbage =) So I have a freeware app that I've made which uses Property Tree from the Boost libraries. I developed the entire app (in VS2010) with the Use Multi-Byte Character Set setting. I decided it was time to go through and update the app to support Unicode as there are some folks with complex character sets that I'd like to