TiXmlElement* element = ...; // obtain pointer to element int value; if (element->QueryIntAttribute("value", &value) == TIXML_SUCCESS) { // attribute "value" was found and its value was stored in 'value' // do something with 'value' } else { // attribute "value" was not found or could not be converted to int }
TiXmlHandle docHandle(&doc); // obtain handle to XML document for (TiXmlElement* element = docHandle.FirstChildElement().Element(); element; element = element->NextSiblingElement()) { int id; if (element->QueryIntAttribute("id", &id) == TIXML_SUCCESS) { // process element with id = 'id' } }In this example, we use a TiXmlHandle to obtain a pointer to the root element of an XML document. Then we iterate over all child elements of the root and try to retrieve the integer attribute "id" of each element. If an element has an "id" attribute, we can process it in some way. The TinyXML-2 library provides a simple and lightweight way to work with XML data in C++, and TiXmlElement is a key class for accessing and manipulating XML elements.