I am using rapidXML and C++ in VS2012 on PC. I have already parsed the XML file, but now I want to print out attribute values individually. I am usually able to do this using the code below. This method, however, needs to know the node name and attribute name. This is a problem because I have multiple nodes with the same name and multiple attributes with the same name. My question is this, how do I get a single attribute value when neither the node name, nor the attribute name, is unique?
The code I use when I have a unique node name and attribute name:
xml_node<> *node0 = doc.first_node("NodeName"); //define the individual node you want to access
xml_attribute<> *attr = node0->first_attribute("price"); //define the individual attribute that you want to access
cout << "Node NodeName has attribute " << attr->name() << " ";
cout << "with value " << attr->value() << "\n";
My XML test file:
<catalog>
<book>
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<price>44.95</price>
</book>
<book>
<author>Ralls, Kim</author>
<title>Midnight Rain</title>
<price>5.95</price>
</book>
</catalog>
For this specific example, how can I get the value of the price attribute on the second book? Can I enter the title attribute value "Midnight Rain" and somehow use that to get the next value?