C++ tinyxml2::NewComment()














































C++ tinyxml2::NewComment()




NewComment() Creates a new Comment associated with the Document. The memory for the Comment is managed by the Document.


Syntax:-


XMLComment* tinyxml2::XMLDocument::NewComment(const char * comment)


Example:-


NewComment_demo_file.xml:-


<book_info>


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


<title>Article</title>


</book>


</book_info>


NewComment.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("NewComment_demo_file.xml");

   
cout
<< " Output : Using NewComment() function of tinyxml2 " << endl;

   

tinyxml2::XMLElement* rootNode = doc.FirstChildElement();

   
tinyxml2::XMLElement* childNode = rootNode->FirstChildElement();

   
tinyxml2::XMLComment* newComment = doc.NewComment(
"This is New Comment Inserted");


/*This will add New comment in Your XML file.*/

   

childNode->InsertFirstChild(newComment);

 
cout
<< "\n New Comment is Inserted Successfully in your XML File." << endl;

   

doc.SaveFile("NewComment_demo_file.xml");


return 0;



}


Output :-

      


After this Tinyxml2 NewComment.exe program runs successfully. 

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


NewComment_demo_file.xml  (After execution of NewComment.exe file):-


<book_info>

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

       

<!--This is New Comment Inserted-->

       

<title>Article</title>

   
</book>


</book_info>


Comments