GetText() is limited compared to getting the XMLText child and accessing it directly.
If the first child of 'this' is a XMLText, the GetText() returns the character string of the Text node, else null is returned.
Syntax:-
const char* tinyxml2::XMLElement::GetText() const
Example:-
GetText.cpp (Filename)
#include "tinyxml2.h" #include <iostream> using namespace std; int main(){ static const char* xml = "<XML_FILE>" "<xml_data>Output : </xml_data>" "<xml_data>Simple Block of Code to demonstrate Working of GetText() func. of tinyxml2</xml_data>" "<xml_data>To Parse an XML and print using GetText().</xml_data>" "</XML_FILE>"; tinyxml2::XMLDocument doc; doc.Parse(xml); tinyxml2::XMLHandle docHandle(&doc); tinyxml2::XMLElement *xml_data = docHandle.FirstChildElement("XML_FILE").ToElement(); if(xml_data){ for(tinyxml2::XMLNode *node = xml_data->FirstChildElement(); node; node = node->NextSibling()){ tinyxml2::XMLElement *p = node->ToElement(); cout<<p->GetText()<<endl; } } return 0; }
Output:-
Comments