Wim van der Vegt / TINYXML

Dependents:   tinyxml_test

Embed: (wiki syntax)

« Back to documentation index

TiXmlText Class Reference

XML text. More...

#include <tinyxml.h>

Inherits TiXmlNode.

Public Types

enum  NodeType
 

The types of XML nodes supported by TinyXml.

More...

Public Member Functions

 TiXmlText (const char *initValue)
 Constructor for text element.
 TiXmlText (const std::string &initValue)
 Constructor.
virtual void Print (FILE *cfile, int depth) const
 All TinyXml classes can print themselves to a filestream or the string class (TiXmlString in non-STL mode, std::string in STL mode.) Either or both cfile and str can be null.
bool CDATA () const
 Queries whether this represents text using a CDATA section.
void SetCDATA (bool _cdata)
 Turns on or off a CDATA representation of text.
virtual const TiXmlTextToText () const
 Cast to a more defined type. Will return null not of the requested type.
virtual TiXmlTextToText ()
 Cast to a more defined type. Will return null not of the requested type.
virtual bool Accept (TiXmlVisitor *content) const
 Walk the XML tree visiting this node and all of its children.
const char * Value () const
 The meaning of 'value' changes for the specific type of TiXmlNode.
const std::string & ValueStr () const
 Return Value() as a std::string.
void SetValue (const char *_value)
 Changes the value of the node.
void SetValue (const std::string &_value)
 STL std::string form.
void Clear ()
 Delete all the children of this node. Does not affect 'this'.
TiXmlNodeParent ()
 One step up the DOM.
const TiXmlNodeFirstChild () const
 The first child of this node. Will be null if there are no children.
const TiXmlNodeFirstChild (const char *value) const
 The first child of this node with the matching 'value'.
TiXmlNodeFirstChild (const char *_value)
 The first child of this node with the matching 'value'. Will be null if none found.
const TiXmlNodeFirstChild (const std::string &_value) const
 STL std::string form.
TiXmlNodeFirstChild (const std::string &_value)
 STL std::string form.
TiXmlNodeLastChild ()
 The last child of this node. Will be null if there are no children.
TiXmlNodeLastChild (const char *_value)
 The last child of this node matching 'value'. Will be null if there are no children.
const TiXmlNodeLastChild (const std::string &_value) const
 STL std::string form.
TiXmlNodeLastChild (const std::string &_value)
 STL std::string form.
const TiXmlNodeIterateChildren (const TiXmlNode *previous) const
 An alternate way to walk the children of a node.
const TiXmlNodeIterateChildren (const char *value, const TiXmlNode *previous) const
 This flavor of IterateChildren searches for children with a particular 'value'.
const TiXmlNodeIterateChildren (const std::string &_value, const TiXmlNode *previous) const
 STL std::string form.
TiXmlNodeIterateChildren (const std::string &_value, const TiXmlNode *previous)
 STL std::string form.
TiXmlNodeInsertEndChild (const TiXmlNode &addThis)
 Add a new node related to this.
TiXmlNodeLinkEndChild (TiXmlNode *addThis)
 Add a new node related to this.
TiXmlNodeInsertBeforeChild (TiXmlNode *beforeThis, const TiXmlNode &addThis)
 Add a new node related to this.
TiXmlNodeInsertAfterChild (TiXmlNode *afterThis, const TiXmlNode &addThis)
 Add a new node related to this.
TiXmlNodeReplaceChild (TiXmlNode *replaceThis, const TiXmlNode &withThis)
 Replace a child of this node.
bool RemoveChild (TiXmlNode *removeThis)
 Delete a child of this node.
const TiXmlNodePreviousSibling () const
 Navigate to a sibling node.
const TiXmlNodePreviousSibling (const char *) const
 Navigate to a sibling node.
const TiXmlNodePreviousSibling (const std::string &_value) const
 STL std::string form.
TiXmlNodePreviousSibling (const std::string &_value)
 STL std::string form.
const TiXmlNodeNextSibling (const std::string &_value) const
 STL std::string form.
