TinyXML Test Suite

struct TiXmlBaseEntity

Public Members

const char *TiXmlBase::Entitystr
unsigned int TiXmlBase::EntitystrLength
char TiXmlBase::Entitychr
class TiXmlAttribute : public TiXmlBase
#include <tinyxml.h>

An attribute is a name-value pair.

Elements have an arbitrary number of attributes, each with a unique name.

Note
The attributes are not TiXmlNodes, since they are not part of the tinyXML document object model. There are other suggested ways to look at this problem.

Public Functions

TiXmlAttributeTiXmlAttribute()

Construct an empty attribute.

TiXmlAttributeTiXmlAttribute(const std::string &_name, const std::string &_value)

std::string constructor.

TiXmlAttributeTiXmlAttribute(const char *_name, const char *_value)

Construct an attribute with a name and value.

const char *TiXmlAttributeName() const

Return the name of this attribute.

const char *TiXmlAttributeValue() const

Return the value of this attribute.

const std::string &TiXmlAttributeValueStr() const

Return the value of this attribute.

int TiXmlAttributeIntValue() const

Return the value of this attribute, converted to an integer.

double TiXmlAttributeDoubleValue() const

Return the value of this attribute, converted to a double.

const TIXML_STRING &TiXmlAttributeNameTStr() const
int TiXmlAttributeQueryIntValue(int *_value) const

QueryIntValue examines the value string.

It is an alternative to the IntValue() method with richer error checking. If the value is an integer, it is stored in ‘value’ and the call returns TIXML_SUCCESS. If it is not an integer, it returns TIXML_WRONG_TYPE.

A specialized but useful call. Note that for success it returns 0, which is the opposite of almost all other TinyXml calls.

int TiXmlAttributeQueryDoubleValue(double *_value) const

QueryDoubleValue examines the value string. See QueryIntValue().

void TiXmlAttributeSetName(const char *_name)

Set the name of this attribute.

void TiXmlAttributeSetValue(const char *_value)

Set the value.

void TiXmlAttributeSetIntValue(int _value)

Set the value from an integer.

void TiXmlAttributeSetDoubleValue(double _value)

Set the value from a double.

void TiXmlAttributeSetName(const std::string &_name)

STL std::string form.

void TiXmlAttributeSetValue(const std::string &_value)

STL std::string form.

const TiXmlAttribute *TiXmlAttributeNext() const

Get the next sibling attribute in the DOM. Returns null at end.

TiXmlAttribute *TiXmlAttributeNext()
const TiXmlAttribute *TiXmlAttributePrevious() const

Get the previous sibling attribute in the DOM. Returns null at beginning.

TiXmlAttribute *TiXmlAttributePrevious()
bool TiXmlAttributeoperator==(const TiXmlAttribute &rhs) const
bool TiXmlAttributeoperator<(const TiXmlAttribute &rhs) const
bool TiXmlAttributeoperator>(const TiXmlAttribute &rhs) const
virtual const char *TiXmlAttributeParse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)
virtual void TiXmlAttributePrint(FILE *cfile, int depth) const

All TinyXml classes can print themselves to a file stream 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.)

void TiXmlAttributePrint(FILE *cfile, int depth, TIXML_STRING *str) const
void TiXmlAttributeSetDocument(TiXmlDocument *doc)

Private Functions

TiXmlAttributeTiXmlAttribute(const TiXmlAttribute&)
void TiXmlAttributeoperator=(const TiXmlAttribute &base)

Friends

friend TiXmlAttribute::TiXmlAttributeSet
class TiXmlAttributeSet

Public Functions

TiXmlAttributeSetTiXmlAttributeSet()
TiXmlAttributeSet~TiXmlAttributeSet()
void TiXmlAttributeSetAdd(TiXmlAttribute *attribute)
void TiXmlAttributeSetRemove(TiXmlAttribute *attribute)
const TiXmlAttribute *TiXmlAttributeSetFirst() const
TiXmlAttribute *TiXmlAttributeSetFirst()
const TiXmlAttribute *TiXmlAttributeSetLast() const
TiXmlAttribute *TiXmlAttributeSetLast()
const TiXmlAttribute *TiXmlAttributeSetFind(const char *_name) const
TiXmlAttribute *TiXmlAttributeSetFind(const char *_name)
const TiXmlAttribute *TiXmlAttributeSetFind(const std::string &_name) const
TiXmlAttribute *TiXmlAttributeSetFind(const std::string &_name)

Private Functions

TiXmlAttributeSetTiXmlAttributeSet(const TiXmlAttributeSet&)
void TiXmlAttributeSetoperator=(const TiXmlAttributeSet&)

Private Members

TiXmlAttribute TiXmlAttributeSetsentinel
class TiXmlBase
#include <tinyxml.h>

TiXmlBase is a base class for every class in TinyXml.

It does little except to establish that TinyXml classes can be printed and provide some utility functions.

In XML, the document and elements can contain other elements and other types of nodes.

A Document can contain: Element (container or leaf)
                        Comment (leaf)
                        Unknown (leaf)
                        Declaration( leaf )

An Element can contain: Element (container or leaf)
                        Text    (leaf)
                        Attributes (not on tree)
                        Comment (leaf)
                        Unknown (leaf)

A Decleration contains: Attributes (not on tree)

Subclassed by TiXmlAttribute, TiXmlNode

Public Types

enum [anonymous]__anonymous1

Values:

