C++ tinyxml2::XMLElement::FindAttribute()














































C++ tinyxml2::XMLElement::FindAttribute()




FindAttribute()  is used to find specific attribute in the list.


Syntax:-

const XMLAttribute* FindAttribute(const char* name) const

Example:-


FindAttribute_demo_file.xml:-


<book_info>

   

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

       

<title>Article</title>

   

</book>

</book_info>


FindAttribute.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("FindAttribute_demo_file.xml");

   

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

  

XMLNode* book_info = xmlDocument.FirstChildElement();

   

XMLNode* book1 = book_info->FirstChildElement();

   

XMLElement* bk1 = book1->ToElement();


cout << "\n Book Name is :" << bk1->FindAttribute("name")->Value() << " ,and its Publish Year

is :" <<bk1->FindAttribute("publish_year")->Value() << endl << endl;


/*This will Print "name" and "publish_year" Attribute value of Book element using FindAttribute()*/


return 0;


}



Output:-




Comments