TiXmlNodeNextSibling (const std::string &_value)
 STL std::string form.
const TiXmlNodeNextSibling () const
 Navigate to a sibling node.
const TiXmlNodeNextSibling (const char *) const
 Navigate to a sibling node with the given 'value'.
const TiXmlElementNextSiblingElement () const
 Convenience function to get through elements.
const TiXmlElementNextSiblingElement (const char *) const
 Convenience function to get through elements.
const TiXmlElementNextSiblingElement (const std::string &_value) const
 STL std::string form.
TiXmlElementNextSiblingElement (const std::string &_value)
 STL std::string form.
const TiXmlElementFirstChildElement () const
 Convenience function to get through elements.
const TiXmlElementFirstChildElement (const char *_value) const
 Convenience function to get through elements.
const TiXmlElementFirstChildElement (const std::string &_value) const
 STL std::string form.
TiXmlElementFirstChildElement (const std::string &_value)
 STL std::string form.
int Type () const
 Query the type (as an enumerated value, above) of this node.
const TiXmlDocumentGetDocument () const
 Return a pointer to the Document this node lives in.
bool NoChildren () const
 Returns true if this node has no children.
virtual const TiXmlDocumentToDocument () const
 Cast to a more defined type. Will return null if not of the requested type.
virtual TiXmlDocumentToDocument ()
 Cast to a more defined type. Will return null if not of the requested type.
virtual const TiXmlElementToElement () const
 Cast to a more defined type. Will return null if not of the requested type.
virtual TiXmlElementToElement ()
 Cast to a more defined type. Will return null if not of the requested type.
virtual const TiXmlCommentToComment () const
 Cast to a more defined type. Will return null if not of the requested type.
virtual TiXmlCommentToComment ()
 Cast to a more defined type. Will return null if not of the requested type.
virtual const TiXmlUnknownToUnknown () const
 Cast to a more defined type. Will return null if not of the requested type.
virtual TiXmlUnknownToUnknown ()
 Cast to a more defined type. Will return null if not of the requested type.
virtual const TiXmlDeclarationToDeclaration () const
 Cast to a more defined type. Will return null if not of the requested type.
virtual TiXmlDeclarationToDeclaration ()
 Cast to a more defined type. Will return null if not of the requested type.
int Row () const
 Return the position, in the original source file, of this node or attribute.
int Column () const
 See Row()
void SetUserData (void *user)
 Set a pointer to arbitrary user data.
void * GetUserData ()
 Get a pointer to arbitrary user data.
const void * GetUserData () const
 Get a pointer to arbitrary user data.

Static Public Member Functions

static void SetCondenseWhiteSpace (bool condense)
 The world does not agree on whether white space should be kept or not.
static bool IsWhiteSpaceCondensed ()
 Return the current white space setting.
static void EncodeString (const TIXML_STRING &str, TIXML_STRING *out)
 Expands entities in a string.

Protected Member Functions

virtual TiXmlNodeClone () const
 [internal use] Creates a new Element and returns it.

Protected Attributes

void * userData
 Field containing a generic user pointer.

Friends

class TiXmlElement
std::istream & operator>> (std::istream &in, TiXmlNode &base)
 An input stream operator, for every class.
std::ostream & operator<< (std::ostream &out, const TiXmlNode &base)
 An output stream operator, for every class.
std::string & operator<< (std::string &out, const TiXmlNode &base)
 Appends the XML node or attribute to a std::string.

Detailed Description

XML text.

A text node can have 2 ways to output the next. "normal" output and CDATA. It will default to the mode it was parsed from the XML file and you generally want to leave it alone, but you can change the output mode with SetCDATA() and query it with CDATA().

Definition at line 1207 of file tinyxml.h.


Member Enumeration Documentation

enum NodeType [inherited]

The types of XML nodes supported by TinyXml.

(All the unsupported types are picked up by UNKNOWN.)

Definition at line 464 of file tinyxml.h.


Constructor & Destructor Documentation

TiXmlText ( const char *  initValue )

Constructor for text element.