TiXmlBaseTIXML_NO_ERROR = 0
TiXmlBaseTIXML_ERROR
TiXmlBaseTIXML_ERROR_OPENING_FILE
TiXmlBaseTIXML_ERROR_OUT_OF_MEMORY
TiXmlBaseTIXML_ERROR_PARSING_ELEMENT
TiXmlBaseTIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME
TiXmlBaseTIXML_ERROR_READING_ELEMENT_VALUE
TiXmlBaseTIXML_ERROR_READING_ATTRIBUTES
TiXmlBaseTIXML_ERROR_PARSING_EMPTY
TiXmlBaseTIXML_ERROR_READING_END_TAG
TiXmlBaseTIXML_ERROR_PARSING_UNKNOWN
TiXmlBaseTIXML_ERROR_PARSING_COMMENT
TiXmlBaseTIXML_ERROR_PARSING_DECLARATION
TiXmlBaseTIXML_ERROR_DOCUMENT_EMPTY
TiXmlBaseTIXML_ERROR_EMBEDDED_NULL
TiXmlBaseTIXML_ERROR_PARSING_CDATA
TiXmlBaseTIXML_ERROR_DOCUMENT_TOP_ONLY
TiXmlBaseTIXML_ERROR_STRING_COUNT

Public Functions

TiXmlBaseTiXmlBase()
virtual TiXmlBase~TiXmlBase()
virtual void TiXmlBasePrint(FILE *cfile, int depth) const = 0

All TinyXml classes can print themselves to a file stream 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.)

int TiXmlBaseRow() const

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
TiXmlDocument::SetTabSize()

int TiXmlBaseColumn() const

See Row()

void TiXmlBaseSetUserData(void *user)

Set a pointer to arbitrary user data.

void *TiXmlBaseGetUserData()

Get a pointer to arbitrary user data.

const void *TiXmlBaseGetUserData() const

Get a pointer to arbitrary user data.

virtual const char *TiXmlBaseParse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding) = 0

Public Static Functions

static void TiXmlBaseSetCondenseWhiteSpace(bool condense)

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.

static bool TiXmlBaseIsWhiteSpaceCondensed()

Return the current white space setting.

Public Static Attributes

const int TiXmlBaseutf8ByteTable[256]

Protected Attributes

TiXmlCursor TiXmlBaselocation
void *TiXmlBaseuserData

Field containing a generic user pointer.

Protected Static Functions

static const char *TiXmlBaseSkipWhiteSpace(const char *, TiXmlEncoding encoding)
static bool TiXmlBaseIsWhiteSpace(char c)
static bool TiXmlBaseIsWhiteSpace(int c)
static bool TiXmlBaseStreamWhiteSpace(std::istream *in, TIXML_STRING *tag)
static bool TiXmlBaseStreamTo(std::istream *in, int character, TIXML_STRING *tag)
static const char *TiXmlBaseReadName(const char *p, TIXML_STRING *name, TiXmlEncoding encoding)
static const char *TiXmlBaseReadText(const char *in, TIXML_STRING *text, bool ignoreWhiteSpace, const char *endTag, bool ignoreCase, TiXmlEncoding encoding)
static const char *TiXmlBaseGetEntity(const char *in, char *value, int *length, TiXmlEncoding encoding)
static const char *TiXmlBaseGetChar(const char *p, char *_value, int *length, TiXmlEncoding encoding)
static void TiXmlBasePutString(const TIXML_STRING &str, TIXML_STRING *out)
static bool TiXmlBaseStringEqual(const char *p, const char *endTag, bool ignoreCase, TiXmlEncoding encoding)
static int TiXmlBaseIsAlpha(unsigned char anyByte, TiXmlEncoding encoding)
static int TiXmlBaseIsAlphaNum(unsigned char anyByte, TiXmlEncoding encoding)
static int TiXmlBaseToLower(int v, TiXmlEncoding encoding)
static void TiXmlBaseConvertUTF32ToUTF8(unsigned long input, char *output, int *length)

Protected Static Attributes

const char *TiXmlBaseerrorString[TIXML_ERROR_STRING_COUNT]

Private Types

enum [anonymous]__anonymous2

Values:

TiXmlBaseNUM_ENTITY = 5
TiXmlBaseMAX_ENTITY_LENGTH = 6

Private Functions

TiXmlBaseTiXmlBase(const TiXmlBase&)
void TiXmlBaseoperator=(const TiXmlBase &base)

Private Static Attributes

Entity TiXmlBaseentity[NUM_ENTITY]
bool TiXmlBasecondenseWhiteSpace

Friends

friend TiXmlBase::TiXmlNode
friend TiXmlBase::TiXmlElement
friend TiXmlBase::TiXmlDocument
class TiXmlComment : public TiXmlNode
#include <tinyxml.h>

An XML comment.

Public Functions

TiXmlCommentTiXmlComment()

Constructs an empty comment.

TiXmlCommentTiXmlComment(const char *_value)

Construct a comment from text.

TiXmlCommentTiXmlComment(const TiXmlComment&)
void TiXmlCommentoperator=(const TiXmlComment &base)
virtual TiXmlComment~TiXmlComment()
virtual TiXmlNode *TiXmlCommentClone() const

Returns a copy of this Comment.

virtual void TiXmlCommentPrint(FILE *cfile, int depth) const

All TinyXml classes can print themselves to a file stream 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.)

virtual const char *TiXmlCommentParse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)
virtual const TiXmlComment *TiXmlCommentToComment() const

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

virtual TiXmlComment *TiXmlCommentToComment()

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

virtual bool TiXmlCommentAccept(TiXmlVisitor *visitor) const

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

Protected Functions

