C++ tinyxml2::XMLElement::FirstAttribute()














































C++ tinyxml2::XMLElement::FirstAttribute()




FirstAttribute()  is used to access the first attribute in tinyxml2::XMLElement.


Syntax:-
const XMLAttribute* FirstAttribute() const


Example:-


FirstAttribute_demo_file.xml:-


<book_info>


<book id="100" edition="2"publish_year="2020">


<title>Tinyxml2 Article</title>

   
</book>


</book_info>



FirstAttribute.cpp (Filename):-

/*include necessary header files*/

#include <iostream>


#include <cstdlib>


#include "tinyxml2.h"


using namespace std;


using namespace tinyxml2;


int main()


{

   

XMLDocument xmlDocument;


xmlDocument.LoadFile("FirstAttribute_demo_file.xml");

   

cout << "\n Output : Using FirstAttribute() function of tinyxml2 " << endl;

   

XMLNode* book_info = xmlDocument.FirstChildElement();

   

XMLNode* book1 = book_info->FirstChildElement();

   

XMLElement* bk1 = book1->ToElement();

   

cout << "\n Book Id is : " <<bk1->FirstAttribute()->Value() << endl;


/*This will Print First Attribute value of Book element*/


return 0;


}



Output:-




Comments