By default, it is treated as normal, encoded text. If you want it be output as a CDATA text element, set the parameter _cdata to 'true'

Definition at line 1215 of file tinyxml.h.

TiXmlText ( const std::string &  initValue )

Constructor.

Definition at line 1224 of file tinyxml.h.


Member Function Documentation

bool Accept ( TiXmlVisitor content ) const [virtual]

Walk the XML tree visiting this node and all of its children.

Implements TiXmlNode.

Definition at line 1313 of file tinyxml.cpp.

bool CDATA (  ) const

Queries whether this represents text using a CDATA section.

Definition at line 1238 of file tinyxml.h.

void Clear (  ) [inherited]

Delete all the children of this node. Does not affect 'this'.

Definition at line 168 of file tinyxml.cpp.

TiXmlNode * Clone (  ) const [protected, virtual]

[internal use] Creates a new Element and returns it.

Implements TiXmlNode.

Definition at line 1319 of file tinyxml.cpp.

int Column (  ) const [inherited]

See Row()

Definition at line 247 of file tinyxml.h.

void EncodeString ( const TIXML_STRING &  str,
TIXML_STRING *  out 
) [static, inherited]

Expands entities in a string.

Note this should not contian the tag's '<', '>', etc, or they will be transformed into entities!

Definition at line 51 of file tinyxml.cpp.

const TiXmlNode* FirstChild (  ) const [inherited]

The first child of this node. Will be null if there are no children.

Definition at line 524 of file tinyxml.h.

const TiXmlNode * FirstChild ( const char *  value ) const [inherited]

The first child of this node with the matching 'value'.

Will be null if none found.

Definition at line 356 of file tinyxml.cpp.

TiXmlNode* FirstChild ( const char *  _value ) [inherited]

The first child of this node with the matching 'value'. Will be null if none found.

Definition at line 528 of file tinyxml.h.

const TiXmlNode* FirstChild ( const std::string &  _value ) const [inherited]

STL std::string form.

Definition at line 542 of file tinyxml.h.

TiXmlNode* FirstChild ( const std::string &  _value ) [inherited]

STL std::string form.

Definition at line 543 of file tinyxml.h.

const TiXmlElement * FirstChildElement ( const char *  _value ) const [inherited]

Convenience function to get through elements.

Definition at line 462 of file tinyxml.cpp.

const TiXmlElement* FirstChildElement ( const std::string &  _value ) const [inherited]

STL std::string form.

Definition at line 678 of file tinyxml.h.

TiXmlElement* FirstChildElement ( const std::string &  _value ) [inherited]

STL std::string form.

Definition at line 679 of file tinyxml.h.

const TiXmlElement * FirstChildElement (  ) const [inherited]

Convenience function to get through elements.

Definition at line 447 of file tinyxml.cpp.

const TiXmlDocument * GetDocument (  ) const [inherited]

Return a pointer to the Document this node lives in.

Returns null if not in a document.

Definition at line 507 of file tinyxml.cpp.

void* GetUserData (  ) [inherited]

Get a pointer to arbitrary user data.

Definition at line 250 of file tinyxml.h.

const void* GetUserData (  ) const [inherited]

Get a pointer to arbitrary user data.

Definition at line 251 of file tinyxml.h.

TiXmlNode * InsertAfterChild ( TiXmlNode afterThis,
const TiXmlNode addThis 
) [inherited]

Add a new node related to this.

Adds a child after the specified child. Returns a pointer to the new object or NULL if an error occured.

Definition at line 259 of file tinyxml.cpp.

TiXmlNode * InsertBeforeChild ( TiXmlNode beforeThis,
const TiXmlNode addThis 
) [inherited]

Add a new node related to this.

Adds a child before the specified child. Returns a pointer to the new object or NULL if an error occured.

Definition at line 227 of file tinyxml.cpp.

TiXmlNode * InsertEndChild ( const TiXmlNode addThis ) [inherited]

Add a new node related to this.

Adds a child past the LastChild. Returns a pointer to the new object or NULL if an error occured.