void TiXmlCommentCopyTo(TiXmlComment *target) const
virtual void TiXmlCommentStreamIn(std::istream *in, TIXML_STRING *tag)
struct TiXmlCursor

Public Functions

TiXmlCursorTiXmlCursor()
void TiXmlCursorClear()

Public Members

int TiXmlCursorrow
int TiXmlCursorcol
class TiXmlDeclaration : public TiXmlNode
#include <tinyxml.h>

In correct XML the declaration is the first entry in the file.

    <?xml version="1.0" standalone="yes"?>

TinyXml will happily read or write files without a declaration, however. There are 3 possible attributes to the declaration: version, encoding, and standalone.

Note: In this version of the code, the attributes are handled as special cases, not generic attributes, simply because there can only be at most 3 and they are always the same.

Public Functions

TiXmlDeclarationTiXmlDeclaration()

Construct an empty declaration.

TiXmlDeclarationTiXmlDeclaration(const std::string &_version, const std::string &_encoding, const std::string &_standalone)

Constructor.

TiXmlDeclarationTiXmlDeclaration(const char *_version, const char *_encoding, const char *_standalone)

Construct.

TiXmlDeclarationTiXmlDeclaration(const TiXmlDeclaration &copy)
void TiXmlDeclarationoperator=(const TiXmlDeclaration &copy)
virtual TiXmlDeclaration~TiXmlDeclaration()
const char *TiXmlDeclarationVersion() const

Version. Will return an empty string if none was found.

const char *TiXmlDeclarationEncoding() const

Encoding. Will return an empty string if none was found.

const char *TiXmlDeclarationStandalone() const

Is this a standalone document?

virtual TiXmlNode *TiXmlDeclarationClone() const

Creates a copy of this Declaration and returns it.

virtual void TiXmlDeclarationPrint(FILE *cfile, int depth, TIXML_STRING *str) const
virtual void TiXmlDeclarationPrint(FILE *cfile, int depth) const

All TinyXml classes can print themselves to a file stream 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.)

virtual const char *TiXmlDeclarationParse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)
virtual const TiXmlDeclaration *TiXmlDeclarationToDeclaration() const

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

virtual TiXmlDeclaration *TiXmlDeclarationToDeclaration()

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

virtual bool TiXmlDeclarationAccept(TiXmlVisitor *visitor) const

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

Protected Functions

void TiXmlDeclarationCopyTo(TiXmlDeclaration *target) const
virtual void TiXmlDeclarationStreamIn(std::istream *in, TIXML_STRING *tag)

Private Members

TIXML_STRING TiXmlDeclarationversion
TIXML_STRING TiXmlDeclarationencoding
TIXML_STRING TiXmlDeclarationstandalone
class TiXmlDocument : public TiXmlNode
#include <tinyxml.h>

Always the top level node.

A document binds together all the XML pieces. It can be saved, loaded, and printed to the screen. The ‘value’ of a document node is the xml file name.

Public Functions

TiXmlDocumentTiXmlDocument()

Create an empty document, that has no name.

TiXmlDocumentTiXmlDocument(const char *documentName)

Create a document with a name. The name of the document is also the filename of the xml.

TiXmlDocumentTiXmlDocument(const std::string &documentName)

Constructor.

TiXmlDocumentTiXmlDocument(const TiXmlDocument &copy)
void TiXmlDocumentoperator=(const TiXmlDocument &copy)
virtual TiXmlDocument~TiXmlDocument()
bool TiXmlDocumentLoadFile(TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING)

Load a file using the current document value.

Returns true if successful. Will delete any existing document data before loading.

bool TiXmlDocumentSaveFile() const

Save a file using the current document value. Returns true if successful.

bool TiXmlDocumentLoadFile(const char *filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING)

Load a file using the given filename. Returns true if successful.

bool TiXmlDocumentSaveFile(const char *filename) const

Save a file using the given filename. Returns true if successful.

bool TiXmlDocumentLoadFile(FILE *, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING)

Load a file using the given FILE*.

Returns true if successful. Note that this method doesn’t stream - the entire object pointed at by the FILE* will be interpreted as an XML file. TinyXML doesn’t stream in XML from the current file location. Streaming may be added in the future.

bool TiXmlDocumentSaveFile(FILE *) const

Save a file using the given FILE*. Returns true if successful.

bool TiXmlDocumentLoadFile(const std::string &filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING)

Parameters
  • encoding: STL std::string version.

bool TiXmlDocumentSaveFile(const std::string &filename) const

< STL std::string version.

virtual const char *TiXmlDocumentParse(const char *p, TiXmlParsingData *data = 0, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING)

Parse the given null terminated block of xml data.

