Subject: [Property Tree] Insert child node at the top of ptree
Hello all, I'm trying to find a way to write a child node to the top of a ptree, instead of the bottom as default. I've tried a number of things but for something that should be so simple I've had no luck. The reason I want to write a node to the top of the structure is because when I use ptree::get_child(), it fetches the first node match in the tree i.e. the oldest node written, not the latest written. I've posted the question on stackoverflow.com, it may explain some more detail: http://stackoverflow.com/questions/10272371/add-child-node-to-top-of-xml-str... I hope I've explained my problem clearly. Thanks in advance! Nathan
I think you are misunderstanding the whole thing here.
You have a lot of nodes whose xpath is root/result_set, but all of
them has an attribute that identifies them: result_number
When you call get_child you are getting an arbitrary node (from boost
documentation):
self_type & get_child(const path_type & path) ;
Get the child at the given path, or throw ptree_bad_path.
Notes:
Depending on the path, the result at each level may not be
completely determinate, i.e. if the same key appears
multiple times, which child is chosen is not specified.
This can lead to the path not being resolved even though
there is a descendant with this path. Example:
a -> b -> c
-> b
The path "a.b.c" will succeed if the resolution of "b" chooses the
first such node, but fail if it chooses the second.
I guess you should use iterators on root to find the last executed set
and then get a reference to that node and then add the results to it.
Hope it helps :)
Saludos!
Juan
On Sun, Apr 22, 2012 at 7:47 PM, johnnyturbo3
Hello all,
I'm trying to find a way to write a child node to the top of a ptree, instead of the bottom as default. I've tried a number of things but for something that should be so simple I've had no luck. The reason I want to write a node to the top of the structure is because when I use ptree::get_child(), it fetches the first node match in the tree i.e. the oldest node written, not the latest written. I've posted the question on stackoverflow.com, it may explain some more detail: http://stackoverflow.com/questions/10272371/add-child-node-to-top-of-xml-str...
I hope I've explained my problem clearly. Thanks in advance!
Nathan
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (2)
-
johnnyturbo3
-
Juan Ramírez