boost-propertytree

Boost Property_Tree iterators, how to handle them?

久未见 提交于 2019-12-03 16:14:25
问题 I am sorry, I asked a question about the same topic before, but my problem concerns another aspect of the one described there (How to iterate a boost...). Take a look at the following code: #include <iostream> #include <string> #include <boost/property_tree/ptree.hpp> #include <boost/property_tree/xml_parser.hpp> #include <boost/algorithm/string/trim.hpp> int main(int argc, char** argv) { using boost::property_tree::ptree; ptree pt; read_xml("try.xml", pt); ptree::const_iterator end = pt.end(

How are attributes parsed in Boost.PropertyTree?

痴心易碎 提交于 2019-12-03 15:08:22
问题 Say I have this XML format: <Widget type="SomeWidget" name="foo"> <Event name="onmouseover"> dostuff(); </Event> </Widget> How do I read the attributes using Boost.PropertyTree? 回答1: If your problem is to get attributes: The attributes of an XML element are stored in the subkey . There is one child node per attribute in the attribute node. Existence of the node is not guaranteed or necessary when there are no attributes. From the doc http://www.boost.org/doc/libs/1_44_0/doc/html/boost

iterate through boost property tree

瘦欲@ 提交于 2019-12-03 13:49:11
问题 I'm iterating over an XML document using boost property tree and storing the results in a struct. The issue I have is that I can only get to the first "item" nodes and can't access the second "item" nodes. I was hoping someone would point out where I've made a mistake. My program output looks like this (you can see items are missing.. there is no cookie2, candy2 or chocolate2 items shown): jar : snAcks snack : coOkie item : cooKie1 snack : canDy item : caNdy1 snack : cHocolate item :

How to iterate over XML structure in boost::property_tree

你说的曾经没有我的故事 提交于 2019-12-03 12:43:58
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 iterate over the <ElementIWant> directly (in a single loop) in the order that they appear in the doc? I

boost::property_tree::json_parser and two-byte wide characters

不羁的心 提交于 2019-12-03 06:52:53
Introduction std::string text = "á"; "á" is two-byte character (assuming a UTF-8 encoding). So following line prints 2. std::cout << text.size() << "\n"; But std::cout still prints text correctly. std::cout << text << "\n"; My problem I pass text to boost::property_tree::ptree and then to write_json boost::property_tree::ptree root; root.put<std::string>("text", text); std::stringstream ss; boost::property_tree::json_parser::write_json(ss, root); std::cout << ss.str() << "\n"; The result is { "text": "\u00C3\u00A1" } text is equal to "á" which is different than "á". Is is possible to fix this

Getting boost property_tree parent node

人盡茶涼 提交于 2019-12-02 04:06:57
问题 I am using boost property_tree in my program. I've set up the tree for using custom path type. What I'm looking for is getting a specific node's parent node id. Here is an example: MetaStorageTree tree; typedef boost::property_tree::basic_ptree<Framework::CommonClientServer::InterfacePathChain_t, MetaStorageTreeNode*> MetaStorageTreeNode_t; class MetaStorageTree : public MetaStorageTreeNode_t; MetaStorageTreeNode* node = new MetaStorageTreeNode(1); MetaStorageTreeNode* node1 = new

Getting boost property_tree parent node

杀马特。学长 韩版系。学妹 提交于 2019-12-02 00:32:41
I am using boost property_tree in my program. I've set up the tree for using custom path type. What I'm looking for is getting a specific node's parent node id. Here is an example: MetaStorageTree tree; typedef boost::property_tree::basic_ptree<Framework::CommonClientServer::InterfacePathChain_t, MetaStorageTreeNode*> MetaStorageTreeNode_t; class MetaStorageTree : public MetaStorageTreeNode_t; MetaStorageTreeNode* node = new MetaStorageTreeNode(1); MetaStorageTreeNode* node1 = new MetaStorageTreeNode(2); tree.put(InterfacePathChain_t{0}, node); tree.put(InterfacePathChain_t{0, 0}, node1); tree

how to get boost json to use the correct data types

不羁岁月 提交于 2019-12-01 21:28:02
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; } The library expressly doesn't support it. Boost Property Library has not been named "Boost Json Library" because it

boost property tree, iterators to an element for inserting?

喜欢而已 提交于 2019-12-01 13:06:59
I've searched a lot through the boost manual, and the internet, as I believe it is quite a standard feature? Well I'm looking into "merging" property trees. - I noticed the function insert , and I hope I can merge trees with this? Below is the line which I am trying to get working: base.insert(base.get_child("BRANCH"), t); base and t are "property trees", base has as (one of many) branch "BRANCH". Now I wish to insert t into this branch? More specifically: how can I get an iterator to "element" if I know that element by name? You can get an iterator to an element using the begin() method: base

boost property tree, iterators to an element for inserting?

戏子无情 提交于 2019-12-01 11:27:37
问题 I've searched a lot through the boost manual, and the internet, as I believe it is quite a standard feature? Well I'm looking into "merging" property trees. - I noticed the function insert , and I hope I can merge trees with this? Below is the line which I am trying to get working: base.insert(base.get_child("BRANCH"), t); base and t are "property trees", base has as (one of many) branch "BRANCH". Now I wish to insert t into this branch? More specifically: how can I get an iterator to