Passing in an encoding to this method (either TIXML_ENCODING_LEGACY or TIXML_ENCODING_UTF8 will force TinyXml to use that encoding, regardless of what TinyXml might otherwise try to detect.

const TiXmlElement *TiXmlDocumentRootElement() const

Get the root element the only top level element of the document.

In well formed XML, there should only be one. TinyXml is tolerant of multiple elements at the document level.

TiXmlElement *TiXmlDocumentRootElement()
bool TiXmlDocumentError() const

If an error occurs, Error will be set to true.

Also,

  • The ErrorId() will contain the integer identifier of the error (not generally useful)
  • The ErrorDesc() method will return the name of the error. (very useful)
  • The ErrorRow() and ErrorCol() will return the location of the error (if known)

const char *TiXmlDocumentErrorDesc() const

Contains a textual (English) description of the error if one occurs.

int TiXmlDocumentErrorId() const

Generally, you probably want the error string ( ErrorDesc() ).

But if you prefer the ErrorId, this function will fetch it.

int TiXmlDocumentErrorRow() const

Returns the location (if known) of the error.

The first column is column 1, and the first row is row 1. A value of 0 means the row and column wasn’t applicable (memory errors, for example, have no row/column) or the parser lost the error. (An error in the error reporting, in that case.)

See
SetTabSize, Row, Column

int TiXmlDocumentErrorCol() const

The column where the error occurred. See ErrorRow()

void TiXmlDocumentSetTabSize(int _tabsize)

SetTabSize() allows the error reporting functions (ErrorRow() and ErrorCol()) to report the correct values for row and column.

It does not change the output or input in any way.

By calling this method, with a tab size greater than 0, the row and column of each node and attribute is stored when the file is loaded. Very useful for tracking the DOM back in to the source file.

The tab size is required for calculating the location of nodes. If not set, the default of 4 is used. The tabsize is set per document. Setting the tabsize to 0 disables row/column tracking.

Note that row and column tracking is not supported when using operator>>.

The tab size needs to be enabled before the parse or load. Correct usage:

TiXmlDocument doc;
doc.SetTabSize( 8 );
doc.Load( "myfile.xml" );

See
Row, Column

int TiXmlDocumentTabSize() const
void TiXmlDocumentClearError()

If you have handled the error, it can be reset with this call.

The error state is automatically cleared if you Parse a new XML block.

void TiXmlDocumentPrint() const

Write the document to standard out using formatted printing (“pretty print”).

virtual void TiXmlDocumentPrint(FILE *cfile, int depth = 0) const

Print this Document to a FILE stream.

void TiXmlDocumentSetError(int err, const char *errorLocation, TiXmlParsingData *prevData, TiXmlEncoding encoding)
virtual const TiXmlDocument *TiXmlDocumentToDocument() const

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

virtual TiXmlDocument *TiXmlDocumentToDocument()

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

virtual bool TiXmlDocumentAccept(TiXmlVisitor *content) const

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

Protected Functions

virtual TiXmlNode *TiXmlDocumentClone() const

Create an exact duplicate of this node and return it.

The memory must be deleted by the caller.

virtual void TiXmlDocumentStreamIn(std::istream *in, TIXML_STRING *tag)

Private Functions

void TiXmlDocumentCopyTo(TiXmlDocument *target) const

Private Members

bool TiXmlDocumenterror
int TiXmlDocumenterrorId
TIXML_STRING TiXmlDocumenterrorDesc
int TiXmlDocumenttabsize
TiXmlCursor TiXmlDocumenterrorLocation
bool TiXmlDocumentuseMicrosoftBOM
class TiXmlElement : public TiXmlNode
#include <tinyxml.h>

The element is a container class.

It has a value, the element name, and can contain other elements, text, comments, and unknowns. Elements also contain an arbitrary number of attributes.

Public Functions

TiXmlElementTiXmlElement(const char *in_value)

Construct an element.

TiXmlElementTiXmlElement(const std::string &_value)

std::string constructor.

TiXmlElementTiXmlElement(const TiXmlElement&)
void TiXmlElementoperator=(const TiXmlElement &base)
virtual TiXmlElement~TiXmlElement()
const char *TiXmlElementAttribute(const char *name) const

Given an attribute name, Attribute() returns the value for the attribute of that name, or null if none exists.

const char *TiXmlElementAttribute(const char *name, int *i) const

Given an attribute name, Attribute() returns the value for the attribute of that name, or null if none exists.

If the attribute exists and can be converted to an integer, the integer value will be put in the return ‘i’, if ‘i’ is non-null.

const char *TiXmlElementAttribute(const char *name, double *d) const

Given an attribute name, Attribute() returns the value for the attribute of that name, or null if none exists.

If the attribute exists and can be converted to an double, the double value will be put in the return ‘d’, if ‘d’ is non-null.

int TiXmlElementQueryIntAttribute(const char *name, int *_value) const

QueryIntAttribute examines the attribute - it is an alternative to the Attribute() method with richer error checking.

If the attribute is an integer, it is stored in ‘value’ and the call returns TIXML_SUCCESS. If it is not an integer, it returns TIXML_WRONG_TYPE. If the attribute does not exist, then TIXML_NO_ATTRIBUTE is returned.

int TiXmlElementQueryDoubleAttribute(const char *name, double *_value) const

QueryDoubleAttribute examines the attribute - see QueryIntAttribute().

int TiXmlElementQueryFloatAttribute(const char *name, float *_value) const

QueryFloatAttribute examines the attribute - see QueryIntAttribute().

template <typename T>
int TiXmlElementQueryValueAttribute(const std::string &name, T *outValue) const

Template form of the attribute query which will try to read the attribute into the specified type.

Very easy, very powerful, but be careful to make sure to call this with the correct type.

Return
TIXML_SUCCESS, TIXML_WRONG_TYPE, or TIXML_NO_ATTRIBUTE

void TiXmlElementSetAttribute(const char *name, const char *_value)

Sets an attribute of name to a given value.

The attribute will be created if it does not exist, or changed if it does.

const std::string *TiXmlElementAttribute(const std::string &name) const
const std::string *TiXmlElementAttribute(const std::string &name, int *i) const
const std::string *TiXmlElementAttribute(const std::string &name, double *d) const
int TiXmlElementQueryIntAttribute(const std::string &name, int *_value) const
int TiXmlElementQueryDoubleAttribute(const std::string &name, double *_value) const
void TiXmlElementSetAttribute(const std::string &name, const std::string &_value)

STL std::string form.

STL std::string form.

void TiXmlElementSetAttribute(const std::string &name, int _value)
void TiXmlElementSetAttribute(const char *name, int value)

Sets an attribute of name to a given value.

The attribute will be created if it does not exist, or changed if it does.

void TiXmlElementSetDoubleAttribute(const char *name, double value)

Sets an attribute of name to a given value.

The attribute will be created if it does not exist, or changed if it does.

void TiXmlElementRemoveAttribute(const char *name)

Deletes an attribute with the given name.

void TiXmlElementRemoveAttribute(const std::string &name)

STL std::string form.

const TiXmlAttribute *TiXmlElementFirstAttribute() const

Access the first attribute in this element.

TiXmlAttribute *TiXmlElementFirstAttribute()
const TiXmlAttribute *TiXmlElementLastAttribute() const

Access the last attribute in this element.

TiXmlAttribute *TiXmlElementLastAttribute()
const char *TiXmlElementGetText() 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.

virtual TiXmlNode *TiXmlElementClone() const

Creates a new Element and returns it - the returned element is a copy.

virtual void TiXmlElementPrint(FILE *cfile, int depth) const

All TinyXml classes can print themselves to a file stream 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.)

