TiXmlElement* element = rootElement->FirstChildElement("item"); double price; if (element->QueryDoubleAttribute("price", &price) == TIXML_SUCCESS) { // Use the price value... }
double x, y, z; if (element->QueryDoubleAttribute("x", &x) == TIXML_SUCCESS && element->QueryDoubleAttribute("y", &y) == TIXML_SUCCESS && element->QueryDoubleAttribute("z", &z) == TIXML_SUCCESS) { // Use the x, y, and z values... }In this example, we assume that the "element" variable is a pointer to a TiXmlElement that has three attributes named "x", "y", and "z", each containing a double-precision floating-point value. We use QueryDoubleAttribute three times, each time passing a different pointer variable to store the retrieved value. If all three calls return TIXML_SUCCESS, we can assume that all three attributes were present and correctly formatted, and we can use the values stored in "x", "y", and "z" in our code. Package/library: TinyXML.