Boost logo

Boost Users :

From: Johan Nilsson (r.johan.nilsson_at_[hidden])
Date: 2006-06-15 06:45:48


Demetrius Cassidy wrote:
> Reading the tutorial for property_tree, using the functions
> ptree.find, ptree.get and ptree.get_child, they will
> only return the topmost node, so if I had two different children
> nodes under my root named '<Logistics>'
> with different data within the children, I would only be able to
> access the first one.
>
> So my question is that how would I go about navigating to each top
> node under my root when they are all
> named the same?
>

[snip]

> I basicly will have a file that looks something like this:
>
> XML file contents:
> <Technologies>
> <Logistics ID="Damage Diagnostics">

   [snip]

> </Logistics>
> <Logistics ID="Basic Self-Repair"> /* I need to access this node */

   [snip]

> </Logistics>
> </Technologies>

Well, something along the lines of this should work (caution: not tested):

ptree technologies;
/* load xml */
for (ptree::const_iterator iter = technologies.begin(); iter !=
technologies.end(); ++iter)
{
    std::cout << "ID: " << (*iter).get<std::string>("<xmlattr>.ID") << '\n';
}

HTH // Johan


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net