Go to the documentation of this file.
26 #ifndef TINYXML_INCLUDED
27 #define TINYXML_INCLUDED
29 #define TIXML_USE_STL // use STL strings instead
32 #pragma warning( push )
33 #pragma warning( disable : 4530 )
34 #pragma warning( disable : 4786 )
48 #if defined( _DEBUG ) && !defined( DEBUG )
56 #define TIXML_STRING std::string
59 #define TIXML_STRING TiXmlString
69 #if defined(_MSC_VER) && (_MSC_VER >= 1400 )
71 #define TIXML_SNPRINTF _snprintf_s
72 #define TIXML_SSCANF sscanf_s
73 #elif defined(_MSC_VER) && (_MSC_VER >= 1200 )
76 #define TIXML_SNPRINTF _snprintf
77 #define TIXML_SSCANF sscanf
78 #elif defined(__GNUC__) && (__GNUC__ >= 3 )
81 #define TIXML_SNPRINTF snprintf
82 #define TIXML_SSCANF sscanf
84 #define TIXML_SNPRINTF snprintf
85 #define TIXML_SSCANF sscanf
220 virtual void Print( FILE* cfile,
int depth )
const = 0;
254 void SetUserData(
void* user ) {
userData = user; }
255 void* GetUserData() {
return userData; }
256 const void* GetUserData()
const {
return userData; }
262 virtual const char*
Parse(
const char* p,
299 return ( isspace( (
unsigned char) c ) || c ==
'\n' || c ==
'\r' );
322 static const char*
ReadText(
const char* in,
324 bool ignoreWhiteSpace,
340 assert( *length >= 0 && *length < 5 );
350 return GetEntity( p, _value, length, encoding );
358 for(
int i=0; p[i] && i<*length; ++i ) {
361 return p + (*length);
393 if ( v < 128 )
return tolower( v );
407 unsigned int strLength;
413 MAX_ENTITY_LENGTH = 6
416 static Entity entity[ NUM_ENTITY ];
417 static bool condenseWhiteSpace;
518 void SetValue(
const std::string& _value ) {
value = _value; }
536 return const_cast< TiXmlNode*
> ((
const_cast< const TiXmlNode*
>(
this))->FirstChild( _value ));
543 return const_cast< TiXmlNode*
> ((
const_cast< const TiXmlNode*
>(
this))->LastChild( _value ));
571 return const_cast< TiXmlNode*
>( (
const_cast< const TiXmlNode*
>(
this))->IterateChildren( previous ) );
577 return const_cast< TiXmlNode*
>( (
const_cast< const TiXmlNode*
>(
this))->IterateChildren( _value, previous ) );
627 return const_cast< TiXmlNode*
>( (
const_cast< const TiXmlNode*
>(
this))->PreviousSibling( _prev ) );
644 return const_cast< TiXmlNode*
>( (
const_cast< const TiXmlNode*
>(
this))->NextSibling( _next ) );
662 return const_cast< TiXmlElement*
>( (
const_cast< const TiXmlNode*
>(
this))->NextSiblingElement( _next ) );
679 return const_cast< TiXmlElement*
>( (
const_cast< const TiXmlNode*
>(
this))->FirstChildElement( _value ) );
704 virtual const TiXmlDocument* ToDocument()
const {
return 0; }
705 virtual const TiXmlElement* ToElement()
const {
return 0; }
706 virtual const TiXmlComment* ToComment()
const {
return 0; }
707 virtual const TiXmlUnknown* ToUnknown()
const {
return 0; }
708 virtual const TiXmlText* ToText()
const {
return 0; }
715 virtual TiXmlText* ToText() {
return 0; }
795 TiXmlAttribute(
const std::string& _name,
const std::string& _value )
814 const char* Name()
const {
return name.c_str(); }
815 const char* Value()
const {
return value.c_str(); }
817 const std::string& ValueStr()
const {
return value; }
838 void SetName(
const char* _name ) { name = _name; }
839 void SetValue(
const char* _value ) { value = _value; }
845 void SetName(
const std::string& _name ) { name = _name; }
848 void SetValue(
const std::string& _value ) { value = _value; }
873 virtual void Print( FILE* cfile,
int depth )
const {
874 Print( cfile, depth, 0 );
923 # ifdef TIXML_USE_STL
952 template<
typename T = std::
string>
976 std::stringstream sstream( node->ValueStr() );
977 sstream >> *outValue;
978 if ( !sstream.fail() )
988 *outValue = node->ValueStr();
992 std::string
Attribute(
const std::string& name )
const;
993 std::string
Attribute(
const std::string& name,
int* i )
const;
994 std::string
Attribute(
const std::string& name,
double* d )
const;
996 void SetAttribute(
const std::string& name,
const std::string& _value );
1043 virtual void Print( FILE* cfile,
int depth )
const;
1050 virtual const TiXmlElement* ToElement()
const {
return this; }
1063 #ifdef TIXML_USE_STL
1096 virtual void Print( FILE* cfile,
int depth )
const;
1103 virtual const TiXmlComment* ToComment()
const {
return this; }
1114 #ifdef TIXML_USE_STL
1144 #ifdef TIXML_USE_STL
1157 virtual void Print( FILE* cfile,
int depth )
const;
1166 virtual const TiXmlText* ToText()
const {
return this; }
1167 virtual TiXmlText* ToText() {
return this; }
1180 #ifdef TIXML_USE_STL
1208 #ifdef TIXML_USE_STL
1211 const std::string& _encoding,
1212 const std::string& _standalone );
1217 const char* _encoding,
1218 const char* _standalone );
1226 const char *
Version()
const {
return version.c_str (); }
1228 const char *
Encoding()
const {
return encoding.c_str (); }
1236 virtual void Print( FILE* cfile,
int depth )
const {
1237 Print( cfile, depth, 0 );
1252 #ifdef TIXML_USE_STL
1283 virtual void Print( FILE* cfile,
int depth )
const;
1287 virtual const TiXmlUnknown* ToUnknown()
const {
return this; }
1297 #ifdef TIXML_USE_STL
1318 #ifdef TIXML_USE_STL
1338 bool SaveFile(
const char * filename )
const;
1348 #ifdef TIXML_USE_STL
1351 return LoadFile( filename.c_str(), encoding );
1355 return SaveFile( filename.c_str() );
1380 const char *
ErrorDesc()
const {
return errorDesc.c_str (); }
1395 int ErrorCol()
const {
return errorLocation.
col+1; }
1431 errorLocation.
row = errorLocation.
col = 0;
1445 virtual void Print( FILE* cfile,
int depth = 0 )
const;
1449 virtual const TiXmlDocument* ToDocument()
const {
return this; }
1459 #ifdef TIXML_USE_STL
1471 bool useMicrosoftBOM;
1592 #ifdef TIXML_USE_STL
1658 buffer(), indent(
" " ), lineBreak(
"\n" ) {}
1674 void SetIndent(
const char* _indent ) { indent = _indent ? _indent :
"" ; }
1676 const char*
Indent() {
return indent.c_str(); }
1681 void SetLineBreak(
const char* _lineBreak ) { lineBreak = _lineBreak ? _lineBreak :
""; }
1692 const char*
CStr() {
return buffer.c_str(); }
1694 size_t Size() {
return buffer.size(); }
1696 #ifdef TIXML_USE_STL
1697 const std::string&
Str() {
return buffer; }
1703 for(
int i=0; i<depth; ++i )
1706 void DoLineBreak() {
1707 buffer += lineBreak;
1711 bool simpleTextPrint;
1719 #pragma warning( pop )
TiXmlNode * ToNode() const
friend std::ostream & operator<<(std::ostream &out, const TiXmlNode &base)
TiXmlDeclaration()
Construct an empty declaration.
@ TIXML_ERROR_PARSING_UNKNOWN
TiXmlAttribute * FindOrCreate(const char *_name)
TiXmlAttribute(const char *_name, const char *_value)
Construct an attribute with a name and value.
virtual bool Visit(const TiXmlComment &)
Visit a comment node.
@ TIXML_ERROR_STRING_COUNT
int QueryDoubleValue(double *_value) const
QueryDoubleValue examines the value string. See QueryIntValue().
TiXmlHandle FirstChildElement() const
Return a handle to the first child element.
const TiXmlElement * NextSiblingElement() const
bool operator<(const TiXmlAttribute &rhs) const
@ TIXML_ERROR_READING_ATTRIBUTES
virtual bool Accept(TiXmlVisitor *visitor) const
bool NoChildren() const
Returns true if this node has no children.
static void EncodeString(const TIXML_STRING &str, TIXML_STRING *out)
virtual void StreamIn(std::istream *in, TIXML_STRING *tag)
static const char * SkipWhiteSpace(const char *, TiXmlEncoding encoding)
virtual const char * Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)
TiXmlDeclaration & operator=(const TiXmlDeclaration ©)
TiXmlNode * InsertAfterChild(TiXmlNode *afterThis, const TiXmlNode &addThis)
virtual bool Accept(TiXmlVisitor *content) const
static void ConvertUTF32ToUTF8(unsigned long input, char *output, int *length)
const char * Version() const
Version. Will return an empty string if none was found.
virtual void StreamIn(std::istream *in, TIXML_STRING *tag)
TiXmlHandle FirstChild(const std::string &_value) const
const std::string & ValueStr() const
TiXmlAttribute * Find(const char *_name) const
virtual bool VisitEnter(const TiXmlElement &, const TiXmlAttribute *)
Visit an element.
int QueryValueAttribute(const std::string &name, std::string *outValue) const
bool operator==(const TiXmlAttribute &rhs) const
size_t Size()
Return the length of the result string.
TiXmlUnknown * ToUnknown() const
static const char * GetChar(const char *p, char *_value, int *length, TiXmlEncoding encoding)
bool SaveFile(const std::string &filename) const
< STL std::string version.
static bool StreamWhiteSpace(std::istream *in, TIXML_STRING *tag)
const char * GetText() const
static int ToLower(int v, TiXmlEncoding encoding)
friend class TiXmlElement
void operator=(const TiXmlBase &base)=delete
TiXmlNode * LinkEndChild(TiXmlNode *addThis)
virtual bool VisitExit(const TiXmlElement &)
Visit an element.
int QueryIntValue(int *_value) const
const TiXmlNode * LastChild() const
virtual void Print(FILE *cfile, int depth) const
const char * ErrorDesc() const
Contains a textual (english) description of the error if one occurs.
virtual const char * Parse(const char *p, TiXmlParsingData *data=0, TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
void CopyTo(TiXmlUnknown *target) const
const TIXML_STRING & ValueTStr() const
virtual void Print(FILE *cfile, int depth, TIXML_STRING *str) const
TiXmlHandle Child(const std::string &_value, int index) const
TiXmlNode * PreviousSibling()
static int IsAlphaNum(unsigned char anyByte, TiXmlEncoding encoding)
static bool StringEqual(const char *p, const char *endTag, bool ignoreCase, TiXmlEncoding encoding)
virtual const char * Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)
virtual TiXmlNode * Clone() const
TiXmlHandle ChildElement(const char *value, int index) const
static bool IsWhiteSpaceCondensed()
Return the current white space setting.
static const char * errorString[TIXML_ERROR_STRING_COUNT]
virtual const char * Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)
TiXmlHandle FirstChild() const
Return a handle to the first child node.
virtual void Print(FILE *cfile, int depth) const =0
virtual bool Visit(const TiXmlText &)
Visit a text node.
void Add(TiXmlAttribute *attribute)
virtual bool VisitExit(const TiXmlDocument &doc)
Visit a document.
void operator=(const TiXmlNode &base)=delete
void SetIntValue(int _value)
Set the value from an integer.
TiXmlHandle ChildElement(const std::string &_value, int index) const
const TiXmlDocument * GetDocument() const
void SetName(const std::string &_name)
STL std::string form.
TiXmlText(const char *initValue)
TiXmlUnknown & operator=(const TiXmlUnknown ©)
const char * LineBreak()
Query the current line breaking string.
TiXmlUnknown * Unknown() const
const int TIXML_PATCH_VERSION
@ TIXML_ERROR_EMBEDDED_NULL
TiXmlNode * InsertBeforeChild(TiXmlNode *beforeThis, const TiXmlNode &addThis)
TiXmlDocument & operator=(const TiXmlDocument ©)
@ TIXML_ERROR_READING_ELEMENT_VALUE
double DoubleValue() const
Return the value of this attribute, converted to a double.
@ TIXML_ERROR_PARSING_CDATA
void SetDoubleValue(double _value)
Set the value from a double.
const char * ReadValue(const char *in, TiXmlParsingData *prevData, TiXmlEncoding encoding)
void CopyTo(TiXmlText *target) const
virtual TiXmlNode * Clone() const
Creates a copy of this Unknown and returns it.
TiXmlNode * PreviousSibling(const char *_prev)
std::string Attribute(const std::string &name) const
@ TIXML_ERROR_DOCUMENT_TOP_ONLY
TiXmlHandle FirstChildElement(const std::string &_value) const
TiXmlAttribute * FirstAttribute()
void SetTabSize(int _tabsize)
TiXmlElement * RootElement()
virtual bool Visit(const TiXmlUnknown &)
Visit an unknown node.
TiXmlNode * IterateChildren(const TiXmlNode *previous)
virtual bool Accept(TiXmlVisitor *content) const
TiXmlElement * ToElement() const
virtual const char * Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)
bool LoadFile(TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
void RemoveAttribute(const std::string &name)
TiXmlHandle(TiXmlNode *_node)
Create a handle from any node (at any depth of the tree.) This can be a null pointer.
void CopyTo(TiXmlElement *target) const
const TiXmlNode * Parent() const
virtual bool Visit(const TiXmlDeclaration &)
Visit a declaration.
int IntValue() const
Return the value of this attribute, converted to an integer.
void Clear()
Delete all the children of this node. Does not affect 'this'.
@ TIXML_ERROR_READING_END_TAG
static const char * GetEntity(const char *in, char *value, int *length, TiXmlEncoding encoding)
friend std::istream & operator>>(std::istream &in, TiXmlNode &base)
TiXmlAttribute()
Construct an empty attribute.
bool SaveFile() const
Save a file using the current document value. Returns true if successful.
static const int utf8ByteTable[256]
virtual void Print(FILE *cfile, int depth) const
TiXmlAttribute * LastAttribute()
virtual void StreamIn(std::istream *in, TIXML_STRING *tag)
const TiXmlAttribute * Last() const
const TiXmlElement * FirstChildElement() const
Convenience function to get through elements.
const char * Value() const
const char * Indent()
Query the indention string.
TiXmlNode * IterateChildren(const char *_value, const TiXmlNode *previous)
TiXmlNode * InsertEndChild(const TiXmlNode &addThis)
virtual bool Accept(TiXmlVisitor *visitor) const =0
TiXmlNode * Parent()
One step up the DOM.
void SetAttribute(const std::string &name, const std::string &_value)
static const char * ReadText(const char *in, TIXML_STRING *text, bool ignoreWhiteSpace, const char *endTag, bool ignoreCase, TiXmlEncoding encoding)
TiXmlNode * ReplaceChild(TiXmlNode *replaceThis, const TiXmlNode &withThis)
void * userData
Field containing a generic user pointer.
const TIXML_STRING & NameTStr() const
bool LoadFile(const std::string &filename, TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
const TiXmlAttribute * Next() const
Get the next sibling attribute in the DOM. Returns null at end.
virtual const char * Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)
TiXmlHandle Child(const char *value, int index) const
bool RemoveChild(TiXmlNode *removeThis)
Delete a child of this node.
virtual ~TiXmlDeclaration()
TiXmlHandle(const TiXmlHandle &ref)
Copy constructor.
virtual void StreamIn(std::istream *in, TIXML_STRING *tag)
TiXmlElement * FirstChildElement(const char *_value)
virtual bool Visit(const TiXmlDeclaration &declaration)
Visit a declaration.
TiXmlElement * NextSiblingElement()
virtual TiXmlNode * Clone() const
Creates a copy of this Declaration and returns it.
void CopyTo(TiXmlDeclaration *target) const
virtual bool Accept(TiXmlVisitor *content) const
TiXmlElement * FirstChildElement()
const int TIXML_MAJOR_VERSION
TiXmlText & operator=(const TiXmlText &base)
virtual void StreamIn(std::istream *in, TIXML_STRING *tag)
static bool StreamTo(std::istream *in, int character, TIXML_STRING *tag)
T readType(const std::string &str) const
virtual bool Accept(TiXmlVisitor *visitor) const
void CopyTo(TiXmlNode *target) const
std::string to_string(const T &t)
virtual TiXmlNode * Clone() const =0
bool CDATA() const
Queries whether this represents text using a CDATA section.
const std::string & Str()
Return the result.
TiXmlText(const TiXmlText ©)
TiXmlElement & operator=(const TiXmlElement &base)
@ TIXML_ERROR_PARSING_EMPTY
static bool IsWhiteSpace(char c)
void SetIndent(const char *_indent)
void SetDocument(TiXmlDocument *doc)
virtual const char * Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)=0
TiXmlHandle operator=(const TiXmlHandle &ref)
int QueryValueAttribute(const std::string &name, T *outValue) const
const TiXmlNode * PreviousSibling() const
Navigate to a sibling node.
@ TIXML_ERROR_DOCUMENT_EMPTY
TiXmlUnknown(const TiXmlUnknown ©)
@ TIXML_ERROR_PARSING_ELEMENT
void SetLineBreak(const char *_lineBreak)
virtual bool VisitEnter(const TiXmlDocument &)
Visit a document.
TiXmlNode * LastChild()
The last child of this node. Will be null if there are no children.
bool operator>(const TiXmlAttribute &rhs) const
@ TIXML_ERROR_PARSING_COMMENT
static int IsAlpha(unsigned char anyByte, TiXmlEncoding encoding)
static bool IsWhiteSpace(int c)
@ TIXML_ERROR_PARSING_DECLARATION
const TiXmlElement * RootElement() const
static void SetCondenseWhiteSpace(bool condense)
const TiXmlNode * NextSibling() const
Navigate to a sibling node.
virtual bool VisitExit(const TiXmlDocument &)
Visit a document.
virtual void Print(FILE *cfile, int depth) const
TiXmlAttribute * Previous()
TiXmlNode * NextSibling(const char *_next)
virtual void Print(FILE *cfile, int depth) const
const char * CStr()
Return the result.
virtual TiXmlNode * Clone() const
Creates a new Element and returns it - the returned element is a copy.
void SetError(int err, const char *errorLocation, TiXmlParsingData *prevData, TiXmlEncoding encoding)
TiXmlElement * NextSiblingElement(const char *_next)
TiXmlNode * Identify(const char *start, TiXmlEncoding encoding)
TiXmlDocument * GetDocument()
void SetValue(const char *_value)
void SetCDATA(bool _cdata)
Turns on or off a CDATA representation of text.
void SetValue(const std::string &_value)
STL std::string form.
const TiXmlAttribute * First() const
virtual TiXmlNode * Clone() const
[internal use] Creates a new Element and returns it.
void SetAttribute(const std::string &name, int _value)
TiXmlText * ToText() const
TiXmlNode * NextSibling()
void tolower(std::string &str)
virtual void Print(FILE *cfile, int depth) const
TiXmlElement * Element() const
virtual bool VisitEnter(const TiXmlDocument &doc)
Visit a document.
TiXmlDocument()
Create an empty document, that has no name.
@ TIXML_ERROR_OPENING_FILE
const int TIXML_MINOR_VERSION
TiXmlNode * LastChild(const char *_value)
The last child of this node matching 'value'. Will be null if there are no children.
const char * Encoding() const
Encoding. Will return an empty string if none was found.
static const char * ReadName(const char *p, TIXML_STRING *name, TiXmlEncoding encoding)
void Remove(TiXmlAttribute *attribute)
const char * Standalone() const
Is this a standalone document?
const TiXmlAttribute * Previous() const
Get the previous sibling attribute in the DOM. Returns null at beginning.
const TiXmlNode * IterateChildren(const TiXmlNode *previous) const
@ TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME
virtual void StreamIn(std::istream *in, TIXML_STRING *tag)=0