33 #ifndef TINYXML_INCLUDED
34 #define TINYXML_INCLUDED
37 #pragma warning( push )
38 #pragma warning( disable : 4530 )
39 #pragma warning( disable : 4786 )
49 #if defined( _DEBUG ) && !defined( DEBUG )
57 #define TIXML_STRING std::string
60 #define TIXML_STRING TiXmlString
70 #if defined(_MSC_VER) && (_MSC_VER >= 1400 )
72 #define TIXML_SNPRINTF _snprintf_s
73 #define TIXML_SNSCANF _snscanf_s
74 #elif defined(_MSC_VER) && (_MSC_VER >= 1200 )
77 #define TIXML_SNPRINTF _snprintf
78 #define TIXML_SNSCANF _snscanf
79 #elif defined(__GNUC__) && (__GNUC__ >= 3 )
82 #define TIXML_SNPRINTF snprintf
83 #define TIXML_SNSCANF snscanf
216 virtual void Print( FILE* cfile,
int depth )
const = 0;
258 virtual const char*
Parse(
const char* p,
290 return ( isspace( (
unsigned char) c ) || c ==
'\n' || c ==
'\r' );
313 static const char*
ReadText(
const char* in,
315 bool ignoreWhiteSpace,
331 assert( *length >= 0 && *length < 5 );
341 return GetEntity( p, _value, length, encoding );
349 for(
int i=0; p[i] && i<*length; ++i ) {
352 return p + (*length);
388 if ( v < 128 )
return tolower( v );
529 return const_cast< TiXmlNode*
> ((
const_cast< const TiXmlNode*
>(
this))->FirstChild( _value ));
536 return const_cast< TiXmlNode*
> ((
const_cast< const TiXmlNode*
>(
this))->LastChild( _value ));
564 return const_cast< TiXmlNode*
>( (
const_cast< const TiXmlNode*
>(
this))->IterateChildren( previous ) );
570 return const_cast< TiXmlNode*
>( (
const_cast< const TiXmlNode*
>(
this))->IterateChildren( _value, previous ) );
620 return const_cast< TiXmlNode*
>( (
const_cast< const TiXmlNode*
>(
this))->PreviousSibling( _prev ) );
637 return const_cast< TiXmlNode*
>( (
const_cast< const TiXmlNode*
>(
this))->NextSibling( _next ) );
655 return const_cast< TiXmlElement*
>( (
const_cast< const TiXmlNode*
>(
this))->NextSiblingElement( _next ) );
672 return const_cast< TiXmlElement*
>( (
const_cast< const TiXmlNode*
>(
this))->FirstChildElement( _value ) );
870 virtual void Print( FILE* cfile,
int depth )
const {
871 Print( cfile, depth, 0 );
963 const char*
Attribute(
const char* name )
const;
971 const char*
Attribute(
const char* name,
int* i )
const;
979 const char*
Attribute(
const char* name,
double* d )
const;
1000 #ifdef TIXML_USE_STL
1014 sstream >> *outValue;
1015 if ( !sstream.fail() )
1024 void SetAttribute(
const char* name,
const char * _value );
1026 #ifdef TIXML_USE_STL
1052 #ifdef TIXML_USE_STL
1098 virtual void Print( FILE* cfile,
int depth )
const;
1118 #ifdef TIXML_USE_STL
1152 virtual void Print( FILE* cfile,
int depth )
const;
1170 #ifdef TIXML_USE_STL
1200 #ifdef TIXML_USE_STL
1213 virtual void Print( FILE* cfile,
int depth )
const;
1236 #ifdef TIXML_USE_STL
1264 #ifdef TIXML_USE_STL
1273 const char* _encoding,
1274 const char* _standalone );
1292 virtual void Print( FILE* cfile,
int depth )
const {
1293 Print( cfile, depth, 0 );
1308 #ifdef TIXML_USE_STL
1339 virtual void Print( FILE* cfile,
int depth )
const;
1353 #ifdef TIXML_USE_STL
1374 #ifdef TIXML_USE_STL
1394 bool SaveFile(
const char * filename )
const;
1404 #ifdef TIXML_USE_STL
1415 return SaveFile( filename.c_str() );
1505 virtual void Print( FILE* cfile,
int depth = 0 )
const;
1519 #ifdef TIXML_USE_STL
1652 #ifdef TIXML_USE_STL
1756 #ifdef TIXML_USE_STL
1763 for(
int i=0; i<
depth; ++i )
1779 #pragma warning( pop )
static const int utf8ByteTable[256]
TiXmlHandle Child(const std::string &_value, int index) const
const TiXmlAttribute * First() const
virtual const char * Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)
TiXmlNode * LastChild(const char *_value)
The last child of this node matching 'value'. Will be null if there are no children.
An attribute is a name-value pair.
TiXmlHandle(TiXmlNode *_node)
Create a handle from any node (at any depth of the tree.) This can be a null pointer.
virtual TiXmlNode * Clone() const
Creates a copy of this Declaration and returns it.
TiXmlUnknown * Unknown() const
TiXmlNode * FirstChild(const std::string &_value)
STL std::string form.
virtual bool Accept(TiXmlVisitor *visitor) const
Walk the XML tree visiting this node and all of its children.
friend std::ostream & operator<<(std::ostream &out, const TiXmlNode &base)
An output stream operator, for every class.
void SetUserData(void *user)
Set a pointer to arbitrary user data.
If you call the Accept() method, it requires being passed a TiXmlVisitor class to handle callbacks...
virtual void StreamIn(std::istream *in, TIXML_STRING *tag)
virtual const TiXmlDocument * ToDocument() const
Cast to a more defined type. Will return null not of the requested type.
TiXmlUnknown(const TiXmlUnknown ©)
const TiXmlNode * Parent() const
const std::string & ValueStr() const
Return Value() as a std::string.
const TiXmlElement * RootElement() const
Get the root element – the only top level element – of the document.
void SetLineBreak(const char *_lineBreak)
Set the line breaking string.
TiXmlElement * NextSiblingElement()
virtual const TiXmlElement * ToElement() const
Cast to a more defined type. Will return null not of the requested type.
TiXmlHandle(const TiXmlHandle &ref)
Copy constructor.
void operator=(const TiXmlNode &base)
TiXmlNode * PreviousSibling(const char *_prev)
TiXmlNode * LastChild()
The last child of this node. Will be null if there are no children.
const char * LineBreak()
Query the current line breaking string.
virtual TiXmlNode * Clone() const
Creates a new Element and returns it - the returned element is a copy.
bool Error() const
If an error occurs, Error will be set to true.
virtual TiXmlElement * ToElement()
Cast to a more defined type. Will return null if not of the requested type.
double DoubleValue() const
Return the value of this attribute, converted to a double.
virtual bool Visit(const TiXmlUnknown &)
Visit an unknow node.
TiXmlAttribute(const char *_name, const char *_value)
Construct an attribute with a name and value.
virtual void StreamIn(std::istream *in, TIXML_STRING *tag)=0
int IntValue() const
Return the value of this attribute, converted to an integer.
virtual const TiXmlText * ToText() const
Cast to a more defined type. Will return null not of the requested type.
virtual const char * Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)
TiXmlHandle FirstChild() const
Return a handle to the first child node.
void CopyTo(TiXmlUnknown *target) const
const void * GetUserData() const
Get a pointer to arbitrary user data.
void CopyTo(TiXmlDocument *target) const
int Type() const
Query the type (as an enumerated value, above) of this node.
static int ToLower(int v, TiXmlEncoding encoding)
TiXmlNode * IterateChildren(const std::string &_value, const TiXmlNode *previous)
STL std::string form.
const TiXmlElement * FirstChildElement(const std::string &_value) const
STL std::string form.
TiXmlNode * IterateChildren(const char *_value, const TiXmlNode *previous)
static int IsAlphaNum(unsigned char anyByte, TiXmlEncoding encoding)
void SetDoubleAttribute(const char *name, double value)
Sets an attribute of name to a given value.
void operator=(const TiXmlUnknown ©)
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 ...
int ErrorId() const
Generally, you probably want the error string ( ErrorDesc() ).
virtual void StreamIn(std::istream *in, TIXML_STRING *tag)
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 ...
TiXmlElement * NextSiblingElement(const std::string &_value)
STL std::string form.
const TIXML_STRING & NameTStr() const
TiXmlAttribute * FirstAttribute()
void operator=(const TiXmlDeclaration ©)
void operator=(const TiXmlAttributeSet &)
TiXmlElement * FirstChildElement(const char *_value)
virtual TiXmlNode * Clone() const
[internal use] Creates a new Element and returns it.
void operator=(const TiXmlDocument ©)
void SetValue(const std::string &_value)
STL std::string form.
virtual void Print(FILE *cfile, int depth, TIXML_STRING *str) const
static const char * ReadName(const char *p, TIXML_STRING *name, TiXmlEncoding encoding)
TiXmlNode * ReplaceChild(TiXmlNode *replaceThis, const TiXmlNode &withThis)
Replace a child of this node.
bool SaveFile(const std::string &filename) const
< STL std::string version.
virtual void StreamIn(std::istream *in, TIXML_STRING *tag)
const TiXmlAttribute * LastAttribute() const
Access the last attribute in this element.
virtual bool VisitExit(const TiXmlElement &)
Visit an element.
void SetName(const char *_name)
Set the name of this attribute.
TiXmlNode * NextSibling()
void SetTabSize(int _tabsize)
SetTabSize() allows the error reporting functions (ErrorRow() and ErrorCol()) to report the correct v...
TiXmlDocument()
Create an empty document, that has no name.
TiXmlAttribute()
Construct an empty attribute.
const int TIXML_PATCH_VERSION
const char * Standalone() const
Is this a standalone document?
TiXmlElement * ToElement() const
Return the handle as a TiXmlElement.
TiXmlElement * NextSiblingElement(const char *_next)
TiXmlElement * FirstChildElement()
virtual TiXmlDocument * ToDocument()
Cast to a more defined type. Will return null if not of the requested type.
void ClearError()
If you have handled the error, it can be reset with this call.
const char * Value() const
Return the value of this attribute.
virtual const TiXmlComment * ToComment() const
Cast to a more defined type. Will return null if not of the requested type.
int QueryIntValue(int *_value) const
QueryIntValue examines the value string.
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 ...
friend std::istream & operator>>(std::istream &in, TiXmlNode &base)
An input stream operator, for every class.
static bool StreamTo(std::istream *in, int character, TIXML_STRING *tag)
bool LoadFile(TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
Load a file using the current document value.
static const char * errorString[TIXML_ERROR_STRING_COUNT]
void SetValue(const char *_value)
Changes the value of the node.
int ErrorCol() const
The column where the error occured. See ErrorRow()
TiXmlNode * InsertEndChild(const TiXmlNode &addThis)
Add a new node related to this.
virtual bool VisitExit(const TiXmlDocument &doc)
Visit a document.
static void ConvertUTF32ToUTF8(unsigned long input, char *output, int *length)
virtual TiXmlElement * ToElement()
Cast to a more defined type. Will return null not of the requested type.
TiXmlNode * InsertBeforeChild(TiXmlNode *beforeThis, const TiXmlNode &addThis)
Add a new node related to this.
static bool condenseWhiteSpace
virtual void StreamIn(std::istream *in, TIXML_STRING *tag)
TiXmlNode * PreviousSibling()
NodeType
The types of XML nodes supported by TinyXml.
virtual const TiXmlDeclaration * ToDeclaration() const
Cast to a more defined type. Will return null if not of the requested type.
TiXmlAttribute * Find(const char *_name)
virtual bool VisitEnter(const TiXmlDocument &)
Visit a document.
TiXmlHandle FirstChildElement() const
Return a handle to the first child element.
TiXmlHandle ChildElement(const std::string &_value, int index) const
const char * Encoding() const
Encoding. Will return an empty string if none was found.
TiXmlNode * LinkEndChild(TiXmlNode *addThis)
Add a new node related to this.
static void PutString(const TIXML_STRING &str, TIXML_STRING *out)
const TiXmlNode * LastChild() const
const char * Name() const
Return the name of this attribute.
void SetDoubleValue(double _value)
Set the value from a double.
void * userData
Field containing a generic user pointer.
virtual bool Accept(TiXmlVisitor *visitor) const =0
Accept a hierchical visit the nodes in the TinyXML DOM.
TiXmlDocument * GetDocument()
void Print() const
Write the document to standard out using formatted printing ("pretty print").
In correct XML the declaration is the first entry in the file.
const TiXmlAttribute * Last() const
static bool IsWhiteSpace(char c)
TiXmlAttributeSet attributeSet
Any tag that tinyXml doesn't recognize is saved as an unknown.
virtual bool Visit(const TiXmlText &)
Visit a text node.
const TiXmlEncoding TIXML_DEFAULT_ENCODING
int ErrorRow() const
Returns the location (if known) of the error.
const char * Version() const
Version. Will return an empty string if none was found.
TiXmlNode * NextSibling(const char *_next)
TiXmlHandle ChildElement(const char *value, int index) const
Return a handle to the "index" child element with the given name.
virtual bool Accept(TiXmlVisitor *content) const
Walk the XML tree visiting this node and all of its children.
int Column() const
See Row()
static bool IsWhiteSpaceCondensed()
Return the current white space setting.
TiXmlText(const TiXmlText ©)
static const char * ReadText(const char *in, TIXML_STRING *text, bool ignoreWhiteSpace, const char *endTag, bool ignoreCase, TiXmlEncoding encoding)
const int TIXML_MAJOR_VERSION
void SetIndent(const char *_indent)
Set the indent characters for printing.
const TiXmlNode * FirstChild() const
The first child of this node. Will be null if there are no children.
const char * ErrorDesc() const
Contains a textual (english) description of the error if one occurs.
bool LoadFile(const std::string &filename, TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
virtual const TiXmlUnknown * ToUnknown() const
Cast to a more defined type. Will return null not of the requested type.
virtual TiXmlDocument * ToDocument()
Cast to a more defined type. Will return null not of the requested type.
const TiXmlAttribute * Next() const
Get the next sibling attribute in the DOM. Returns null at end.
void RemoveAttribute(const char *name)
Deletes an attribute with the given name.
virtual TiXmlNode * Clone() const
Create an exact duplicate of this node and return it.
void SetAttribute(const char *name, const char *_value)
Sets an attribute of name to a given value.
virtual const char * Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)
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 ...
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 ...
void SetCDATA(bool _cdata)
Turns on or off a CDATA representation of text.
const char * Indent()
Query the indention string.
TiXmlElement * FirstChildElement(const std::string &_value)
STL std::string form.
bool SaveFile() const
Save a file using the current document value. Returns true if successful.
virtual TiXmlDeclaration * ToDeclaration()
Cast to a more defined type. Will return null not of the requested type.
Always the top level node.
const TiXmlElement * FirstChildElement() const
Convenience function to get through elements.
virtual const char * Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)=0
virtual const char * Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)
virtual const TiXmlDeclaration * ToDeclaration() const
Cast to a more defined type. Will return null not of the requested type.
int QueryDoubleValue(double *_value) const
QueryDoubleValue examines the value string. See QueryIntValue().
TiXmlElement(const char *in_value)
Construct an element.
const TiXmlNode * LastChild(const std::string &_value) const
STL std::string form.
int QueryFloatAttribute(const char *name, float *_value) const
QueryFloatAttribute examines the attribute - see QueryIntAttribute().
const TiXmlNode * PreviousSibling() const
Navigate to a sibling node.
const TiXmlNode * NextSibling(const std::string &_value) const
STL std::string form.
const TiXmlAttribute * Find(const char *_name) const
static Entity entity[NUM_ENTITY]
static const char * SkipWhiteSpace(const char *, TiXmlEncoding encoding)
TiXmlNode * Identify(const char *start, TiXmlEncoding encoding)
TiXmlNode * InsertAfterChild(TiXmlNode *afterThis, const TiXmlNode &addThis)
Add a new node related to this.
void operator=(const TiXmlAttribute &base)
virtual TiXmlDeclaration * ToDeclaration()
Cast to a more defined type. Will return null if not of the requested type.
virtual const TiXmlElement * ToElement() const
Cast to a more defined type. Will return null if not of the requested type.
const char * ReadValue(const char *in, TiXmlParsingData *prevData, TiXmlEncoding encoding)
TiXmlHandle Child(const char *value, int index) const
Return a handle to the "index" child with the given name.
void Add(TiXmlAttribute *attribute)
const std::string & ValueStr() const
Return the value of this attribute.
const TiXmlDocument * GetDocument() const
Return a pointer to the Document this node lives in.
bool CDATA() const
Queries whether this represents text using a CDATA section.
A TiXmlHandle is a class that wraps a node pointer with null checks; this is an incredibly useful thi...
static bool IsWhiteSpace(int c)
virtual TiXmlComment * ToComment()
Cast to a more defined type. Will return null if not of the requested type.
bool operator>(const TiXmlAttribute &rhs) const
const TiXmlNode * IterateChildren(const std::string &_value, const TiXmlNode *previous) const
STL std::string form.
static const char * GetEntity(const char *in, char *value, int *length, TiXmlEncoding encoding)
void operator=(const TiXmlBase &base)
TiXmlNode * ToNode() const
Return the handle as a TiXmlNode.
const TiXmlAttribute * Previous() const
Get the previous sibling attribute in the DOM. Returns null at beginning.
static void SetCondenseWhiteSpace(bool condense)
The world does not agree on whether white space should be kept or not.
bool operator<(const TiXmlAttribute &rhs) const
TiXmlBase is a base class for every class in TinyXml.
const TiXmlElement * NextSiblingElement() const
Convenience function to get through elements.
TiXmlNode * Parent()
One step up the DOM.
virtual TiXmlUnknown * ToUnknown()
Cast to a more defined type. Will return null if not of the requested type.
bool operator==(const TiXmlAttribute &rhs) const
virtual const char * Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)
virtual const TiXmlUnknown * ToUnknown() const
Cast to a more defined type. Will return null if not of the requested type.
static bool StringEqual(const char *p, const char *endTag, bool ignoreCase, TiXmlEncoding encoding)
virtual bool VisitEnter(const TiXmlDocument &doc)
Visit a document.
virtual const char * Parse(const char *p, TiXmlParsingData *data=0, TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
Parse the given null terminated block of xml data.
void operator=(const TiXmlElement &base)
TiXmlHandle operator=(const TiXmlHandle &ref)
TiXmlNode * IterateChildren(const TiXmlNode *previous)
int QueryIntAttribute(const char *name, int *_value) const
QueryIntAttribute examines the attribute - it is an alternative to the Attribute() method with richer...
int Row() const
Return the position, in the original source file, of this node or attribute.
TiXmlHandle FirstChild(const std::string &_value) const
void SetError(int err, const char *errorLocation, TiXmlParsingData *prevData, TiXmlEncoding encoding)
TiXmlAttribute * Previous()
TiXmlElement * Element() const
virtual bool Accept(TiXmlVisitor *content) const
Walk the XML tree visiting this node and all of its children.
TiXmlNode(NodeType _type)
TiXmlElement * RootElement()
int QueryValueAttribute(const std::string &name, T *outValue) const
Template form of the attribute query which will try to read the attribute into the specified type...
void * GetUserData()
Get a pointer to arbitrary user data.
The parent class for everything in the Document Object Model.
virtual const TiXmlText * ToText() const
Cast to a more defined type. Will return null if not of the requested type.
void CopyTo(TiXmlNode *target) const
TiXmlNode * LastChild(const std::string &_value)
STL std::string form.
size_t Size()
Return the length of the result string.
void SetIntValue(int _value)
Set the value from an integer.
Print to memory functionality.
TiXmlNode * PreviousSibling(const std::string &_value)
STL std::string form.
virtual TiXmlNode * Clone() const
Creates a copy of this Unknown and returns it.
const TiXmlNode * FirstChild(const std::string &_value) const
STL std::string form.
virtual bool VisitExit(const TiXmlDocument &)
Visit a document.
virtual bool Visit(const TiXmlComment &)
Visit a comment node.
static bool StreamWhiteSpace(std::istream *in, TIXML_STRING *tag)
static const char * GetChar(const char *p, char *_value, int *length, TiXmlEncoding encoding)
int QueryDoubleAttribute(const char *name, double *_value) const
QueryDoubleAttribute examines the attribute - see QueryIntAttribute().
void operator=(const TiXmlText &base)
TiXmlText(const char *initValue)
Constructor for text element.
const TiXmlNode * IterateChildren(const TiXmlNode *previous) const
An alternate way to walk the children of a node.
const char * Value() const
The meaning of 'value' changes for the specific type of TiXmlNode.
TiXmlNode * NextSibling(const std::string &_value)
STL std::string form.
void CopyTo(TiXmlText *target) const
bool NoChildren() const
Returns true if this node has no children.
void CopyTo(TiXmlElement *target) const
virtual bool Accept(TiXmlVisitor *visitor) const
Walk the XML tree visiting this node and all of its children.
const TiXmlAttribute * FirstAttribute() const
Access the first attribute in this element.
bool RemoveChild(TiXmlNode *removeThis)
Delete a child of this node.
void RemoveAttribute(const std::string &name)
STL std::string form.
void SetDocument(TiXmlDocument *doc)
const char * GetText() const
Convenience function for easy access to the text inside an element.
virtual TiXmlUnknown * ToUnknown()
Cast to a more defined type. Will return null not of the requested type.
virtual const TiXmlDocument * ToDocument() const
Cast to a more defined type. Will return null if not of the requested type.
void Remove(TiXmlAttribute *attribute)
void Clear()
Delete all the children of this node. Does not affect 'this'.
TiXmlHandle FirstChildElement(const std::string &_value) const
void SetValue(const char *_value)
Set the value.
const std::string & Str()
Return the result.
virtual ~TiXmlDeclaration()
const TiXmlNode * NextSibling() const
Navigate to a sibling node.
virtual TiXmlText * ToText()
Cast to a more defined type. Will return null not of the requested type.
TiXmlAttribute * LastAttribute()
TiXmlText * ToText() const
Return the handle as a TiXmlText.
TiXmlDeclaration()
Construct an empty declaration.
void SetStreamPrinting()
Switch over to "stream printing" which is the most dense formatting without linebreaks.
static int IsAlpha(unsigned char anyByte, TiXmlEncoding encoding)
const char * Attribute(const char *name) const
Given an attribute name, Attribute() returns the value for the attribute of that name, or null if none exists.
virtual void Print(FILE *cfile, int depth) const =0
All TinyXml classes can print themselves to a filestream or the string class (TiXmlString in non-STL ...
virtual bool Accept(TiXmlVisitor *content) const
Walk the XML tree visiting this node and all of its children.
virtual TiXmlNode * Clone() const =0
Create an exact duplicate of this node and return it.
virtual void StreamIn(std::istream *in, TIXML_STRING *tag)
const TiXmlElement * NextSiblingElement(const std::string &_value) const
STL std::string form.
virtual bool Visit(const TiXmlDeclaration &declaration)
Visit a declaration.
void CopyTo(TiXmlDeclaration *target) const
TiXmlUnknown * ToUnknown() const
Return the handle as a TiXmlUnknown.
const TiXmlNode * PreviousSibling(const std::string &_value) const
STL std::string form.
const char * CStr()
Return the result.
virtual TiXmlText * ToText()
Cast to a more defined type. Will return null if not of the requested type.
const int TIXML_MINOR_VERSION
The element is a container class.
TiXmlCursor errorLocation
virtual bool VisitEnter(const TiXmlElement &, const TiXmlAttribute *)
Visit an element.
virtual bool Visit(const TiXmlDeclaration &)
Visit a declaration.
TiXmlAttribute * Find(const std::string &_name)