C++ tinyxml2::Name()














































C++ tinyxml2::Name()




Name() gets the name of an element (which is the Value() of the node.) 



Syntax:-


const char* Name() const


Example:-


Name_demo_file.xml:-


<?xml version="1.0"?>

<catalog>

   

<book id="bk101" edition="6th edition">

       

<author fName="Gambardella"  mName="Vijay" lName= "Matthew" />

        <title>XML Developer's Guide</title>

       

<genre>Computer</genre>

       

<publish_date>2000-10-01</publish_date>

   

</book>

</catalog>


Name.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("Name_demo_file.xml");

  

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

  

XMLNode* book_info = xmlDocument.FirstChildElement();

  

XMLNode* book1 = book_info->FirstChildElement();

   

XMLElement* bk1 = book1->ToElement();


cout << "\n First attribute Value of Book 1 is : " << bk1->FirstAttribute()->Name() << endl;

/*This will print the first Attribute value using Name()*/


return 0;

}


Output:-




Comments