Definition at line 212 of file tinyxml.cpp.

static bool IsWhiteSpaceCondensed (  ) [static, inherited]

Return the current white space setting.

Definition at line 226 of file tinyxml.h.

const TiXmlNode * IterateChildren ( const TiXmlNode previous ) const [inherited]

An alternate way to walk the children of a node.

One way to iterate over nodes is:

            for( child = parent->FirstChild(); child; child = child->NextSibling() )
        

IterateChildren does the same thing with the syntax:

            child = 0;
            while( child = parent->IterateChildren( child ) )
        

IterateChildren takes the previous child as input and finds the next one. If the previous child is null, it returns the first. IterateChildren will return null when done.

Definition at line 380 of file tinyxml.cpp.

const TiXmlNode * IterateChildren ( const char *  value,
const TiXmlNode previous 
) const [inherited]

This flavor of IterateChildren searches for children with a particular 'value'.

Definition at line 394 of file tinyxml.cpp.

const TiXmlNode* IterateChildren ( const std::string &  _value,
const TiXmlNode previous 
) const [inherited]

STL std::string form.

Definition at line 576 of file tinyxml.h.

TiXmlNode* IterateChildren ( const std::string &  _value,
const TiXmlNode previous 
) [inherited]

STL std::string form.

Definition at line 577 of file tinyxml.h.

TiXmlNode* LastChild ( const std::string &  _value ) [inherited]

STL std::string form.

Definition at line 545 of file tinyxml.h.

const TiXmlNode* LastChild ( const std::string &  _value ) const [inherited]

STL std::string form.

Definition at line 544 of file tinyxml.h.

TiXmlNode* LastChild (  ) [inherited]

The last child of this node. Will be null if there are no children.

Definition at line 534 of file tinyxml.h.

TiXmlNode* LastChild ( const char *  _value ) [inherited]

The last child of this node matching 'value'. Will be null if there are no children.

Definition at line 537 of file tinyxml.h.

TiXmlNode * LinkEndChild ( TiXmlNode addThis ) [inherited]

Add a new node related to this.

Adds a child past the LastChild.

NOTE: the node to be added is passed by pointer, and will be henceforth owned (and deleted) by tinyXml. This method is efficient and avoids an extra copy, but should be used with care as it uses a different memory model than the other insert functions.

See also:
InsertEndChild

Definition at line 185 of file tinyxml.cpp.

const TiXmlNode* NextSibling (  ) const [inherited]

Navigate to a sibling node.

Definition at line 633 of file tinyxml.h.

const TiXmlNode* NextSibling ( const std::string &  _value ) const [inherited]

STL std::string form.

Definition at line 628 of file tinyxml.h.

TiXmlNode* NextSibling ( const std::string &  _value ) [inherited]

STL std::string form.

Definition at line 629 of file tinyxml.h.

const TiXmlNode * NextSibling ( const char *  _value ) const [inherited]

Navigate to a sibling node with the given 'value'.

Definition at line 408 of file tinyxml.cpp.

const TiXmlElement * NextSiblingElement ( const char *  _value ) const [inherited]

Convenience function to get through elements.

Calls NextSibling and ToElement. Will skip all non-Element nodes. Returns 0 if there is not another element.

Definition at line 492 of file tinyxml.cpp.

const TiXmlElement * NextSiblingElement (  ) const [inherited]

Convenience function to get through elements.

Calls NextSibling and ToElement. Will skip all non-Element nodes. Returns 0 if there is not another element.

Definition at line 477 of file tinyxml.cpp.

const TiXmlElement* NextSiblingElement ( const std::string &  _value ) const [inherited]

STL std::string form.

Definition at line 661 of file tinyxml.h.

TiXmlElement* NextSiblingElement ( const std::string &  _value ) [inherited]

STL std::string form.

Definition at line 662 of file tinyxml.h.

bool NoChildren (  ) const [inherited]

Returns true if this node has no children.

Definition at line 697 of file tinyxml.h.

TiXmlNode* Parent (  ) [inherited]

One step up the DOM.

