The following is a reduced sample of actual xml I would like to process with Boost.PropertyTree
library. Actually, there are a lot of other fields in an original xml-file
<?xml version="1.0" encoding="UTF-8"?>
<foo>
<bar>
<item>
<link>http://www.one.com</link>
</item>
<item>
<link>http://www.two.net</link>
</item>
<item>
<link>http://www.sex.gov</link>
</item>
...
</bar>
</foo>
I need to iterate through all link
tags. There is an example of the required code.
for (auto item: pt.get_child("foo.bar"))
if ("item" == item.first)
for (auto prop: item.second)
if ("link" == prop.first)
std::cout << prop.second.get_value<std::string>() << std::endl;
This is too ugly code for simple purpose. Is there a way to simplify it? For example, I could wait next code to be valid for the purpose:
for (auto item: pt.get_child("foo.bar.item.link"))
std::cout << item.second.get_value<std::string>() << std::endl;
This code does not work, but it illustrates, what I would like to get.
Such a function doesn't exist.
Frankly, if you want XPath, just use a library that supports it:
Otherwise, you can always make the effort yourself:
Now you can write it as e.g.:
Live On Coliru
Prints