I have some XML that looks like this:
<animal>
<name>shark</name>
<color>blue</color>
</animal>
<animal>
<name>dog</name>
<color>black</color>
</animal>
I'm trying to print only the animal names (shark and dog). I am using boost so I tried the following code:
ptree pt;
boost::property_tree::read_xml("animals.xml", pt);
BOOST_FOREACH(boost::property_tree::ptree::value_type &v, pt.get_child("animal"))
{
std::cout << v.second.data() << std::endl;
}
But it only prints shark and blue. I'm not sure what the problem is, and I can't find good examples. Can someone offer some advice?