Definition at line 521 of file tinyxml.h.

const TiXmlNode* PreviousSibling (  ) const [inherited]

Navigate to a sibling node.

Definition at line 616 of file tinyxml.h.

const TiXmlNode* PreviousSibling ( const std::string &  _value ) const [inherited]

STL std::string form.

Definition at line 626 of file tinyxml.h.

const TiXmlNode * PreviousSibling ( const char *  _value ) const [inherited]

Navigate to a sibling node.

Definition at line 420 of file tinyxml.cpp.

TiXmlNode* PreviousSibling ( const std::string &  _value ) [inherited]

STL std::string form.

Definition at line 627 of file tinyxml.h.

void Print ( FILE *  cfile,
int  depth 
) const [virtual]

All TinyXml classes can print themselves to a filestream or the string class (TiXmlString in non-STL mode, std::string in STL mode.) Either or both cfile and str can be null.

This is a formatted print, and will insert tabs and newlines.

(For an unformatted stream, use the << operator.)

Implements TiXmlBase.

Definition at line 1285 of file tinyxml.cpp.

bool RemoveChild ( TiXmlNode removeThis ) [inherited]

Delete a child of this node.

Definition at line 330 of file tinyxml.cpp.

TiXmlNode * ReplaceChild ( TiXmlNode replaceThis,
const TiXmlNode withThis 
) [inherited]

Replace a child of this node.

Returns a pointer to the new object or NULL if an error occured.

Definition at line 291 of file tinyxml.cpp.

int Row (  ) const [inherited]

Return the position, in the original source file, of this node or attribute.

The row and column are 1-based. (That is the first row and first column is 1,1). If the returns values are 0 or less, then the parser does not have a row and column value.

Generally, the row and column value will be set when the TiXmlDocument::Load(), TiXmlDocument::LoadFile(), or any TiXmlNode::Parse() is called. It will NOT be set when the DOM was created from operator>>.

The values reflect the initial load. Once the DOM is modified programmatically (by adding or changing nodes and attributes) the new values will NOT update to reflect changes in the document.

There is a minor performance cost to computing the row and column. Computation can be disabled if TiXmlDocument::SetTabSize() is called with 0 as the value.

See also:
TiXmlDocument::SetTabSize()

Definition at line 246 of file tinyxml.h.

void SetCDATA ( bool  _cdata )

Turns on or off a CDATA representation of text.

Definition at line 1240 of file tinyxml.h.

static void SetCondenseWhiteSpace ( bool  condense ) [static, inherited]

The world does not agree on whether white space should be kept or not.

In order to make everyone happy, these global, static functions are provided to set whether or not TinyXml will condense all white space into a single space or not. The default is to condense. Note changing this value is not thread safe.

Definition at line 223 of file tinyxml.h.

void SetUserData ( void *  user ) [inherited]

Set a pointer to arbitrary user data.

Definition at line 249 of file tinyxml.h.

void SetValue ( const char *  _value ) [inherited]

Changes the value of the node.

Defined as:

        Document:    filename of the xml file
        Element:    name of the element
        Comment:    the comment text
        Unknown:    the tag contents
        Text:        the text string
        

Definition at line 510 of file tinyxml.h.

void SetValue ( const std::string &  _value ) [inherited]

STL std::string form.

Definition at line 514 of file tinyxml.h.

virtual TiXmlComment* ToComment (  ) [virtual, inherited]

Cast to a more defined type. Will return null if not of the requested type.

Reimplemented in TiXmlComment.

Definition at line 708 of file tinyxml.h.

virtual const TiXmlComment* ToComment (  ) const [virtual, inherited]

Cast to a more defined type. Will return null if not of the requested type.

Reimplemented in TiXmlComment.

Definition at line 701 of file tinyxml.h.

virtual const TiXmlDeclaration* ToDeclaration (  ) const [virtual, inherited]

Cast to a more defined type. Will return null if not of the requested type.

Reimplemented in TiXmlDeclaration.

Definition at line 704 of file tinyxml.h.

