Function GetText


#include <tinyxml2/tinyxml2.h>

const char * tinyxml2::XMLElement::GetText() const


Convenience function for easy access to the text inside an element. Although easy and concise, 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.

This is a convenient method for getting the text of simple contained text: <foo>This is text</foo> const char* str = fooElement->GetText();

'str' will be a pointer to "This is text".

Note that this function can be misleading. If the element foo was created from this XML: <foo>This is text</foo>

then the value of str would be null. The first child node isn't a text node, it is another element. From this XML: <foo>This is text</foo> GetText() will return "This is ".




From lines 1326-1332 in tinyxml2.cpp

const char* XMLElement::GetText() const
    if ( FirstChild() && FirstChild()->ToText() ) {
        return FirstChild()->Value();
    return 0;


There are 0 discussions relevant for this page, and 1 discussions in the whole project.

Add Discussion

Log in to comment