Logo Search packages:      
Sourcecode: rarian version File versions

const char * TiXmlElement::GetText (  )  const

Convenience function for easy access to the text inside an element. Although easy and concise, GetText() is limited compared to getting the TiXmlText child and accessing it directly.

If the first child of 'this' is a TiXmlText, 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><b>This is text</b></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 <b>text</b></foo> 
GetText() will return "This is ".

WARNING: GetText() accesses a child node - don't become confused with the similarly named TiXmlHandle::Text() and TiXmlNode::ToText() which are safe type casts on the referenced node.

Definition at line 928 of file tinyxml.cpp.

References TiXmlNode::FirstChild(), TiXmlNode::ToText(), and TiXmlNode::Value().

      const TiXmlNode* child = this->FirstChild();
      if ( child ) {
            const TiXmlText* childText = child->ToText();
            if ( childText ) {
                  return childText->Value();
      return 0;

Generated by  Doxygen 1.6.0   Back to index