virtual const char *TiXmlElementParse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)
virtual const TiXmlElement *TiXmlElementToElement() const

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

virtual TiXmlElement *TiXmlElementToElement()

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

virtual bool TiXmlElementAccept(TiXmlVisitor *visitor) const

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

Protected Functions

void TiXmlElementCopyTo(TiXmlElement *target) const
void TiXmlElementClearThis()
virtual void TiXmlElementStreamIn(std::istream *in, TIXML_STRING *tag)
const char *TiXmlElementReadValue(const char *in, TiXmlParsingData *prevData, TiXmlEncoding encoding)

Private Members

TiXmlAttributeSet TiXmlElementattributeSet
class TiXmlHandle
#include <tinyxml.h>

A TiXmlHandle is a class that wraps a node pointer with null checks; this is an incredibly useful thing.

Note that TiXmlHandle is not part of the TinyXml DOM structure. It is a separate utility class.

Take an example:

<Document>
    <Element attributeA = "valueA">
        <Child attributeB = "value1" />
        <Child attributeB = "value2" />
    </Element>
<Document>

Assuming you want the value of “attributeB” in the second “Child” element, it’s very easy to write a lot of code that looks like:

TiXmlElement* root = document.FirstChildElement( "Document" );
if ( root )
{
    TiXmlElement* element = root->FirstChildElement( "Element" );
    if ( element )
    {
        TiXmlElement* child = element->FirstChildElement( "Child" );
        if ( child )
        {
            TiXmlElement* child2 = child->NextSiblingElement( "Child" );
            if ( child2 )
            {
                // Finally do something useful.

And that doesn’t even cover “else” cases. TiXmlHandle addresses the verbosity of such code. A TiXmlHandle checks for null pointers so it is perfectly safe and correct to use:

TiXmlHandle docHandle( &document );
TiXmlElement* child2 = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).Child( "Child", 1 ).ToElement();
if ( child2 )
{
    // do something useful

Which is MUCH more concise and useful.

It is also safe to copy handles - internally they are nothing more than node pointers.

TiXmlHandle handleCopy = handle;

What they should not be used for is iteration:

int i=0; 
while ( true )
{
    TiXmlElement* child = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).Child( "Child", i ).ToElement();
    if ( !child )
        break;
    // do something
    ++i;
}

It seems reasonable, but it is in fact two embedded while loops. The Child method is a linear walk to find the element, so this code would iterate much more than it needs to. Instead, prefer:

TiXmlElement* child = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).FirstChild( "Child" ).ToElement();

for( child; child; child=child->NextSiblingElement() )
{
    // do something
}

Public Functions

TiXmlHandleTiXmlHandle(TiXmlNode *_node)

Create a handle from any node (at any depth of the tree.) This can be a null pointer.

TiXmlHandleTiXmlHandle(const TiXmlHandle &ref)

Copy constructor.

TiXmlHandle TiXmlHandleoperator=(const TiXmlHandle &ref)
TiXmlHandle TiXmlHandleFirstChild() const

Return a handle to the first child node.

TiXmlHandle TiXmlHandleFirstChild(const char *value) const

Return a handle to the first child node with the given name.

TiXmlHandle TiXmlHandleFirstChildElement() const

Return a handle to the first child element.

TiXmlHandle TiXmlHandleFirstChildElement(const char *value) const

Return a handle to the first child element with the given name.

TiXmlHandle TiXmlHandleChild(const char *value, int index) const

Return a handle to the “index” child with the given name.

The first child is 0, the second 1, etc.

TiXmlHandle TiXmlHandleChild(int index) const

Return a handle to the “index” child.

The first child is 0, the second 1, etc.

TiXmlHandle TiXmlHandleChildElement(const char *value, int index) const

Return a handle to the “index” child element with the given name.

The first child element is 0, the second 1, etc. Note that only TiXmlElements are indexed: other types are not counted.

TiXmlHandle TiXmlHandleChildElement(int index) const

Return a handle to the “index” child element.

The first child element is 0, the second 1, etc. Note that only TiXmlElements are indexed: other types are not counted.

TiXmlHandle TiXmlHandleFirstChild(const std::string &_value) const
TiXmlHandle TiXmlHandleFirstChildElement(const std::string &_value) const
TiXmlHandle TiXmlHandleChild(const std::string &_value, int index) const
TiXmlHandle TiXmlHandleChildElement(const std::string &_value, int index) const
TiXmlNode *TiXmlHandleToNode() const

Return the handle as a TiXmlNode.

This may return null.

TiXmlElement *TiXmlHandleToElement() const

Return the handle as a TiXmlElement.

This may return null.

TiXmlText *TiXmlHandleToText() const

Return the handle as a TiXmlText.

This may return null.

TiXmlUnknown *TiXmlHandleToUnknown() const

Return the handle as a TiXmlUnknown.

This may return null.

TiXmlNode *TiXmlHandleNode() const

Return the handle as a TiXmlNode. This may return null.

TiXmlElement *TiXmlHandleElement() const

Return the handle as a TiXmlElement. This may return null.

TiXmlText *TiXmlHandleText() const

This may return null.

TiXmlUnknown *TiXmlHandleUnknown() const

This may return null.

Private Members

TiXmlNode *TiXmlHandlenode
class TiXmlNode : public TiXmlBase
#include <tinyxml.h>

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.

Subclassed by TiXmlComment, TiXmlDeclaration, TiXmlDocument, TiXmlElement, TiXmlText, TiXmlUnknown

Public Types

enum TiXmlNodeNodeType

The types of XML nodes supported by TinyXml.

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

Values:

TiXmlNodeDOCUMENT
TiXmlNodeELEMENT
TiXmlNodeCOMMENT
TiXmlNodeUNKNOWN
TiXmlNodeTEXT
TiXmlNodeDECLARATION
TiXmlNodeTYPECOUNT

Public Functions

virtual TiXmlNode~TiXmlNode()
const char *TiXmlNodeValue() 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.

const std::string &TiXmlNodeValueStr() const

Return Value() as a std::string.

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

void TiXmlNodeSetValue(const char *_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

void TiXmlNodeSetValue(const std::string &_value)

STL std::string form.

void TiXmlNodeClear()

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

TiXmlNode *TiXmlNodeParent()

One step up the DOM.

const TiXmlNode *TiXmlNodeParent() const
const TiXmlNode *TiXmlNodeFirstChild() const

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

TiXmlNode *TiXmlNodeFirstChild()
const TiXmlNode *TiXmlNodeFirstChild(const char *value) const

The first child of this node with the matching ‘value’.

Will be null if none found.

TiXmlNode *TiXmlNodeFirstChild(const char *_value)

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

const TiXmlNode *TiXmlNodeLastChild() const
TiXmlNode *TiXmlNodeLastChild()

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

const TiXmlNode *TiXmlNodeLastChild(const char *value) const
TiXmlNode *TiXmlNodeLastChild(const char *_value)

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

const TiXmlNode *TiXmlNodeFirstChild(const std::string &_value) const

STL std::string form.

TiXmlNode *TiXmlNodeFirstChild(const std::string &_value)

STL std::string form.

const TiXmlNode *TiXmlNodeLastChild(const std::string &_value) const

STL std::string form.

TiXmlNode *TiXmlNodeLastChild(const std::string &_value)

STL std::string form.

const TiXmlNode *TiXmlNodeIterateChildren(const TiXmlNode *previous) const

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.

TiXmlNode *TiXmlNodeIterateChildren(const TiXmlNode *previous)
const TiXmlNode *TiXmlNodeIterateChildren(const char *value, const TiXmlNode *previous) const

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

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

STL std::string form.

TiXmlNode *TiXmlNodeIterateChildren(const std::string &_value, const TiXmlNode *previous)

STL std::string form.

TiXmlNode *TiXmlNodeInsertEndChild(const TiXmlNode &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 occurred.

TiXmlNode *TiXmlNodeLinkEndChild(TiXmlNode *addThis)

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
InsertEndChild

TiXmlNode *TiXmlNodeInsertBeforeChild(TiXmlNode *beforeThis, const TiXmlNode &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 occurred.

TiXmlNode *TiXmlNodeInsertAfterChild(TiXmlNode *afterThis, const TiXmlNode &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 occurred.

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

Replace a child of this node.

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

bool TiXmlNodeRemoveChild(TiXmlNode *removeThis)

Delete a child of this node.

const TiXmlNode *TiXmlNodePreviousSibling() const

Navigate to a sibling node.

TiXmlNode *TiXmlNodePreviousSibling()
const TiXmlNode *TiXmlNodePreviousSibling(const char *) const

Navigate to a sibling node.

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

STL std::string form.

TiXmlNode *TiXmlNodePreviousSibling(const std::string &_value)

STL std::string form.

const TiXmlNode *TiXmlNodeNextSibling(const std::string &_value) const

STL std::string form.

TiXmlNode *TiXmlNodeNextSibling(const std::string &_value)

STL std::string form.

const TiXmlNode *TiXmlNodeNextSibling() const

Navigate to a sibling node.

TiXmlNode *TiXmlNodeNextSibling()
const TiXmlNode *TiXmlNodeNextSibling(const char *) const

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

TiXmlNode *TiXmlNodeNextSibling(const char *_next)
const TiXmlElement *TiXmlNodeNextSiblingElement() const

Convenience function to get through elements.

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

TiXmlElement *TiXmlNodeNextSiblingElement()
const TiXmlElement *TiXmlNodeNextSiblingElement(const char *) const

Convenience function to get through elements.

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

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

STL std::string form.

TiXmlElement *TiXmlNodeNextSiblingElement(const std::string &_value)

STL std::string form.

const TiXmlElement *TiXmlNodeFirstChildElement() const

Convenience function to get through elements.

TiXmlElement *TiXmlNodeFirstChildElement()
const TiXmlElement *TiXmlNodeFirstChildElement(const char *_value) const

Convenience function to get through elements.

TiXmlElement *TiXmlNodeFirstChildElement(const char *_value)
const TiXmlElement *TiXmlNodeFirstChildElement(const std::string &_value) const

STL std::string form.

TiXmlElement *TiXmlNodeFirstChildElement(const std::string &_value)

STL std::string form.

int TiXmlNodeType() const

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

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

const TiXmlDocument *TiXmlNodeGetDocument() const

Return a pointer to the Document this node lives in.

Returns null if not in a document.

TiXmlDocument *TiXmlNodeGetDocument()
bool TiXmlNodeNoChildren() const

Returns true if this node has no children.

virtual const TiXmlDocument *TiXmlNodeToDocument() const

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

virtual const TiXmlElement *TiXmlNodeToElement() const

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

virtual const TiXmlComment *TiXmlNodeToComment() const

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

virtual const TiXmlUnknown *TiXmlNodeToUnknown() const

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

virtual const TiXmlText *TiXmlNodeToText() const

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

virtual const TiXmlDeclaration *TiXmlNodeToDeclaration() const

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

virtual TiXmlDocument *TiXmlNodeToDocument()

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

virtual TiXmlElement *TiXmlNodeToElement()

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

virtual TiXmlComment *TiXmlNodeToComment()

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

virtual TiXmlUnknown *TiXmlNodeToUnknown()

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

virtual TiXmlText *TiXmlNodeToText()

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

virtual TiXmlDeclaration *TiXmlNodeToDeclaration()

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

virtual TiXmlNode *TiXmlNodeClone() const = 0

Create an exact duplicate of this node and return it.

The memory must be deleted by the caller.

virtual bool TiXmlNodeAccept(TiXmlVisitor *visitor) const = 0

Accept a hierarchical 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();

Protected Functions

TiXmlNodeTiXmlNode(NodeType _type)
void TiXmlNodeCopyTo(TiXmlNode *target) const
virtual void TiXmlNodeStreamIn(std::istream *in, TIXML_STRING *tag) = 0
TiXmlNode *TiXmlNodeIdentify(const char *start, TiXmlEncoding encoding)

Protected Attributes

TiXmlNode *TiXmlNodeparent
NodeType TiXmlNodetype
TiXmlNode *TiXmlNodefirstChild
TiXmlNode *TiXmlNodelastChild
TIXML_STRING TiXmlNodevalue
TiXmlNode *TiXmlNodeprev
TiXmlNode *TiXmlNodenext

Private Functions

TiXmlNodeTiXmlNode(const TiXmlNode&)
void TiXmlNodeoperator=(const TiXmlNode &base)

Friends

friend TiXmlNode::TiXmlDocument
friend TiXmlNode::TiXmlElement
std::istream &operator>>(std::istream &in, TiXmlNode &base)

An input stream operator, for every class.

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

std::ostream &operator<<(std::ostream &out, const TiXmlNode &base)

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.

std::string &operator<<(std::string &out, const TiXmlNode &base)

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

class TiXmlPrinter : public TiXmlVisitor
#include <tinyxml.h>

Print to memory functionality.

The TiXmlPrinter is useful when you need to:

  1. Print to memory (especially in non-STL mode)
  2. Control formatting (line endings, etc.)

When constructed, the TiXmlPrinter is in its default “pretty printing” mode. Before calling Accept() you can call methods to control the printing of the XML document. After TiXmlNode::Accept() is called, the printed document can be accessed via the CStr(), Str(), and Size() methods.

TiXmlPrinter uses the Visitor API.

TiXmlPrinter printer;
printer.SetIndent( "\t" );

doc.Accept( &printer );
fprintf( stdout, "%s", printer.CStr() );

Public Functions

TiXmlPrinterTiXmlPrinter()
virtual bool TiXmlPrinterVisitEnter(const TiXmlDocument&)

Visit a document.

virtual bool TiXmlPrinterVisitExit(const TiXmlDocument&)

Visit a document.

virtual bool TiXmlPrinterVisitEnter(const TiXmlElement&, const TiXmlAttribute *)

Visit an element.

virtual bool TiXmlPrinterVisitExit(const TiXmlElement&)

Visit an element.

virtual bool TiXmlPrinterVisit(const TiXmlDeclaration&)

Visit a declaration.

virtual bool TiXmlPrinterVisit(const TiXmlText&)

Visit a text node.

virtual bool TiXmlPrinterVisit(const TiXmlComment&)

Visit a comment node.

virtual bool TiXmlPrinterVisit(const TiXmlUnknown&)

Visit an unknown node.

void TiXmlPrinterSetIndent(const char *_indent)

Set the indent characters for printing.

By default 4 spaces but tab () is also useful, or null/empty string for no indentation.

const char *TiXmlPrinterIndent()

Query the indention string.

void TiXmlPrinterSetLineBreak(const char *_lineBreak)

Set the line breaking string.

By default set to newline (

). Some operating systems prefer other characters, or can be set to the null/empty string for no indentation.

const char *TiXmlPrinterLineBreak()

Query the current line breaking string.

void TiXmlPrinterSetStreamPrinting()

Switch over to “stream printing” which is the most dense formatting without line breaks.

Common when the XML is needed for network transmission.

const char *TiXmlPrinterCStr()

Return the result.

size_t TiXmlPrinterSize()

Return the length of the result string.

const std::string &TiXmlPrinterStr()

Return the result.

Private Functions

void TiXmlPrinterDoIndent()
void TiXmlPrinterDoLineBreak()

Private Members

int TiXmlPrinterdepth
bool TiXmlPrintersimpleTextPrint
TIXML_STRING TiXmlPrinterbuffer
TIXML_STRING TiXmlPrinterindent
TIXML_STRING TiXmlPrinterlineBreak
class TiXmlText : public TiXmlNode
#include <tinyxml.h>

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().

Public Functions

TiXmlTextTiXmlText(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’

virtual TiXmlText~TiXmlText()
TiXmlTextTiXmlText(const std::string &initValue)

Constructor.

TiXmlTextTiXmlText(const TiXmlText &copy)
void TiXmlTextoperator=(const TiXmlText &base)
virtual void TiXmlTextPrint(FILE *cfile, int depth) const

All TinyXml classes can print themselves to a file stream 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.)

bool TiXmlTextCDATA() const

Queries whether this represents text using a CDATA section.

void TiXmlTextSetCDATA(bool _cdata)

Turns on or off a CDATA representation of text.

virtual const char *TiXmlTextParse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)
virtual const TiXmlText *TiXmlTextToText() const

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

virtual TiXmlText *TiXmlTextToText()

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

virtual bool TiXmlTextAccept(TiXmlVisitor *content) const

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

Protected Functions

virtual TiXmlNode *TiXmlTextClone() const

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

void TiXmlTextCopyTo(TiXmlText *target) const
bool TiXmlTextBlank() const
virtual void TiXmlTextStreamIn(std::istream *in, TIXML_STRING *tag)

Private Members

bool TiXmlTextcdata

Friends

friend TiXmlText::TiXmlElement
class TiXmlUnknown : public TiXmlNode
#include <tinyxml.h>

Any tag that tinyXml doesn’t recognize is saved as an unknown.

It is a tag of text, but should not be modified. It will be written back to the XML, unchanged, when the file is saved.

DTD tags get thrown into TiXmlUnknowns.

Public Functions

TiXmlUnknownTiXmlUnknown()
virtual TiXmlUnknown~TiXmlUnknown()
TiXmlUnknownTiXmlUnknown(const TiXmlUnknown &copy)
void TiXmlUnknownoperator=(const TiXmlUnknown &copy)
virtual TiXmlNode *TiXmlUnknownClone() const

Creates a copy of this Unknown and returns it.

virtual void TiXmlUnknownPrint(FILE *cfile, int depth) const

All TinyXml classes can print themselves to a file stream 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.)

virtual const char *TiXmlUnknownParse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)
virtual const TiXmlUnknown *TiXmlUnknownToUnknown() const

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

virtual TiXmlUnknown *TiXmlUnknownToUnknown()

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

virtual bool TiXmlUnknownAccept(TiXmlVisitor *content) const

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

Protected Functions

void TiXmlUnknownCopyTo(TiXmlUnknown *target) const
virtual void TiXmlUnknownStreamIn(std::istream *in, TIXML_STRING *tag)
class TiXmlVisitor
#include <tinyxml.h>

If you call the Accept() method, it requires being passed a TiXmlVisitor class to handle callbacks.

For nodes that contain other nodes (Document, Element) you will get called with a VisitEnter/VisitExit pair. Nodes that are always leaves are simple called with Visit().

If you return ‘true’ from a Visit method, recursive parsing will continue. If you return false, no children of this node or its sibilings will be Visited.

All flavors of Visit methods have a default implementation that returns ‘true’ (continue visiting). You need to only override methods that are interesting to you.

Generally Accept() is called on the TiXmlDocument, although all nodes support Visiting.

You should never change the document from a callback.

See
TiXmlNode::Accept()

Subclassed by TiXmlPrinter

Public Functions

virtual TiXmlVisitor~TiXmlVisitor()
virtual bool TiXmlVisitorVisitEnter(const TiXmlDocument&)

Visit a document.

virtual bool TiXmlVisitorVisitExit(const TiXmlDocument&)

Visit a document.

virtual bool TiXmlVisitorVisitEnter(const TiXmlElement&, const TiXmlAttribute *)

Visit an element.

virtual bool TiXmlVisitorVisitExit(const TiXmlElement&)

Visit an element.

virtual bool TiXmlVisitorVisit(const TiXmlDeclaration&)

Visit a declaration.

virtual bool TiXmlVisitorVisit(const TiXmlText&)

Visit a text node.

virtual bool TiXmlVisitorVisit(const TiXmlComment&)

Visit a comment node.

virtual bool TiXmlVisitorVisit(const TiXmlUnknown&)

Visit an unknown node.

file tinyxml.h
#include <ctype.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <assert.h>#include <string>#include <iostream>#include <sstream>

Defines

TIXML_USE_STL
TIXML_STRING
TIXML_SAFE

Enums

enum [anonymous]

Values:

TIXML_SUCCESS
TIXML_NO_ATTRIBUTE
TIXML_WRONG_TYPE
enum TiXmlEncoding

Values:

TIXML_ENCODING_UNKNOWN
TIXML_ENCODING_UTF8
TIXML_ENCODING_LEGACY

Variables

const int TIXML_MAJOR_VERSION = 2
const int TIXML_MINOR_VERSION = 5
const int TIXML_PATCH_VERSION = 2
const TiXmlEncoding TIXML_DEFAULT_ENCODING = TIXML_ENCODING_UNKNOWN
page deprecated