C++ tinyxml2::SetName()














































C++ tinyxml2::SetName()




SetName() sets the name of the element.



Syntax:-


void SetName(const char*str , bool staticMem=false)


Example:-


SetName_demo_file.xml:-


<Book_Info>

   

<name>Tinyxml2 Developers Guide</name>


<genre>Computer</genre>

  

<publish_date>1999-01-26</publish_date>


</Book_Info>


SetName.cpp (Filename):-

/*include necessary header files*/


#include <iostream>


#include <cstdlib>


#include "tinyxml2.h"


using namespace std;


using namespace tinyxml2;


int main()


{

   

tinyxml2::XMLDocument doc;


doc.LoadFile("SetName_demo_file.xml");

   

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

   

XMLNode* book_info = doc.FirstChildElement();

   

XMLNode* book1 = book_info->FirstChildElement();

   

XMLElement* bk1 = book1->ToElement();

   

cout << " Name of tag before SetName() function is : " << bk1->Value() << endl;

   

bk1->SetName("title");

  

/*This will set name of "name" child as "title".*/

   

cout << " New Name of tag after SetName() function is applied is : " << bk1->Value() << endl << endl;

   

doc.SaveFile("SetName_demo_file.xml");


return 0;


}


Output:-


After this Tinyxml2  SetName.cpp  program runs successfully. SetName_demo_file.xml

file contents are as follows:


SetName_demo_file.xml :-

</Book_Info>

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

   

<genre>Computer</genre>

   
<publish_date>1999-01-26</publish_date>


</Book_Info>



Comments