When we parse any xml file, we got a ptree, but how to know name of the root node? Or like when we pass a node as argument in a function, then how we can get the name of node in function.
Asked
Active
Viewed 1,876 times
1
-
1For parsing XML, I'd suggest using an XML library. Boost Property Tree is NOT an XML library. – sehe Jun 08 '18 at 09:05
2 Answers
0
There's no such way. If you have access to an ancestor (like, e.g. the tree root) you can use iteration to find it though.
See this answer for sample code:

sehe
- 374,641
- 47
- 450
- 633
-1
You should know name of the node in advance or you can find it out using loop
for (auto it : ptree)
{
std::string name = it.first;
}

Serj
- 1
- 1
-
This will give the name of child of ptree (starting from attributes if present), I want to know the name of ptree. like in libxml we can get the name by node->get_name(), it simply gives the name of the node – Ankit Jun 08 '18 at 08:08