C++ tinyxml2::XMLElement::DeleteAttribute()














































C++ tinyxml2::XMLElement::DeleteAttribute()




DeleteAttribute() of Tinyxml2 is used to delete an attribute with the given name.

Syntax:-

 void tinyxml2::XMLElement::DeleteAttribute(const char *name)


Example:-


DeleteAttribute_demo_file.xml:-


<book_info>

  

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

        <title>Article</title>

</book>


</book_info>



DeleteAttribute.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("DeleteAttribute_demo_file.xml");

   

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

   

XMLNode* book_info = xmlDocument.FirstChildElement();

   

XMLNode* book1 = book_info->FirstChildElement();

   

XMLElement* bk1 = book1->ToElement();

   

bk1->ToElement()->DeleteAttribute("name");


/*This will delete "name" Attribute of Book element*/


cout << "\n Name Attribute of Book Element is Successfully Deleted." << endl;


xmlDocument.SaveFile("DeleteAttribute_demo_file.xml");


return 0;


}



Output:- 

           

After this Tinyxml2 DeleteAttribute.exe program runs successfully. 

A file  "DeleteAttribute_demo_file.xml" is updated as follows using savefile()


DeleteAttribute_demo_file.xml  (After execution of DeleteAttribute.exe file)


<book_info>

  

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

        <title>Article</title>

</book>


</book_info>


Comments