virtual TiXmlDeclaration* ToDeclaration (  ) [virtual, inherited]

Cast to a more defined type. Will return null if not of the requested type.

Reimplemented in TiXmlDeclaration.

Definition at line 711 of file tinyxml.h.

virtual TiXmlDocument* ToDocument (  ) [virtual, inherited]

Cast to a more defined type. Will return null if not of the requested type.

Reimplemented in TiXmlDocument.

Definition at line 706 of file tinyxml.h.

virtual const TiXmlDocument* ToDocument (  ) const [virtual, inherited]

Cast to a more defined type. Will return null if not of the requested type.

Reimplemented in TiXmlDocument.

Definition at line 699 of file tinyxml.h.

virtual const TiXmlElement* ToElement (  ) const [virtual, inherited]

Cast to a more defined type. Will return null if not of the requested type.

Reimplemented in TiXmlElement.

Definition at line 700 of file tinyxml.h.

virtual TiXmlElement* ToElement (  ) [virtual, inherited]

Cast to a more defined type. Will return null if not of the requested type.

Reimplemented in TiXmlElement.

Definition at line 707 of file tinyxml.h.

virtual TiXmlText* ToText (  ) [virtual]

Cast to a more defined type. Will return null not of the requested type.

Reimplemented from TiXmlNode.

Definition at line 1245 of file tinyxml.h.

virtual const TiXmlText* ToText (  ) const [virtual]

Cast to a more defined type. Will return null not of the requested type.

Reimplemented from TiXmlNode.

Definition at line 1244 of file tinyxml.h.

virtual const TiXmlUnknown* ToUnknown (  ) const [virtual, inherited]

Cast to a more defined type. Will return null if not of the requested type.

Reimplemented in TiXmlUnknown.

Definition at line 702 of file tinyxml.h.

virtual TiXmlUnknown* ToUnknown (  ) [virtual, inherited]

Cast to a more defined type. Will return null if not of the requested type.

Reimplemented in TiXmlUnknown.

Definition at line 709 of file tinyxml.h.

int Type (  ) const [inherited]

Query the type (as an enumerated value, above) of this node.

The possible types are: DOCUMENT, ELEMENT, COMMENT, UNKNOWN, TEXT, and DECLARATION.

Definition at line 686 of file tinyxml.h.

const char* Value (  ) const [inherited]

The meaning of 'value' changes for the specific type of TiXmlNode.

        Document:    filename of the xml file
        Element:    name of the element
        Comment:    the comment text
        Unknown:    the tag contents
        Text:        the text string
        

The subclasses will wrap this function.

Definition at line 489 of file tinyxml.h.

const std::string& ValueStr (  ) const [inherited]

Return Value() as a std::string.

If you only use STL, this is more efficient than calling Value(). Only available in STL mode.

Definition at line 496 of file tinyxml.h.


Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  out,
const TiXmlNode base 
) [friend, inherited]

An output stream operator, for every class.

Note that this outputs without any newlines or formatting, as opposed to Print(), which includes tabs and new lines.

The operator<< and operator>> are not completely symmetric. Writing a node to a stream is very well defined. You'll get a nice stream of output, without any extra whitespace or newlines.

But reading is not as well defined. (As it always is.) If you create a TiXmlElement (for example) and read that from an input stream, the text needs to define an element or junk will result. This is true of all input streams, but it's worth keeping in mind.

A TiXmlDocument will read nodes until it reads a root element, and all the children of that root element.

Definition at line 1561 of file tinyxml.cpp.

std::string& operator<< ( std::string &  out,
const TiXmlNode base 
) [friend, inherited]

Appends the XML node or attribute to a std::string.

Definition at line 1572 of file tinyxml.cpp.

std::istream& operator>> ( std::istream &  in,
TiXmlNode base 
) [friend, inherited]

An input stream operator, for every class.

Tolerant of newlines and formatting, but doesn't expect them.

Definition at line 1548 of file tinyxml.cpp.


Field Documentation

void* userData [protected, inherited]

Field containing a generic user pointer.

Definition at line 378 of file tinyxml.h.