C++ tinyxml2::XMLDocument::RootElement()














































C++ tinyxml2::XMLDocument::RootElement()




RootElement() method of Tinyxml2 is used to get the root element of the xml
document.
Get the root element which is the only top level element of the document.

In well formed XML,there should only be one. TinyXml2 is tolerant of multiple elements at the

document level.


Syntax:-

XMLElement* tinyxml2::XMLDocument::RootElement()

Example:-

RootElement_demo_file.xml

<?xml version="1.0"?>


<Root_Element>

 
<Child_1>

   
<Child_2>

        <Child_3>This_is_Child_3_Content_Newly_Inserted.</Child_3>

</Child_2>


</Child_1>


</Root_Element>


RootElement.cpp (Filename)

#include <iostream>


#include <cstdlib>


#include "tinyxml2.h"


using namespace std;


using namespace tinyxml2;


int main()


{


XMLDocument doc;


doc.LoadFile("RootElement_demo_file.xml");


XMLElement* return_root = doc.RootElement();


/*This will return root element of your whole RootElement_demo_file.xml file*/

   
cout
<< " Output : Using RootElement()" << endl;


cout << " Root Element is : " <<return_root->Value();


return 0;


}



Output :-

 Output : Using RootElement()

 Root Element is : Root_Element 


                  



Comments