C++ tinyxml2::IntAttribute()

C++ tinyxml2::IntAttribute()

Given an attribute name, IntAttribute() returns the value of the attribute interpreted as an integer. The default value will be returned if the attribute isn't present, or if there is an error.


int tinyxml2::XMLElement::IntAttribute(const char* name,int defaultValue=0)


IntAttribute.cpp (Filename):-

/*include necessary header files*/

#include <iostream>

#include "tinyxml2.h"

using namespace std;

using namespace tinyxml2;

int main()


static const char* xml =


"<entry name=\"Tinyxml2 xml file\" hidden=\"true\" int=\"20\">This is simple Example of IntAttribute() code. Here value of int is now </entry>"




cout << " Output : Using IntAttribute() function of tinyxml2. " << endl;


tinyxml2::XMLDocument doc;




tinyxml2::XMLHandle docHandle(&doc);


tinyxml2::XMLElement* entry = docHandle.FirstChildElement("entries").ToElement();

    for (tinyxml2::XMLNode* node = entry->FirstChildElement(); node; node = node->NextSibling())


tinyxml2::XMLElement* e = node->ToElement();


const char* name = e->Attribute("name");


if (name) cout << name << ": ";


cout << e->GetText();


int true_age = e->IntAttribute("int") + 20;


/*This will add IntAttribute value to "age" here.*/


cout << " " << true_age << endl;


return 0;