TiXmlNode

class TiXmlNode

Bases: TiXmlBase

The parent class for everything in the Document Object Model. (Except for attributes). Nodes have siblings, a parent, and children. A node can be in a document, or stand on its own. The type of a TiXmlNode can be queried, and it can be cast to its more defined type.

Inheritance diagram

Inheritance diagram of TiXmlNode

virtual bool Accept(TiXmlVisitor *visitor) const = 0

Accept a hierchical visit the nodes in the TinyXML DOM. Every node in the XML tree will be conditionally visited and the host will be called back via the TiXmlVisitor interface.

This is essentially a SAX interface for TinyXML. (Note however it doesn’t re-parse the XML for the callbacks, so the performance of TinyXML is unchanged by using this interface versus any other.)

The interface has been based on ideas from:

Which are both good references for “visiting”.

An example of using Accept():

TiXmlPrinter printer;
tinyxmlDoc.Accept( &printer );
const char* xmlcstr = printer.CStr();
void Clear(void)

/// Delete all the children of this node. Does not affect ‘this’.

virtual TiXmlNode *Clone(void) const = 0

Create an exact duplicate of this node and return it. The memory must be deleted by the caller.

TiXmlNode const *FirstChild(void) const
TiXmlNode *FirstChild(void)
TiXmlNode const *FirstChild(char const *value) const
TiXmlNode *FirstChild(char const *_value)
TiXmlNode const *FirstChild(std::string const &_value) const
TiXmlNode *FirstChild(std::string const &_value)

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

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

///< The first child of this node with the matching ‘value’. Will be null if none found. /// The first child of this node with the matching ‘value’. Will be null if none found.

///< STL std::string form.

///< STL std::string form.

TiXmlElement const *FirstChildElement(void) const
TiXmlElement *FirstChildElement(void)
TiXmlElement const *FirstChildElement(char const *_value) const
TiXmlElement *FirstChildElement(char const *_value)
TiXmlElement const *FirstChildElement(std::string const &_value) const
TiXmlElement *FirstChildElement(std::string const &_value)

/// Convenience function to get through elements.

/// Convenience function to get through elements.

///< STL std::string form.

///< STL std::string form.

TiXmlDocument const *GetDocument(void) const
TiXmlDocument *GetDocument(void)

Return a pointer to the Document this node lives in. Returns null if not in a document.

TiXmlNode *InsertAfterChild(TiXmlNode *afterThis, TiXmlNode const &addThis)

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.

TiXmlNode *InsertBeforeChild(TiXmlNode *beforeThis, TiXmlNode const &addThis)

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.

TiXmlNode *InsertEndChild(TiXmlNode const &addThis)

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.

TiXmlNode const *IterateChildren(TiXmlNode const *previous) const
TiXmlNode *IterateChildren(TiXmlNode const *previous)
TiXmlNode const *IterateChildren(char const *value, TiXmlNode const *previous) const
TiXmlNode *IterateChildren(char const *_value, TiXmlNode const *previous)
TiXmlNode const *IterateChildren(std::string const &_value, TiXmlNode const *previous) const
TiXmlNode *IterateChildren(std::string const &_value, TiXmlNode const *previous)

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.

This flavor of IterateChildren searches for children with a particular ‘value’

STL std::string form.

STL std::string form.

TiXmlNode const *LastChild(void) const
TiXmlNode *LastChild(void)
TiXmlNode const *LastChild(char const *value) const
TiXmlNode *LastChild(char const *_value)
TiXmlNode const *LastChild(std::string const &_value) const
TiXmlNode *LastChild(std::string const &_value)

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

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

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

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

///< STL std::string form.

///< STL std::string form.

TiXmlNode const *NextSibling(std::string const &_value) const
TiXmlNode *NextSibling(std::string const &_value)
TiXmlNode const *NextSibling(void) const
TiXmlNode *NextSibling(void)
TiXmlNode const *NextSibling(char const*) const
TiXmlNode *NextSibling(char const *_next)

///< STL std::string form.

///< STL std::string form.

/// Navigate to a sibling node.

/// Navigate to a sibling node with the given ‘value’.

TiXmlElement const *NextSiblingElement(void) const
TiXmlElement *NextSiblingElement(void)
TiXmlElement const *NextSiblingElement(char const*) const
TiXmlElement *NextSiblingElement(char const *_next)
TiXmlElement const *NextSiblingElement(std::string const &_value) const
TiXmlElement *NextSiblingElement(std::string const &_value)

Convenience function to get through elements. Calls NextSibling() and ToElement(). Will skip all non-Element nodes. Returns 0 if there is not another element.

Convenience function to get through elements. Calls NextSibling() and ToElement(). Will skip all non-Element nodes. Returns 0 if there is not another element.

STL std::string form.

STL std::string form.

bool NoChildren(void) const

/// Returns true if this node has no children.

enum NodeType

The types of XML nodes supported by TinyXml. (All the unsupported types are picked up by UNKNOWN.)

enumerator TINYXML_DOCUMENT = 0
enumerator TINYXML_ELEMENT = 1
enumerator TINYXML_COMMENT = 2
enumerator TINYXML_UNKNOWN = 3
enumerator TINYXML_TEXT = 4
enumerator TINYXML_DECLARATION = 5
enumerator TINYXML_TYPECOUNT = 6
TiXmlNode *Parent(void)
TiXmlNode const *Parent(void) const

/// One step up the DOM.

TiXmlNode const *PreviousSibling(void) const
TiXmlNode *PreviousSibling(void)
TiXmlNode const *PreviousSibling(char const*) const
TiXmlNode *PreviousSibling(char const *_prev)
TiXmlNode const *PreviousSibling(std::string const &_value) const
TiXmlNode *PreviousSibling(std::string const &_value)

/// Navigate to a sibling node.

/// Navigate to a sibling node.

///< STL std::string form.

///< STL std::string form.

bool RemoveChild(TiXmlNode *removeThis)

/// Delete a child of this node.

TiXmlNode *ReplaceChild(TiXmlNode *replaceThis, TiXmlNode const &withThis)

Replace a child of this node. Returns a pointer to the new object or NULL if an error occured.

void SetValue(char const *_value)
void SetValue(std::string const &_value)

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

STL std::string form.

virtual TiXmlComment const *ToComment(void) const
virtual TiXmlComment *ToComment(void)

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

virtual TiXmlDeclaration const *ToDeclaration(void) const
virtual TiXmlDeclaration *ToDeclaration(void)

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

virtual TiXmlDocument const *ToDocument(void) const
virtual TiXmlDocument *ToDocument(void)

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

virtual TiXmlElement const *ToElement(void) const
virtual TiXmlElement *ToElement(void)

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

virtual TiXmlText const *ToText(void) const
virtual TiXmlText *ToText(void)

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

virtual TiXmlUnknown const *ToUnknown(void) const
virtual TiXmlUnknown *ToUnknown(void)

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

int Type(void) const

Query the type (as an enumerated value, above) of this node. The possible types are: DOCUMENT, ELEMENT, COMMENT, UNKNOWN, TEXT, and DECLARATION.

char const *Value(void) const

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.

std::string const &ValueStr(void) const

Return Value() as a std::string. If you only use STL, this is more efficient than calling Value(). Only available in STL mode.

std::string const &ValueTStr(void) const