+/*\r
+Original code by Lee Thomason (www.grinninglizard.com)\r
+\r
+This software is provided 'as-is', without any express or implied\r
+warranty. In no event will the authors be held liable for any\r
+damages arising from the use of this software.\r
+\r
+Permission is granted to anyone to use this software for any\r
+purpose, including commercial applications, and to alter it and\r
+redistribute it freely, subject to the following restrictions:\r
+\r
+1. The origin of this software must not be misrepresented; you must\r
+not claim that you wrote the original software. If you use this\r
+software in a product, an acknowledgment in the product documentation\r
+would be appreciated but is not required.\r
+\r
+2. Altered source versions must be plainly marked as such, and\r
+must not be misrepresented as being the original software.\r
+\r
+3. This notice may not be removed or altered from any source\r
+distribution.\r
+*/\r
+\r
+#ifndef TINYXML2_INCLUDED\r
+#define TINYXML2_INCLUDED\r
+\r
+#if defined(ANDROID_NDK) || defined(__BORLANDC__) || defined(__QNXNTO__)\r
+# include <ctype.h>\r
+# include <limits.h>\r
+# include <stdio.h>\r
+# include <stdlib.h>\r
+# include <string.h>\r
+#else\r
+# include <cctype>\r
+# include <climits>\r
+# include <cstdio>\r
+# include <cstdlib>\r
+# include <cstring>\r
+#endif\r
+\r
+/*\r
+ TODO: intern strings instead of allocation.\r
+*/\r
+/*\r
+ gcc:\r
+ g++ -Wall -DDEBUG tinyxml2.cpp xmltest.cpp -o gccxmltest.exe\r
+\r
+ Formatting, Artistic Style:\r
+ AStyle.exe --style=1tbs --indent-switches --break-closing-brackets --indent-preprocessor tinyxml2.cpp tinyxml2.h\r
+*/\r
+\r
+#if defined( _DEBUG ) || defined( DEBUG ) || defined (__DEBUG__)\r
+# ifndef DEBUG\r
+# define DEBUG\r
+# endif\r
+#endif\r
+\r
+#ifdef _MSC_VER\r
+# pragma warning(push)\r
+# pragma warning(disable: 4251)\r
+#endif\r
+\r
+#ifdef _WIN32\r
+# ifdef TINYXML2_EXPORT\r
+# define TINYXML2_LIB __declspec(dllexport)\r
+# elif defined(TINYXML2_IMPORT)\r
+# define TINYXML2_LIB __declspec(dllimport)\r
+# else\r
+# define TINYXML2_LIB\r
+# endif\r
+#else\r
+# define TINYXML2_LIB\r
+#endif\r
+\r
+\r
+#if defined(DEBUG)\r
+# if defined(_MSC_VER)\r
+# // "(void)0," is for suppressing C4127 warning in "assert(false)", "assert(true)" and the like\r
+# define TIXMLASSERT( x ) if ( !((void)0,(x))) { __debugbreak(); }\r
+# elif defined (ANDROID_NDK)\r
+# include <android/log.h>\r
+# define TIXMLASSERT( x ) if ( !(x)) { __android_log_assert( "assert", "grinliz", "ASSERT in '%s' at %d.", __FILE__, __LINE__ ); }\r
+# else\r
+# include <assert.h>\r
+# define TIXMLASSERT assert\r
+# endif\r
+#else\r
+# define TIXMLASSERT( x ) {}\r
+#endif\r
+\r
+\r
+/* Versioning, past 1.0.14:\r
+ http://semver.org/\r
+*/\r
+static const int TIXML2_MAJOR_VERSION = 3;\r
+static const int TIXML2_MINOR_VERSION = 0;\r
+static const int TIXML2_PATCH_VERSION = 0;\r
+\r
+#include <cpPlugins_tinyxml2_Export.h>\r
+#undef TINYXML2_LIB\r
+#define TINYXML2_LIB cpPlugins_tinyxml2_EXPORT\r
+\r
+namespace tinyxml2\r
+{\r
+class XMLDocument;\r
+class XMLElement;\r
+class XMLAttribute;\r
+class XMLComment;\r
+class XMLText;\r
+class XMLDeclaration;\r
+class XMLUnknown;\r
+class XMLPrinter;\r
+\r
+/*\r
+ A class that wraps strings. Normally stores the start and end\r
+ pointers into the XML file itself, and will apply normalization\r
+ and entity translation if actually read. Can also store (and memory\r
+ manage) a traditional char[]\r
+*/\r
+class StrPair\r
+{\r
+public:\r
+ enum {\r
+ NEEDS_ENTITY_PROCESSING = 0x01,\r
+ NEEDS_NEWLINE_NORMALIZATION = 0x02,\r
+ NEEDS_WHITESPACE_COLLAPSING = 0x04,\r
+\r
+ TEXT_ELEMENT = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION,\r
+ TEXT_ELEMENT_LEAVE_ENTITIES = NEEDS_NEWLINE_NORMALIZATION,\r
+ ATTRIBUTE_NAME = 0,\r
+ ATTRIBUTE_VALUE = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION,\r
+ ATTRIBUTE_VALUE_LEAVE_ENTITIES = NEEDS_NEWLINE_NORMALIZATION,\r
+ COMMENT = NEEDS_NEWLINE_NORMALIZATION\r
+ };\r
+\r
+ StrPair() : _flags( 0 ), _start( 0 ), _end( 0 ) {}\r
+ ~StrPair();\r
+\r
+ void Set( char* start, char* end, int flags ) {\r
+ Reset();\r
+ _start = start;\r
+ _end = end;\r
+ _flags = flags | NEEDS_FLUSH;\r
+ }\r
+\r
+ const char* GetStr();\r
+\r
+ bool Empty() const {\r
+ return _start == _end;\r
+ }\r
+\r
+ void SetInternedStr( const char* str ) {\r
+ Reset();\r
+ _start = const_cast<char*>(str);\r
+ }\r
+\r
+ void SetStr( const char* str, int flags=0 );\r
+\r
+ char* ParseText( char* in, const char* endTag, int strFlags );\r
+ char* ParseName( char* in );\r
+\r
+ void TransferTo( StrPair* other );\r
+\r
+private:\r
+ void Reset();\r
+ void CollapseWhitespace();\r
+\r
+ enum {\r
+ NEEDS_FLUSH = 0x100,\r
+ NEEDS_DELETE = 0x200\r
+ };\r
+\r
+ int _flags;\r
+ char* _start;\r
+ char* _end;\r
+\r
+ StrPair( const StrPair& other ); // not supported\r
+ void operator=( StrPair& other ); // not supported, use TransferTo()\r
+};\r
+\r
+\r
+/*\r
+ A dynamic array of Plain Old Data. Doesn't support constructors, etc.\r
+ Has a small initial memory pool, so that low or no usage will not\r
+ cause a call to new/delete\r
+*/\r
+template <class T, int INITIAL_SIZE>\r
+class DynArray\r
+{\r
+public:\r
+ DynArray() {\r
+ _mem = _pool;\r
+ _allocated = INITIAL_SIZE;\r
+ _size = 0;\r
+ }\r
+\r
+ ~DynArray() {\r
+ if ( _mem != _pool ) {\r
+ delete [] _mem;\r
+ }\r
+ }\r
+\r
+ void Clear() {\r
+ _size = 0;\r
+ }\r
+\r
+ void Push( T t ) {\r
+ TIXMLASSERT( _size < INT_MAX );\r
+ EnsureCapacity( _size+1 );\r
+ _mem[_size++] = t;\r
+ }\r
+\r
+ T* PushArr( int count ) {\r
+ TIXMLASSERT( count >= 0 );\r
+ TIXMLASSERT( _size <= INT_MAX - count );\r
+ EnsureCapacity( _size+count );\r
+ T* ret = &_mem[_size];\r
+ _size += count;\r
+ return ret;\r
+ }\r
+\r
+ T Pop() {\r
+ TIXMLASSERT( _size > 0 );\r
+ return _mem[--_size];\r
+ }\r
+\r
+ void PopArr( int count ) {\r
+ TIXMLASSERT( _size >= count );\r
+ _size -= count;\r
+ }\r
+\r
+ bool Empty() const {\r
+ return _size == 0;\r
+ }\r
+\r
+ T& operator[](int i) {\r
+ TIXMLASSERT( i>= 0 && i < _size );\r
+ return _mem[i];\r
+ }\r
+\r
+ const T& operator[](int i) const {\r
+ TIXMLASSERT( i>= 0 && i < _size );\r
+ return _mem[i];\r
+ }\r
+\r
+ const T& PeekTop() const {\r
+ TIXMLASSERT( _size > 0 );\r
+ return _mem[ _size - 1];\r
+ }\r
+\r
+ int Size() const {\r
+ TIXMLASSERT( _size >= 0 );\r
+ return _size;\r
+ }\r
+\r
+ int Capacity() const {\r
+ TIXMLASSERT( _allocated >= INITIAL_SIZE );\r
+ return _allocated;\r
+ }\r
+\r
+ const T* Mem() const {\r
+ TIXMLASSERT( _mem );\r
+ return _mem;\r
+ }\r
+\r
+ T* Mem() {\r
+ TIXMLASSERT( _mem );\r
+ return _mem;\r
+ }\r
+\r
+private:\r
+ DynArray( const DynArray& ); // not supported\r
+ void operator=( const DynArray& ); // not supported\r
+\r
+ void EnsureCapacity( int cap ) {\r
+ TIXMLASSERT( cap > 0 );\r
+ if ( cap > _allocated ) {\r
+ TIXMLASSERT( cap <= INT_MAX / 2 );\r
+ int newAllocated = cap * 2;\r
+ T* newMem = new T[newAllocated];\r
+ memcpy( newMem, _mem, sizeof(T)*_size ); // warning: not using constructors, only works for PODs\r
+ if ( _mem != _pool ) {\r
+ delete [] _mem;\r
+ }\r
+ _mem = newMem;\r
+ _allocated = newAllocated;\r
+ }\r
+ }\r
+\r
+ T* _mem;\r
+ T _pool[INITIAL_SIZE];\r
+ int _allocated; // objects allocated\r
+ int _size; // number objects in use\r
+};\r
+\r
+\r
+/*\r
+ Parent virtual class of a pool for fast allocation\r
+ and deallocation of objects.\r
+*/\r
+class MemPool\r
+{\r
+public:\r
+ MemPool() {}\r
+ virtual ~MemPool() {}\r
+\r
+ virtual int ItemSize() const = 0;\r
+ virtual void* Alloc() = 0;\r
+ virtual void Free( void* ) = 0;\r
+ virtual void SetTracked() = 0;\r
+ virtual void Clear() = 0;\r
+};\r
+\r
+\r
+/*\r
+ Template child class to create pools of the correct type.\r
+*/\r
+template< int SIZE >\r
+class MemPoolT : public MemPool\r
+{\r
+public:\r
+ MemPoolT() : _root(0), _currentAllocs(0), _nAllocs(0), _maxAllocs(0), _nUntracked(0) {}\r
+ ~MemPoolT() {\r
+ Clear();\r
+ }\r
+ \r
+ void Clear() {\r
+ // Delete the blocks.\r
+ while( !_blockPtrs.Empty()) {\r
+ Block* b = _blockPtrs.Pop();\r
+ delete b;\r
+ }\r
+ _root = 0;\r
+ _currentAllocs = 0;\r
+ _nAllocs = 0;\r
+ _maxAllocs = 0;\r
+ _nUntracked = 0;\r
+ }\r
+\r
+ virtual int ItemSize() const {\r
+ return SIZE;\r
+ }\r
+ int CurrentAllocs() const {\r
+ return _currentAllocs;\r
+ }\r
+\r
+ virtual void* Alloc() {\r
+ if ( !_root ) {\r
+ // Need a new block.\r
+ Block* block = new Block();\r
+ _blockPtrs.Push( block );\r
+\r
+ for( int i=0; i<COUNT-1; ++i ) {\r
+ block->chunk[i].next = &block->chunk[i+1];\r
+ }\r
+ block->chunk[COUNT-1].next = 0;\r
+ _root = block->chunk;\r
+ }\r
+ void* result = _root;\r
+ _root = _root->next;\r
+\r
+ ++_currentAllocs;\r
+ if ( _currentAllocs > _maxAllocs ) {\r
+ _maxAllocs = _currentAllocs;\r
+ }\r
+ _nAllocs++;\r
+ _nUntracked++;\r
+ return result;\r
+ }\r
+ \r
+ virtual void Free( void* mem ) {\r
+ if ( !mem ) {\r
+ return;\r
+ }\r
+ --_currentAllocs;\r
+ Chunk* chunk = static_cast<Chunk*>( mem );\r
+#ifdef DEBUG\r
+ memset( chunk, 0xfe, sizeof(Chunk) );\r
+#endif\r
+ chunk->next = _root;\r
+ _root = chunk;\r
+ }\r
+ void Trace( const char* name ) {\r
+ printf( "Mempool %s watermark=%d [%dk] current=%d size=%d nAlloc=%d blocks=%d\n",\r
+ name, _maxAllocs, _maxAllocs*SIZE/1024, _currentAllocs, SIZE, _nAllocs, _blockPtrs.Size() );\r
+ }\r
+\r
+ void SetTracked() {\r
+ _nUntracked--;\r
+ }\r
+\r
+ int Untracked() const {\r
+ return _nUntracked;\r
+ }\r
+\r
+ // This number is perf sensitive. 4k seems like a good tradeoff on my machine.\r
+ // The test file is large, 170k.\r
+ // Release: VS2010 gcc(no opt)\r
+ // 1k: 4000\r
+ // 2k: 4000\r
+ // 4k: 3900 21000\r
+ // 16k: 5200\r
+ // 32k: 4300\r
+ // 64k: 4000 21000\r
+ enum { COUNT = (4*1024)/SIZE }; // Some compilers do not accept to use COUNT in private part if COUNT is private\r
+\r
+private:\r
+ MemPoolT( const MemPoolT& ); // not supported\r
+ void operator=( const MemPoolT& ); // not supported\r
+\r
+ union Chunk {\r
+ Chunk* next;\r
+ char mem[SIZE];\r
+ };\r
+ struct Block {\r
+ Chunk chunk[COUNT];\r
+ };\r
+ DynArray< Block*, 10 > _blockPtrs;\r
+ Chunk* _root;\r
+\r
+ int _currentAllocs;\r
+ int _nAllocs;\r
+ int _maxAllocs;\r
+ int _nUntracked;\r
+};\r
+\r
+\r
+\r
+/**\r
+ Implements the interface to the "Visitor pattern" (see the Accept() method.)\r
+ If you call the Accept() method, it requires being passed a XMLVisitor\r
+ class to handle callbacks. For nodes that contain other nodes (Document, Element)\r
+ you will get called with a VisitEnter/VisitExit pair. Nodes that are always leafs\r
+ are simply called with Visit().\r
+\r
+ If you return 'true' from a Visit method, recursive parsing will continue. If you return\r
+ false, <b>no children of this node or its siblings</b> will be visited.\r
+\r
+ All flavors of Visit methods have a default implementation that returns 'true' (continue\r
+ visiting). You need to only override methods that are interesting to you.\r
+\r
+ Generally Accept() is called on the XMLDocument, although all nodes support visiting.\r
+\r
+ You should never change the document from a callback.\r
+\r
+ @sa XMLNode::Accept()\r
+*/\r
+class TINYXML2_LIB XMLVisitor\r
+{\r
+public:\r
+ virtual ~XMLVisitor() {}\r
+\r
+ /// Visit a document.\r
+ virtual bool VisitEnter( const XMLDocument& /*doc*/ ) {\r
+ return true;\r
+ }\r
+ /// Visit a document.\r
+ virtual bool VisitExit( const XMLDocument& /*doc*/ ) {\r
+ return true;\r
+ }\r
+\r
+ /// Visit an element.\r
+ virtual bool VisitEnter( const XMLElement& /*element*/, const XMLAttribute* /*firstAttribute*/ ) {\r
+ return true;\r
+ }\r
+ /// Visit an element.\r
+ virtual bool VisitExit( const XMLElement& /*element*/ ) {\r
+ return true;\r
+ }\r
+\r
+ /// Visit a declaration.\r
+ virtual bool Visit( const XMLDeclaration& /*declaration*/ ) {\r
+ return true;\r
+ }\r
+ /// Visit a text node.\r
+ virtual bool Visit( const XMLText& /*text*/ ) {\r
+ return true;\r
+ }\r
+ /// Visit a comment node.\r
+ virtual bool Visit( const XMLComment& /*comment*/ ) {\r
+ return true;\r
+ }\r
+ /// Visit an unknown node.\r
+ virtual bool Visit( const XMLUnknown& /*unknown*/ ) {\r
+ return true;\r
+ }\r
+};\r
+\r
+// WARNING: must match XMLDocument::_errorNames[]\r
+enum XMLError {\r
+ XML_SUCCESS = 0,\r
+ XML_NO_ERROR = 0,\r
+ XML_NO_ATTRIBUTE,\r
+ XML_WRONG_ATTRIBUTE_TYPE,\r
+ XML_ERROR_FILE_NOT_FOUND,\r
+ XML_ERROR_FILE_COULD_NOT_BE_OPENED,\r
+ XML_ERROR_FILE_READ_ERROR,\r
+ XML_ERROR_ELEMENT_MISMATCH,\r
+ XML_ERROR_PARSING_ELEMENT,\r
+ XML_ERROR_PARSING_ATTRIBUTE,\r
+ XML_ERROR_IDENTIFYING_TAG,\r
+ XML_ERROR_PARSING_TEXT,\r
+ XML_ERROR_PARSING_CDATA,\r
+ XML_ERROR_PARSING_COMMENT,\r
+ XML_ERROR_PARSING_DECLARATION,\r
+ XML_ERROR_PARSING_UNKNOWN,\r
+ XML_ERROR_EMPTY_DOCUMENT,\r
+ XML_ERROR_MISMATCHED_ELEMENT,\r
+ XML_ERROR_PARSING,\r
+ XML_CAN_NOT_CONVERT_TEXT,\r
+ XML_NO_TEXT_NODE,\r
+\r
+ XML_ERROR_COUNT\r
+};\r
+\r
+\r
+/*\r
+ Utility functionality.\r
+*/\r
+class XMLUtil\r
+{\r
+public:\r
+ static const char* SkipWhiteSpace( const char* p ) {\r
+ TIXMLASSERT( p );\r
+ while( IsWhiteSpace(*p) ) {\r
+ ++p;\r
+ }\r
+ TIXMLASSERT( p );\r
+ return p;\r
+ }\r
+ static char* SkipWhiteSpace( char* p ) {\r
+ return const_cast<char*>( SkipWhiteSpace( const_cast<const char*>(p) ) );\r
+ }\r
+\r
+ // Anything in the high order range of UTF-8 is assumed to not be whitespace. This isn't\r
+ // correct, but simple, and usually works.\r
+ static bool IsWhiteSpace( char p ) {\r
+ return !IsUTF8Continuation(p) && isspace( static_cast<unsigned char>(p) );\r
+ }\r
+ \r
+ inline static bool IsNameStartChar( unsigned char ch ) {\r
+ if ( ch >= 128 ) {\r
+ // This is a heuristic guess in attempt to not implement Unicode-aware isalpha()\r
+ return true;\r
+ }\r
+ if ( isalpha( ch ) ) {\r
+ return true;\r
+ }\r
+ return ch == ':' || ch == '_';\r
+ }\r
+ \r
+ inline static bool IsNameChar( unsigned char ch ) {\r
+ return IsNameStartChar( ch )\r
+ || isdigit( ch )\r
+ || ch == '.'\r
+ || ch == '-';\r
+ }\r
+\r
+ inline static bool StringEqual( const char* p, const char* q, int nChar=INT_MAX ) {\r
+ if ( p == q ) {\r
+ return true;\r
+ }\r
+ return strncmp( p, q, nChar ) == 0;\r
+ }\r
+ \r
+ inline static bool IsUTF8Continuation( char p ) {\r
+ return ( p & 0x80 ) != 0;\r
+ }\r
+\r
+ static const char* ReadBOM( const char* p, bool* hasBOM );\r
+ // p is the starting location,\r
+ // the UTF-8 value of the entity will be placed in value, and length filled in.\r
+ static const char* GetCharacterRef( const char* p, char* value, int* length );\r
+ static void ConvertUTF32ToUTF8( unsigned long input, char* output, int* length );\r
+\r
+ // converts primitive types to strings\r
+ static void ToStr( int v, char* buffer, int bufferSize );\r
+ static void ToStr( unsigned v, char* buffer, int bufferSize );\r
+ static void ToStr( bool v, char* buffer, int bufferSize );\r
+ static void ToStr( float v, char* buffer, int bufferSize );\r
+ static void ToStr( double v, char* buffer, int bufferSize );\r
+\r
+ // converts strings to primitive types\r
+ static bool ToInt( const char* str, int* value );\r
+ static bool ToUnsigned( const char* str, unsigned* value );\r
+ static bool ToBool( const char* str, bool* value );\r
+ static bool ToFloat( const char* str, float* value );\r
+ static bool ToDouble( const char* str, double* value );\r
+};\r
+\r
+\r
+/** XMLNode is a base class for every object that is in the\r
+ XML Document Object Model (DOM), except XMLAttributes.\r
+ Nodes have siblings, a parent, and children which can\r
+ be navigated. A node is always in a XMLDocument.\r
+ The type of a XMLNode can be queried, and it can\r
+ be cast to its more defined type.\r
+\r
+ A XMLDocument allocates memory for all its Nodes.\r
+ When the XMLDocument gets deleted, all its Nodes\r
+ will also be deleted.\r
+\r
+ @verbatim\r
+ A Document can contain: Element (container or leaf)\r
+ Comment (leaf)\r
+ Unknown (leaf)\r
+ Declaration( leaf )\r
+\r
+ An Element can contain: Element (container or leaf)\r
+ Text (leaf)\r
+ Attributes (not on tree)\r
+ Comment (leaf)\r
+ Unknown (leaf)\r
+\r
+ @endverbatim\r
+*/\r
+class TINYXML2_LIB XMLNode\r
+{\r
+ friend class XMLDocument;\r
+ friend class XMLElement;\r
+public:\r
+\r
+ /// Get the XMLDocument that owns this XMLNode.\r
+ const XMLDocument* GetDocument() const {\r
+ TIXMLASSERT( _document );\r
+ return _document;\r
+ }\r
+ /// Get the XMLDocument that owns this XMLNode.\r
+ XMLDocument* GetDocument() {\r
+ TIXMLASSERT( _document );\r
+ return _document;\r
+ }\r
+\r
+ /// Safely cast to an Element, or null.\r
+ virtual XMLElement* ToElement() {\r
+ return 0;\r
+ }\r
+ /// Safely cast to Text, or null.\r
+ virtual XMLText* ToText() {\r
+ return 0;\r
+ }\r
+ /// Safely cast to a Comment, or null.\r
+ virtual XMLComment* ToComment() {\r
+ return 0;\r
+ }\r
+ /// Safely cast to a Document, or null.\r
+ virtual XMLDocument* ToDocument() {\r
+ return 0;\r
+ }\r
+ /// Safely cast to a Declaration, or null.\r
+ virtual XMLDeclaration* ToDeclaration() {\r
+ return 0;\r
+ }\r
+ /// Safely cast to an Unknown, or null.\r
+ virtual XMLUnknown* ToUnknown() {\r
+ return 0;\r
+ }\r
+\r
+ virtual const XMLElement* ToElement() const {\r
+ return 0;\r
+ }\r
+ virtual const XMLText* ToText() const {\r
+ return 0;\r
+ }\r
+ virtual const XMLComment* ToComment() const {\r
+ return 0;\r
+ }\r
+ virtual const XMLDocument* ToDocument() const {\r
+ return 0;\r
+ }\r
+ virtual const XMLDeclaration* ToDeclaration() const {\r
+ return 0;\r
+ }\r
+ virtual const XMLUnknown* ToUnknown() const {\r
+ return 0;\r
+ }\r
+\r
+ /** The meaning of 'value' changes for the specific type.\r
+ @verbatim\r
+ Document: empty (NULL is returned, not an empty string)\r
+ Element: name of the element\r
+ Comment: the comment text\r
+ Unknown: the tag contents\r
+ Text: the text string\r
+ @endverbatim\r
+ */\r
+ const char* Value() const;\r
+\r
+ /** Set the Value of an XML node.\r
+ @sa Value()\r
+ */\r
+ void SetValue( const char* val, bool staticMem=false );\r
+\r
+ /// Get the parent of this node on the DOM.\r
+ const XMLNode* Parent() const {\r
+ return _parent;\r
+ }\r
+\r
+ XMLNode* Parent() {\r
+ return _parent;\r
+ }\r
+\r
+ /// Returns true if this node has no children.\r
+ bool NoChildren() const {\r
+ return !_firstChild;\r
+ }\r
+\r
+ /// Get the first child node, or null if none exists.\r
+ const XMLNode* FirstChild() const {\r
+ return _firstChild;\r
+ }\r
+\r
+ XMLNode* FirstChild() {\r
+ return _firstChild;\r
+ }\r
+\r
+ /** Get the first child element, or optionally the first child\r
+ element with the specified name.\r
+ */\r
+ const XMLElement* FirstChildElement( const char* name = 0 ) const;\r
+\r
+ XMLElement* FirstChildElement( const char* name = 0 ) {\r
+ return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->FirstChildElement( name ));\r
+ }\r
+\r
+ /// Get the last child node, or null if none exists.\r
+ const XMLNode* LastChild() const {\r
+ return _lastChild;\r
+ }\r
+\r
+ XMLNode* LastChild() {\r
+ return _lastChild;\r
+ }\r
+\r
+ /** Get the last child element or optionally the last child\r
+ element with the specified name.\r
+ */\r
+ const XMLElement* LastChildElement( const char* name = 0 ) const;\r
+\r
+ XMLElement* LastChildElement( const char* name = 0 ) {\r
+ return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->LastChildElement(name) );\r
+ }\r
+\r
+ /// Get the previous (left) sibling node of this node.\r
+ const XMLNode* PreviousSibling() const {\r
+ return _prev;\r
+ }\r
+\r
+ XMLNode* PreviousSibling() {\r
+ return _prev;\r
+ }\r
+\r
+ /// Get the previous (left) sibling element of this node, with an optionally supplied name.\r
+ const XMLElement* PreviousSiblingElement( const char* name = 0 ) const ;\r
+\r
+ XMLElement* PreviousSiblingElement( const char* name = 0 ) {\r
+ return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->PreviousSiblingElement( name ) );\r
+ }\r
+\r
+ /// Get the next (right) sibling node of this node.\r
+ const XMLNode* NextSibling() const {\r
+ return _next;\r
+ }\r
+\r
+ XMLNode* NextSibling() {\r
+ return _next;\r
+ }\r
+\r
+ /// Get the next (right) sibling element of this node, with an optionally supplied name.\r
+ const XMLElement* NextSiblingElement( const char* name = 0 ) const;\r
+\r
+ XMLElement* NextSiblingElement( const char* name = 0 ) {\r
+ return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->NextSiblingElement( name ) );\r
+ }\r
+\r
+ /**\r
+ Add a child node as the last (right) child.\r
+ If the child node is already part of the document,\r
+ it is moved from its old location to the new location.\r
+ Returns the addThis argument or 0 if the node does not\r
+ belong to the same document.\r
+ */\r
+ XMLNode* InsertEndChild( XMLNode* addThis );\r
+\r
+ XMLNode* LinkEndChild( XMLNode* addThis ) {\r
+ return InsertEndChild( addThis );\r
+ }\r
+ /**\r
+ Add a child node as the first (left) child.\r
+ If the child node is already part of the document,\r
+ it is moved from its old location to the new location.\r
+ Returns the addThis argument or 0 if the node does not\r
+ belong to the same document.\r
+ */\r
+ XMLNode* InsertFirstChild( XMLNode* addThis );\r
+ /**\r
+ Add a node after the specified child node.\r
+ If the child node is already part of the document,\r
+ it is moved from its old location to the new location.\r
+ Returns the addThis argument or 0 if the afterThis node\r
+ is not a child of this node, or if the node does not\r
+ belong to the same document.\r
+ */\r
+ XMLNode* InsertAfterChild( XMLNode* afterThis, XMLNode* addThis );\r
+\r
+ /**\r
+ Delete all the children of this node.\r
+ */\r
+ void DeleteChildren();\r
+\r
+ /**\r
+ Delete a child of this node.\r
+ */\r
+ void DeleteChild( XMLNode* node );\r
+\r
+ /**\r
+ Make a copy of this node, but not its children.\r
+ You may pass in a Document pointer that will be\r
+ the owner of the new Node. If the 'document' is\r
+ null, then the node returned will be allocated\r
+ from the current Document. (this->GetDocument())\r
+\r
+ Note: if called on a XMLDocument, this will return null.\r
+ */\r
+ virtual XMLNode* ShallowClone( XMLDocument* document ) const = 0;\r
+\r
+ /**\r
+ Test if 2 nodes are the same, but don't test children.\r
+ The 2 nodes do not need to be in the same Document.\r
+\r
+ Note: if called on a XMLDocument, this will return false.\r
+ */\r
+ virtual bool ShallowEqual( const XMLNode* compare ) const = 0;\r
+\r
+ /** Accept a hierarchical visit of the nodes in the TinyXML-2 DOM. Every node in the\r
+ XML tree will be conditionally visited and the host will be called back\r
+ via the XMLVisitor interface.\r
+\r
+ This is essentially a SAX interface for TinyXML-2. (Note however it doesn't re-parse\r
+ the XML for the callbacks, so the performance of TinyXML-2 is unchanged by using this\r
+ interface versus any other.)\r
+\r
+ The interface has been based on ideas from:\r
+\r
+ - http://www.saxproject.org/\r
+ - http://c2.com/cgi/wiki?HierarchicalVisitorPattern\r
+\r
+ Which are both good references for "visiting".\r
+\r
+ An example of using Accept():\r
+ @verbatim\r
+ XMLPrinter printer;\r
+ tinyxmlDoc.Accept( &printer );\r
+ const char* xmlcstr = printer.CStr();\r
+ @endverbatim\r
+ */\r
+ virtual bool Accept( XMLVisitor* visitor ) const = 0;\r
+\r
+protected:\r
+ XMLNode( XMLDocument* );\r
+ virtual ~XMLNode();\r
+\r
+ virtual char* ParseDeep( char*, StrPair* );\r
+\r
+ XMLDocument* _document;\r
+ XMLNode* _parent;\r
+ mutable StrPair _value;\r
+\r
+ XMLNode* _firstChild;\r
+ XMLNode* _lastChild;\r
+\r
+ XMLNode* _prev;\r
+ XMLNode* _next;\r
+\r
+private:\r
+ MemPool* _memPool;\r
+ void Unlink( XMLNode* child );\r
+ static void DeleteNode( XMLNode* node );\r
+ void InsertChildPreamble( XMLNode* insertThis ) const;\r
+\r
+ XMLNode( const XMLNode& ); // not supported\r
+ XMLNode& operator=( const XMLNode& ); // not supported\r
+};\r
+\r
+\r
+/** XML text.\r
+\r
+ Note that a text node can have child element nodes, for example:\r
+ @verbatim\r
+ <root>This is <b>bold</b></root>\r
+ @endverbatim\r
+\r
+ A text node can have 2 ways to output the next. "normal" output\r
+ and CDATA. It will default to the mode it was parsed from the XML file and\r
+ you generally want to leave it alone, but you can change the output mode with\r
+ SetCData() and query it with CData().\r
+*/\r
+class TINYXML2_LIB XMLText : public XMLNode\r
+{\r
+ friend class XMLBase;\r
+ friend class XMLDocument;\r
+public:\r
+ virtual bool Accept( XMLVisitor* visitor ) const;\r
+\r
+ virtual XMLText* ToText() {\r
+ return this;\r
+ }\r
+ virtual const XMLText* ToText() const {\r
+ return this;\r
+ }\r
+\r
+ /// Declare whether this should be CDATA or standard text.\r
+ void SetCData( bool isCData ) {\r
+ _isCData = isCData;\r
+ }\r
+ /// Returns true if this is a CDATA text element.\r
+ bool CData() const {\r
+ return _isCData;\r
+ }\r
+\r
+ virtual XMLNode* ShallowClone( XMLDocument* document ) const;\r
+ virtual bool ShallowEqual( const XMLNode* compare ) const;\r
+\r
+protected:\r
+ XMLText( XMLDocument* doc ) : XMLNode( doc ), _isCData( false ) {}\r
+ virtual ~XMLText() {}\r
+\r
+ char* ParseDeep( char*, StrPair* endTag );\r
+\r
+private:\r
+ bool _isCData;\r
+\r
+ XMLText( const XMLText& ); // not supported\r
+ XMLText& operator=( const XMLText& ); // not supported\r
+};\r
+\r
+\r
+/** An XML Comment. */\r
+class TINYXML2_LIB XMLComment : public XMLNode\r
+{\r
+ friend class XMLDocument;\r
+public:\r
+ virtual XMLComment* ToComment() {\r
+ return this;\r
+ }\r
+ virtual const XMLComment* ToComment() const {\r
+ return this;\r
+ }\r
+\r
+ virtual bool Accept( XMLVisitor* visitor ) const;\r
+\r
+ virtual XMLNode* ShallowClone( XMLDocument* document ) const;\r
+ virtual bool ShallowEqual( const XMLNode* compare ) const;\r
+\r
+protected:\r
+ XMLComment( XMLDocument* doc );\r
+ virtual ~XMLComment();\r
+\r
+ char* ParseDeep( char*, StrPair* endTag );\r
+\r
+private:\r
+ XMLComment( const XMLComment& ); // not supported\r
+ XMLComment& operator=( const XMLComment& ); // not supported\r
+};\r
+\r
+\r
+/** In correct XML the declaration is the first entry in the file.\r
+ @verbatim\r
+ <?xml version="1.0" standalone="yes"?>\r
+ @endverbatim\r
+\r
+ TinyXML-2 will happily read or write files without a declaration,\r
+ however.\r
+\r
+ The text of the declaration isn't interpreted. It is parsed\r
+ and written as a string.\r
+*/\r
+class TINYXML2_LIB XMLDeclaration : public XMLNode\r
+{\r
+ friend class XMLDocument;\r
+public:\r
+ virtual XMLDeclaration* ToDeclaration() {\r
+ return this;\r
+ }\r
+ virtual const XMLDeclaration* ToDeclaration() const {\r
+ return this;\r
+ }\r
+\r
+ virtual bool Accept( XMLVisitor* visitor ) const;\r
+\r
+ virtual XMLNode* ShallowClone( XMLDocument* document ) const;\r
+ virtual bool ShallowEqual( const XMLNode* compare ) const;\r
+\r
+protected:\r
+ XMLDeclaration( XMLDocument* doc );\r
+ virtual ~XMLDeclaration();\r
+\r
+ char* ParseDeep( char*, StrPair* endTag );\r
+\r
+private:\r
+ XMLDeclaration( const XMLDeclaration& ); // not supported\r
+ XMLDeclaration& operator=( const XMLDeclaration& ); // not supported\r
+};\r
+\r
+\r
+/** Any tag that TinyXML-2 doesn't recognize is saved as an\r
+ unknown. It is a tag of text, but should not be modified.\r
+ It will be written back to the XML, unchanged, when the file\r
+ is saved.\r
+\r
+ DTD tags get thrown into XMLUnknowns.\r
+*/\r
+class TINYXML2_LIB XMLUnknown : public XMLNode\r
+{\r
+ friend class XMLDocument;\r
+public:\r
+ virtual XMLUnknown* ToUnknown() {\r
+ return this;\r
+ }\r
+ virtual const XMLUnknown* ToUnknown() const {\r
+ return this;\r
+ }\r
+\r
+ virtual bool Accept( XMLVisitor* visitor ) const;\r
+\r
+ virtual XMLNode* ShallowClone( XMLDocument* document ) const;\r
+ virtual bool ShallowEqual( const XMLNode* compare ) const;\r
+\r
+protected:\r
+ XMLUnknown( XMLDocument* doc );\r
+ virtual ~XMLUnknown();\r
+\r
+ char* ParseDeep( char*, StrPair* endTag );\r
+\r
+private:\r
+ XMLUnknown( const XMLUnknown& ); // not supported\r
+ XMLUnknown& operator=( const XMLUnknown& ); // not supported\r
+};\r
+\r
+\r
+\r
+/** An attribute is a name-value pair. Elements have an arbitrary\r
+ number of attributes, each with a unique name.\r
+\r
+ @note The attributes are not XMLNodes. You may only query the\r
+ Next() attribute in a list.\r
+*/\r
+class TINYXML2_LIB XMLAttribute\r
+{\r
+ friend class XMLElement;\r
+public:\r
+ /// The name of the attribute.\r
+ const char* Name() const;\r
+\r
+ /// The value of the attribute.\r
+ const char* Value() const;\r
+\r
+ /// The next attribute in the list.\r
+ const XMLAttribute* Next() const {\r
+ return _next;\r
+ }\r
+\r
+ /** IntValue interprets the attribute as an integer, and returns the value.\r
+ If the value isn't an integer, 0 will be returned. There is no error checking;\r
+ use QueryIntValue() if you need error checking.\r
+ */\r
+ int IntValue() const {\r
+ int i=0;\r
+ QueryIntValue( &i );\r
+ return i;\r
+ }\r
+ /// Query as an unsigned integer. See IntValue()\r
+ unsigned UnsignedValue() const {\r
+ unsigned i=0;\r
+ QueryUnsignedValue( &i );\r
+ return i;\r
+ }\r
+ /// Query as a boolean. See IntValue()\r
+ bool BoolValue() const {\r
+ bool b=false;\r
+ QueryBoolValue( &b );\r
+ return b;\r
+ }\r
+ /// Query as a double. See IntValue()\r
+ double DoubleValue() const {\r
+ double d=0;\r
+ QueryDoubleValue( &d );\r
+ return d;\r
+ }\r
+ /// Query as a float. See IntValue()\r
+ float FloatValue() const {\r
+ float f=0;\r
+ QueryFloatValue( &f );\r
+ return f;\r
+ }\r
+\r
+ /** QueryIntValue interprets the attribute as an integer, and returns the value\r
+ in the provided parameter. The function will return XML_NO_ERROR on success,\r
+ and XML_WRONG_ATTRIBUTE_TYPE if the conversion is not successful.\r
+ */\r
+ XMLError QueryIntValue( int* value ) const;\r
+ /// See QueryIntValue\r
+ XMLError QueryUnsignedValue( unsigned int* value ) const;\r
+ /// See QueryIntValue\r
+ XMLError QueryBoolValue( bool* value ) const;\r
+ /// See QueryIntValue\r
+ XMLError QueryDoubleValue( double* value ) const;\r
+ /// See QueryIntValue\r
+ XMLError QueryFloatValue( float* value ) const;\r
+\r
+ /// Set the attribute to a string value.\r
+ void SetAttribute( const char* value );\r
+ /// Set the attribute to value.\r
+ void SetAttribute( int value );\r
+ /// Set the attribute to value.\r
+ void SetAttribute( unsigned value );\r
+ /// Set the attribute to value.\r
+ void SetAttribute( bool value );\r
+ /// Set the attribute to value.\r
+ void SetAttribute( double value );\r
+ /// Set the attribute to value.\r
+ void SetAttribute( float value );\r
+\r
+private:\r
+ enum { BUF_SIZE = 200 };\r
+\r
+ XMLAttribute() : _next( 0 ), _memPool( 0 ) {}\r
+ virtual ~XMLAttribute() {}\r
+\r
+ XMLAttribute( const XMLAttribute& ); // not supported\r
+ void operator=( const XMLAttribute& ); // not supported\r
+ void SetName( const char* name );\r
+\r
+ char* ParseDeep( char* p, bool processEntities );\r
+\r
+ mutable StrPair _name;\r
+ mutable StrPair _value;\r
+ XMLAttribute* _next;\r
+ MemPool* _memPool;\r
+};\r
+\r
+\r
+/** The element is a container class. It has a value, the element name,\r
+ and can contain other elements, text, comments, and unknowns.\r
+ Elements also contain an arbitrary number of attributes.\r
+*/\r
+class TINYXML2_LIB XMLElement : public XMLNode\r
+{\r
+ friend class XMLBase;\r
+ friend class XMLDocument;\r
+public:\r
+ /// Get the name of an element (which is the Value() of the node.)\r
+ const char* Name() const {\r
+ return Value();\r
+ }\r
+ /// Set the name of the element.\r
+ void SetName( const char* str, bool staticMem=false ) {\r
+ SetValue( str, staticMem );\r
+ }\r
+\r
+ virtual XMLElement* ToElement() {\r
+ return this;\r
+ }\r
+ virtual const XMLElement* ToElement() const {\r
+ return this;\r
+ }\r
+ virtual bool Accept( XMLVisitor* visitor ) const;\r
+\r
+ /** Given an attribute name, Attribute() returns the value\r
+ for the attribute of that name, or null if none\r
+ exists. For example:\r
+\r
+ @verbatim\r
+ const char* value = ele->Attribute( "foo" );\r
+ @endverbatim\r
+\r
+ The 'value' parameter is normally null. However, if specified,\r
+ the attribute will only be returned if the 'name' and 'value'\r
+ match. This allow you to write code:\r
+\r
+ @verbatim\r
+ if ( ele->Attribute( "foo", "bar" ) ) callFooIsBar();\r
+ @endverbatim\r
+\r
+ rather than:\r
+ @verbatim\r
+ if ( ele->Attribute( "foo" ) ) {\r
+ if ( strcmp( ele->Attribute( "foo" ), "bar" ) == 0 ) callFooIsBar();\r
+ }\r
+ @endverbatim\r
+ */\r
+ const char* Attribute( const char* name, const char* value=0 ) const;\r
+\r
+ /** Given an attribute name, IntAttribute() returns the value\r
+ of the attribute interpreted as an integer. 0 will be\r
+ returned if there is an error. For a method with error\r
+ checking, see QueryIntAttribute()\r
+ */\r
+ int IntAttribute( const char* name ) const {\r
+ int i=0;\r
+ QueryIntAttribute( name, &i );\r
+ return i;\r
+ }\r
+ /// See IntAttribute()\r
+ unsigned UnsignedAttribute( const char* name ) const {\r
+ unsigned i=0;\r
+ QueryUnsignedAttribute( name, &i );\r
+ return i;\r
+ }\r
+ /// See IntAttribute()\r
+ bool BoolAttribute( const char* name ) const {\r
+ bool b=false;\r
+ QueryBoolAttribute( name, &b );\r
+ return b;\r
+ }\r
+ /// See IntAttribute()\r
+ double DoubleAttribute( const char* name ) const {\r
+ double d=0;\r
+ QueryDoubleAttribute( name, &d );\r
+ return d;\r
+ }\r
+ /// See IntAttribute()\r
+ float FloatAttribute( const char* name ) const {\r
+ float f=0;\r
+ QueryFloatAttribute( name, &f );\r
+ return f;\r
+ }\r
+\r
+ /** Given an attribute name, QueryIntAttribute() returns\r
+ XML_NO_ERROR, XML_WRONG_ATTRIBUTE_TYPE if the conversion\r
+ can't be performed, or XML_NO_ATTRIBUTE if the attribute\r
+ doesn't exist. If successful, the result of the conversion\r
+ will be written to 'value'. If not successful, nothing will\r
+ be written to 'value'. This allows you to provide default\r
+ value:\r
+\r
+ @verbatim\r
+ int value = 10;\r
+ QueryIntAttribute( "foo", &value ); // if "foo" isn't found, value will still be 10\r
+ @endverbatim\r
+ */\r
+ XMLError QueryIntAttribute( const char* name, int* value ) const {\r
+ const XMLAttribute* a = FindAttribute( name );\r
+ if ( !a ) {\r
+ return XML_NO_ATTRIBUTE;\r
+ }\r
+ return a->QueryIntValue( value );\r
+ }\r
+ /// See QueryIntAttribute()\r
+ XMLError QueryUnsignedAttribute( const char* name, unsigned int* value ) const {\r
+ const XMLAttribute* a = FindAttribute( name );\r
+ if ( !a ) {\r
+ return XML_NO_ATTRIBUTE;\r
+ }\r
+ return a->QueryUnsignedValue( value );\r
+ }\r
+ /// See QueryIntAttribute()\r
+ XMLError QueryBoolAttribute( const char* name, bool* value ) const {\r
+ const XMLAttribute* a = FindAttribute( name );\r
+ if ( !a ) {\r
+ return XML_NO_ATTRIBUTE;\r
+ }\r
+ return a->QueryBoolValue( value );\r
+ }\r
+ /// See QueryIntAttribute()\r
+ XMLError QueryDoubleAttribute( const char* name, double* value ) const {\r
+ const XMLAttribute* a = FindAttribute( name );\r
+ if ( !a ) {\r
+ return XML_NO_ATTRIBUTE;\r
+ }\r
+ return a->QueryDoubleValue( value );\r
+ }\r
+ /// See QueryIntAttribute()\r
+ XMLError QueryFloatAttribute( const char* name, float* value ) const {\r
+ const XMLAttribute* a = FindAttribute( name );\r
+ if ( !a ) {\r
+ return XML_NO_ATTRIBUTE;\r
+ }\r
+ return a->QueryFloatValue( value );\r
+ }\r
+\r
+ \r
+ /** Given an attribute name, QueryAttribute() returns\r
+ XML_NO_ERROR, XML_WRONG_ATTRIBUTE_TYPE if the conversion\r
+ can't be performed, or XML_NO_ATTRIBUTE if the attribute\r
+ doesn't exist. It is overloaded for the primitive types,\r
+ and is a generally more convenient replacement of\r
+ QueryIntAttribute() and related functions.\r
+ \r
+ If successful, the result of the conversion\r
+ will be written to 'value'. If not successful, nothing will\r
+ be written to 'value'. This allows you to provide default\r
+ value:\r
+\r
+ @verbatim\r
+ int value = 10;\r
+ QueryAttribute( "foo", &value ); // if "foo" isn't found, value will still be 10\r
+ @endverbatim\r
+ */\r
+ int QueryAttribute( const char* name, int* value ) const {\r
+ return QueryIntAttribute( name, value );\r
+ }\r
+\r
+ int QueryAttribute( const char* name, unsigned int* value ) const {\r
+ return QueryUnsignedAttribute( name, value );\r
+ }\r
+\r
+ int QueryAttribute( const char* name, bool* value ) const {\r
+ return QueryBoolAttribute( name, value );\r
+ }\r
+\r
+ int QueryAttribute( const char* name, double* value ) const {\r
+ return QueryDoubleAttribute( name, value );\r
+ }\r
+\r
+ int QueryAttribute( const char* name, float* value ) const {\r
+ return QueryFloatAttribute( name, value );\r
+ }\r
+\r
+ /// Sets the named attribute to value.\r
+ void SetAttribute( const char* name, const char* value ) {\r
+ XMLAttribute* a = FindOrCreateAttribute( name );\r
+ a->SetAttribute( value );\r
+ }\r
+ /// Sets the named attribute to value.\r
+ void SetAttribute( const char* name, int value ) {\r
+ XMLAttribute* a = FindOrCreateAttribute( name );\r
+ a->SetAttribute( value );\r
+ }\r
+ /// Sets the named attribute to value.\r
+ void SetAttribute( const char* name, unsigned value ) {\r
+ XMLAttribute* a = FindOrCreateAttribute( name );\r
+ a->SetAttribute( value );\r
+ }\r
+ /// Sets the named attribute to value.\r
+ void SetAttribute( const char* name, bool value ) {\r
+ XMLAttribute* a = FindOrCreateAttribute( name );\r
+ a->SetAttribute( value );\r
+ }\r
+ /// Sets the named attribute to value.\r
+ void SetAttribute( const char* name, double value ) {\r
+ XMLAttribute* a = FindOrCreateAttribute( name );\r
+ a->SetAttribute( value );\r
+ }\r
+ /// Sets the named attribute to value.\r
+ void SetAttribute( const char* name, float value ) {\r
+ XMLAttribute* a = FindOrCreateAttribute( name );\r
+ a->SetAttribute( value );\r
+ }\r
+\r
+ /**\r
+ Delete an attribute.\r
+ */\r
+ void DeleteAttribute( const char* name );\r
+\r
+ /// Return the first attribute in the list.\r
+ const XMLAttribute* FirstAttribute() const {\r
+ return _rootAttribute;\r
+ }\r
+ /// Query a specific attribute in the list.\r
+ const XMLAttribute* FindAttribute( const char* name ) const;\r
+\r
+ /** Convenience function for easy access to the text inside an element. Although easy\r
+ and concise, GetText() is limited compared to getting the XMLText child\r
+ and accessing it directly.\r
+\r
+ If the first child of 'this' is a XMLText, the GetText()\r
+ returns the character string of the Text node, else null is returned.\r
+\r
+ This is a convenient method for getting the text of simple contained text:\r
+ @verbatim\r
+ <foo>This is text</foo>\r
+ const char* str = fooElement->GetText();\r
+ @endverbatim\r
+\r
+ 'str' will be a pointer to "This is text".\r
+\r
+ Note that this function can be misleading. If the element foo was created from\r
+ this XML:\r
+ @verbatim\r
+ <foo><b>This is text</b></foo>\r
+ @endverbatim\r
+\r
+ then the value of str would be null. The first child node isn't a text node, it is\r
+ another element. From this XML:\r
+ @verbatim\r
+ <foo>This is <b>text</b></foo>\r
+ @endverbatim\r
+ GetText() will return "This is ".\r
+ */\r
+ const char* GetText() const;\r
+\r
+ /** Convenience function for easy access to the text inside an element. Although easy\r
+ and concise, SetText() is limited compared to creating an XMLText child\r
+ and mutating it directly.\r
+\r
+ If the first child of 'this' is a XMLText, SetText() sets its value to\r
+ the given string, otherwise it will create a first child that is an XMLText.\r
+\r
+ This is a convenient method for setting the text of simple contained text:\r
+ @verbatim\r
+ <foo>This is text</foo>\r
+ fooElement->SetText( "Hullaballoo!" );\r
+ <foo>Hullaballoo!</foo>\r
+ @endverbatim\r
+\r
+ Note that this function can be misleading. If the element foo was created from\r
+ this XML:\r
+ @verbatim\r
+ <foo><b>This is text</b></foo>\r
+ @endverbatim\r
+\r
+ then it will not change "This is text", but rather prefix it with a text element:\r
+ @verbatim\r
+ <foo>Hullaballoo!<b>This is text</b></foo>\r
+ @endverbatim\r
+ \r
+ For this XML:\r
+ @verbatim\r
+ <foo />\r
+ @endverbatim\r
+ SetText() will generate\r
+ @verbatim\r
+ <foo>Hullaballoo!</foo>\r
+ @endverbatim\r
+ */\r
+ void SetText( const char* inText );\r
+ /// Convenience method for setting text inside an element. See SetText() for important limitations.\r
+ void SetText( int value );\r
+ /// Convenience method for setting text inside an element. See SetText() for important limitations.\r
+ void SetText( unsigned value ); \r
+ /// Convenience method for setting text inside an element. See SetText() for important limitations.\r
+ void SetText( bool value ); \r
+ /// Convenience method for setting text inside an element. See SetText() for important limitations.\r
+ void SetText( double value ); \r
+ /// Convenience method for setting text inside an element. See SetText() for important limitations.\r
+ void SetText( float value ); \r
+\r
+ /**\r
+ Convenience method to query the value of a child text node. This is probably best\r
+ shown by example. Given you have a document is this form:\r
+ @verbatim\r
+ <point>\r
+ <x>1</x>\r
+ <y>1.4</y>\r
+ </point>\r
+ @endverbatim\r
+\r
+ The QueryIntText() and similar functions provide a safe and easier way to get to the\r
+ "value" of x and y.\r
+\r
+ @verbatim\r
+ int x = 0;\r
+ float y = 0; // types of x and y are contrived for example\r
+ const XMLElement* xElement = pointElement->FirstChildElement( "x" );\r
+ const XMLElement* yElement = pointElement->FirstChildElement( "y" );\r
+ xElement->QueryIntText( &x );\r
+ yElement->QueryFloatText( &y );\r
+ @endverbatim\r
+\r
+ @returns XML_SUCCESS (0) on success, XML_CAN_NOT_CONVERT_TEXT if the text cannot be converted\r
+ to the requested type, and XML_NO_TEXT_NODE if there is no child text to query.\r
+\r
+ */\r
+ XMLError QueryIntText( int* ival ) const;\r
+ /// See QueryIntText()\r
+ XMLError QueryUnsignedText( unsigned* uval ) const;\r
+ /// See QueryIntText()\r
+ XMLError QueryBoolText( bool* bval ) const;\r
+ /// See QueryIntText()\r
+ XMLError QueryDoubleText( double* dval ) const;\r
+ /// See QueryIntText()\r
+ XMLError QueryFloatText( float* fval ) const;\r
+\r
+ // internal:\r
+ enum {\r
+ OPEN, // <foo>\r
+ CLOSED, // <foo/>\r
+ CLOSING // </foo>\r
+ };\r
+ int ClosingType() const {\r
+ return _closingType;\r
+ }\r
+ virtual XMLNode* ShallowClone( XMLDocument* document ) const;\r
+ virtual bool ShallowEqual( const XMLNode* compare ) const;\r
+\r
+protected:\r
+ char* ParseDeep( char* p, StrPair* endTag );\r
+\r
+private:\r
+ XMLElement( XMLDocument* doc );\r
+ virtual ~XMLElement();\r
+ XMLElement( const XMLElement& ); // not supported\r
+ void operator=( const XMLElement& ); // not supported\r
+\r
+ XMLAttribute* FindAttribute( const char* name ) {\r
+ return const_cast<XMLAttribute*>(const_cast<const XMLElement*>(this)->FindAttribute( name ));\r
+ }\r
+ XMLAttribute* FindOrCreateAttribute( const char* name );\r
+ //void LinkAttribute( XMLAttribute* attrib );\r
+ char* ParseAttributes( char* p );\r
+ static void DeleteAttribute( XMLAttribute* attribute );\r
+\r
+ enum { BUF_SIZE = 200 };\r
+ int _closingType;\r
+ // The attribute list is ordered; there is no 'lastAttribute'\r
+ // because the list needs to be scanned for dupes before adding\r
+ // a new attribute.\r
+ XMLAttribute* _rootAttribute;\r
+};\r
+\r
+\r
+enum Whitespace {\r
+ PRESERVE_WHITESPACE,\r
+ COLLAPSE_WHITESPACE\r
+};\r
+\r
+\r
+/** A Document binds together all the functionality.\r
+ It can be saved, loaded, and printed to the screen.\r
+ All Nodes are connected and allocated to a Document.\r
+ If the Document is deleted, all its Nodes are also deleted.\r
+*/\r
+class TINYXML2_LIB XMLDocument : public XMLNode\r
+{\r
+ friend class XMLElement;\r
+public:\r
+ /// constructor\r
+ XMLDocument( bool processEntities = true, Whitespace = PRESERVE_WHITESPACE );\r
+ ~XMLDocument();\r
+\r
+ virtual XMLDocument* ToDocument() {\r
+ TIXMLASSERT( this == _document );\r
+ return this;\r
+ }\r
+ virtual const XMLDocument* ToDocument() const {\r
+ TIXMLASSERT( this == _document );\r
+ return this;\r
+ }\r
+\r
+ /**\r
+ Parse an XML file from a character string.\r
+ Returns XML_NO_ERROR (0) on success, or\r
+ an errorID.\r
+\r
+ You may optionally pass in the 'nBytes', which is\r
+ the number of bytes which will be parsed. If not\r
+ specified, TinyXML-2 will assume 'xml' points to a\r
+ null terminated string.\r
+ */\r
+ XMLError Parse( const char* xml, size_t nBytes=(size_t)(-1) );\r
+\r
+ /**\r
+ Load an XML file from disk.\r
+ Returns XML_NO_ERROR (0) on success, or\r
+ an errorID.\r
+ */\r
+ XMLError LoadFile( const char* filename );\r
+\r
+ /**\r
+ Load an XML file from disk. You are responsible\r
+ for providing and closing the FILE*. \r
+ \r
+ NOTE: The file should be opened as binary ("rb")\r
+ not text in order for TinyXML-2 to correctly\r
+ do newline normalization.\r
+\r
+ Returns XML_NO_ERROR (0) on success, or\r
+ an errorID.\r
+ */\r
+ XMLError LoadFile( FILE* );\r
+\r
+ /**\r
+ Save the XML file to disk.\r
+ Returns XML_NO_ERROR (0) on success, or\r
+ an errorID.\r
+ */\r
+ XMLError SaveFile( const char* filename, bool compact = false );\r
+\r
+ /**\r
+ Save the XML file to disk. You are responsible\r
+ for providing and closing the FILE*.\r
+\r
+ Returns XML_NO_ERROR (0) on success, or\r
+ an errorID.\r
+ */\r
+ XMLError SaveFile( FILE* fp, bool compact = false );\r
+\r
+ bool ProcessEntities() const {\r
+ return _processEntities;\r
+ }\r
+ Whitespace WhitespaceMode() const {\r
+ return _whitespace;\r
+ }\r
+\r
+ /**\r
+ Returns true if this document has a leading Byte Order Mark of UTF8.\r
+ */\r
+ bool HasBOM() const {\r
+ return _writeBOM;\r
+ }\r
+ /** Sets whether to write the BOM when writing the file.\r
+ */\r
+ void SetBOM( bool useBOM ) {\r
+ _writeBOM = useBOM;\r
+ }\r
+\r
+ /** Return the root element of DOM. Equivalent to FirstChildElement().\r
+ To get the first node, use FirstChild().\r
+ */\r
+ XMLElement* RootElement() {\r
+ return FirstChildElement();\r
+ }\r
+ const XMLElement* RootElement() const {\r
+ return FirstChildElement();\r
+ }\r
+\r
+ /** Print the Document. If the Printer is not provided, it will\r
+ print to stdout. If you provide Printer, this can print to a file:\r
+ @verbatim\r
+ XMLPrinter printer( fp );\r
+ doc.Print( &printer );\r
+ @endverbatim\r
+\r
+ Or you can use a printer to print to memory:\r
+ @verbatim\r
+ XMLPrinter printer;\r
+ doc.Print( &printer );\r
+ // printer.CStr() has a const char* to the XML\r
+ @endverbatim\r
+ */\r
+ void Print( XMLPrinter* streamer=0 ) const;\r
+ virtual bool Accept( XMLVisitor* visitor ) const;\r
+\r
+ /**\r
+ Create a new Element associated with\r
+ this Document. The memory for the Element\r
+ is managed by the Document.\r
+ */\r
+ XMLElement* NewElement( const char* name );\r
+ /**\r
+ Create a new Comment associated with\r
+ this Document. The memory for the Comment\r
+ is managed by the Document.\r
+ */\r
+ XMLComment* NewComment( const char* comment );\r
+ /**\r
+ Create a new Text associated with\r
+ this Document. The memory for the Text\r
+ is managed by the Document.\r
+ */\r
+ XMLText* NewText( const char* text );\r
+ /**\r
+ Create a new Declaration associated with\r
+ this Document. The memory for the object\r
+ is managed by the Document.\r
+\r
+ If the 'text' param is null, the standard\r
+ declaration is used.:\r
+ @verbatim\r
+ <?xml version="1.0" encoding="UTF-8"?>\r
+ @endverbatim\r
+ */\r
+ XMLDeclaration* NewDeclaration( const char* text=0 );\r
+ /**\r
+ Create a new Unknown associated with\r
+ this Document. The memory for the object\r
+ is managed by the Document.\r
+ */\r
+ XMLUnknown* NewUnknown( const char* text );\r
+\r
+ /**\r
+ Delete a node associated with this document.\r
+ It will be unlinked from the DOM.\r
+ */\r
+ void DeleteNode( XMLNode* node );\r
+\r
+ void SetError( XMLError error, const char* str1, const char* str2 );\r
+\r
+ /// Return true if there was an error parsing the document.\r
+ bool Error() const {\r
+ return _errorID != XML_NO_ERROR;\r
+ }\r
+ /// Return the errorID.\r
+ XMLError ErrorID() const {\r
+ return _errorID;\r
+ }\r
+ const char* ErrorName() const;\r
+\r
+ /// Return a possibly helpful diagnostic location or string.\r
+ const char* GetErrorStr1() const {\r
+ return _errorStr1;\r
+ }\r
+ /// Return a possibly helpful secondary diagnostic location or string.\r
+ const char* GetErrorStr2() const {\r
+ return _errorStr2;\r
+ }\r
+ /// If there is an error, print it to stdout.\r
+ void PrintError() const;\r
+ \r
+ /// Clear the document, resetting it to the initial state.\r
+ void Clear();\r
+\r
+ // internal\r
+ char* Identify( char* p, XMLNode** node );\r
+\r
+ virtual XMLNode* ShallowClone( XMLDocument* /*document*/ ) const {\r
+ return 0;\r
+ }\r
+ virtual bool ShallowEqual( const XMLNode* /*compare*/ ) const {\r
+ return false;\r
+ }\r
+\r
+private:\r
+ XMLDocument( const XMLDocument& ); // not supported\r
+ void operator=( const XMLDocument& ); // not supported\r
+\r
+ bool _writeBOM;\r
+ bool _processEntities;\r
+ XMLError _errorID;\r
+ Whitespace _whitespace;\r
+ const char* _errorStr1;\r
+ const char* _errorStr2;\r
+ char* _charBuffer;\r
+\r
+ MemPoolT< sizeof(XMLElement) > _elementPool;\r
+ MemPoolT< sizeof(XMLAttribute) > _attributePool;\r
+ MemPoolT< sizeof(XMLText) > _textPool;\r
+ MemPoolT< sizeof(XMLComment) > _commentPool;\r
+\r
+ static const char* _errorNames[XML_ERROR_COUNT];\r
+\r
+ void Parse();\r
+};\r
+\r
+\r
+/**\r
+ A XMLHandle is a class that wraps a node pointer with null checks; this is\r
+ an incredibly useful thing. Note that XMLHandle is not part of the TinyXML-2\r
+ DOM structure. It is a separate utility class.\r
+\r
+ Take an example:\r
+ @verbatim\r
+ <Document>\r
+ <Element attributeA = "valueA">\r
+ <Child attributeB = "value1" />\r
+ <Child attributeB = "value2" />\r
+ </Element>\r
+ </Document>\r
+ @endverbatim\r
+\r
+ Assuming you want the value of "attributeB" in the 2nd "Child" element, it's very\r
+ easy to write a *lot* of code that looks like:\r
+\r
+ @verbatim\r
+ XMLElement* root = document.FirstChildElement( "Document" );\r
+ if ( root )\r
+ {\r
+ XMLElement* element = root->FirstChildElement( "Element" );\r
+ if ( element )\r
+ {\r
+ XMLElement* child = element->FirstChildElement( "Child" );\r
+ if ( child )\r
+ {\r
+ XMLElement* child2 = child->NextSiblingElement( "Child" );\r
+ if ( child2 )\r
+ {\r
+ // Finally do something useful.\r
+ @endverbatim\r
+\r
+ And that doesn't even cover "else" cases. XMLHandle addresses the verbosity\r
+ of such code. A XMLHandle checks for null pointers so it is perfectly safe\r
+ and correct to use:\r
+\r
+ @verbatim\r
+ XMLHandle docHandle( &document );\r
+ XMLElement* child2 = docHandle.FirstChildElement( "Document" ).FirstChildElement( "Element" ).FirstChildElement().NextSiblingElement();\r
+ if ( child2 )\r
+ {\r
+ // do something useful\r
+ @endverbatim\r
+\r
+ Which is MUCH more concise and useful.\r
+\r
+ It is also safe to copy handles - internally they are nothing more than node pointers.\r
+ @verbatim\r
+ XMLHandle handleCopy = handle;\r
+ @endverbatim\r
+\r
+ See also XMLConstHandle, which is the same as XMLHandle, but operates on const objects.\r
+*/\r
+class TINYXML2_LIB XMLHandle\r
+{\r
+public:\r
+ /// Create a handle from any node (at any depth of the tree.) This can be a null pointer.\r
+ XMLHandle( XMLNode* node ) {\r
+ _node = node;\r
+ }\r
+ /// Create a handle from a node.\r
+ XMLHandle( XMLNode& node ) {\r
+ _node = &node;\r
+ }\r
+ /// Copy constructor\r
+ XMLHandle( const XMLHandle& ref ) {\r
+ _node = ref._node;\r
+ }\r
+ /// Assignment\r
+ XMLHandle& operator=( const XMLHandle& ref ) {\r
+ _node = ref._node;\r
+ return *this;\r
+ }\r
+\r
+ /// Get the first child of this handle.\r
+ XMLHandle FirstChild() {\r
+ return XMLHandle( _node ? _node->FirstChild() : 0 );\r
+ }\r
+ /// Get the first child element of this handle.\r
+ XMLHandle FirstChildElement( const char* name = 0 ) {\r
+ return XMLHandle( _node ? _node->FirstChildElement( name ) : 0 );\r
+ }\r
+ /// Get the last child of this handle.\r
+ XMLHandle LastChild() {\r
+ return XMLHandle( _node ? _node->LastChild() : 0 );\r
+ }\r
+ /// Get the last child element of this handle.\r
+ XMLHandle LastChildElement( const char* name = 0 ) {\r
+ return XMLHandle( _node ? _node->LastChildElement( name ) : 0 );\r
+ }\r
+ /// Get the previous sibling of this handle.\r
+ XMLHandle PreviousSibling() {\r
+ return XMLHandle( _node ? _node->PreviousSibling() : 0 );\r
+ }\r
+ /// Get the previous sibling element of this handle.\r
+ XMLHandle PreviousSiblingElement( const char* name = 0 ) {\r
+ return XMLHandle( _node ? _node->PreviousSiblingElement( name ) : 0 );\r
+ }\r
+ /// Get the next sibling of this handle.\r
+ XMLHandle NextSibling() {\r
+ return XMLHandle( _node ? _node->NextSibling() : 0 );\r
+ }\r
+ /// Get the next sibling element of this handle.\r
+ XMLHandle NextSiblingElement( const char* name = 0 ) {\r
+ return XMLHandle( _node ? _node->NextSiblingElement( name ) : 0 );\r
+ }\r
+\r
+ /// Safe cast to XMLNode. This can return null.\r
+ XMLNode* ToNode() {\r
+ return _node;\r
+ }\r
+ /// Safe cast to XMLElement. This can return null.\r
+ XMLElement* ToElement() {\r
+ return ( ( _node == 0 ) ? 0 : _node->ToElement() );\r
+ }\r
+ /// Safe cast to XMLText. This can return null.\r
+ XMLText* ToText() {\r
+ return ( ( _node == 0 ) ? 0 : _node->ToText() );\r
+ }\r
+ /// Safe cast to XMLUnknown. This can return null.\r
+ XMLUnknown* ToUnknown() {\r
+ return ( ( _node == 0 ) ? 0 : _node->ToUnknown() );\r
+ }\r
+ /// Safe cast to XMLDeclaration. This can return null.\r
+ XMLDeclaration* ToDeclaration() {\r
+ return ( ( _node == 0 ) ? 0 : _node->ToDeclaration() );\r
+ }\r
+\r
+private:\r
+ XMLNode* _node;\r
+};\r
+\r
+\r
+/**\r
+ A variant of the XMLHandle class for working with const XMLNodes and Documents. It is the\r
+ same in all regards, except for the 'const' qualifiers. See XMLHandle for API.\r
+*/\r
+class TINYXML2_LIB XMLConstHandle\r
+{\r
+public:\r
+ XMLConstHandle( const XMLNode* node ) {\r
+ _node = node;\r
+ }\r
+ XMLConstHandle( const XMLNode& node ) {\r
+ _node = &node;\r
+ }\r
+ XMLConstHandle( const XMLConstHandle& ref ) {\r
+ _node = ref._node;\r
+ }\r
+\r
+ XMLConstHandle& operator=( const XMLConstHandle& ref ) {\r
+ _node = ref._node;\r
+ return *this;\r
+ }\r
+\r
+ const XMLConstHandle FirstChild() const {\r
+ return XMLConstHandle( _node ? _node->FirstChild() : 0 );\r
+ }\r
+ const XMLConstHandle FirstChildElement( const char* name = 0 ) const {\r
+ return XMLConstHandle( _node ? _node->FirstChildElement( name ) : 0 );\r
+ }\r
+ const XMLConstHandle LastChild() const {\r
+ return XMLConstHandle( _node ? _node->LastChild() : 0 );\r
+ }\r
+ const XMLConstHandle LastChildElement( const char* name = 0 ) const {\r
+ return XMLConstHandle( _node ? _node->LastChildElement( name ) : 0 );\r
+ }\r
+ const XMLConstHandle PreviousSibling() const {\r
+ return XMLConstHandle( _node ? _node->PreviousSibling() : 0 );\r
+ }\r
+ const XMLConstHandle PreviousSiblingElement( const char* name = 0 ) const {\r
+ return XMLConstHandle( _node ? _node->PreviousSiblingElement( name ) : 0 );\r
+ }\r
+ const XMLConstHandle NextSibling() const {\r
+ return XMLConstHandle( _node ? _node->NextSibling() : 0 );\r
+ }\r
+ const XMLConstHandle NextSiblingElement( const char* name = 0 ) const {\r
+ return XMLConstHandle( _node ? _node->NextSiblingElement( name ) : 0 );\r
+ }\r
+\r
+\r
+ const XMLNode* ToNode() const {\r
+ return _node;\r
+ }\r
+ const XMLElement* ToElement() const {\r
+ return ( ( _node == 0 ) ? 0 : _node->ToElement() );\r
+ }\r
+ const XMLText* ToText() const {\r
+ return ( ( _node == 0 ) ? 0 : _node->ToText() );\r
+ }\r
+ const XMLUnknown* ToUnknown() const {\r
+ return ( ( _node == 0 ) ? 0 : _node->ToUnknown() );\r
+ }\r
+ const XMLDeclaration* ToDeclaration() const {\r
+ return ( ( _node == 0 ) ? 0 : _node->ToDeclaration() );\r
+ }\r
+\r
+private:\r
+ const XMLNode* _node;\r
+};\r
+\r
+\r
+/**\r
+ Printing functionality. The XMLPrinter gives you more\r
+ options than the XMLDocument::Print() method.\r
+\r
+ It can:\r
+ -# Print to memory.\r
+ -# Print to a file you provide.\r
+ -# Print XML without a XMLDocument.\r
+\r
+ Print to Memory\r
+\r
+ @verbatim\r
+ XMLPrinter printer;\r
+ doc.Print( &printer );\r
+ SomeFunction( printer.CStr() );\r
+ @endverbatim\r
+\r
+ Print to a File\r
+\r
+ You provide the file pointer.\r
+ @verbatim\r
+ XMLPrinter printer( fp );\r
+ doc.Print( &printer );\r
+ @endverbatim\r
+\r
+ Print without a XMLDocument\r
+\r
+ When loading, an XML parser is very useful. However, sometimes\r
+ when saving, it just gets in the way. The code is often set up\r
+ for streaming, and constructing the DOM is just overhead.\r
+\r
+ The Printer supports the streaming case. The following code\r
+ prints out a trivially simple XML file without ever creating\r
+ an XML document.\r
+\r
+ @verbatim\r
+ XMLPrinter printer( fp );\r
+ printer.OpenElement( "foo" );\r
+ printer.PushAttribute( "foo", "bar" );\r
+ printer.CloseElement();\r
+ @endverbatim\r
+*/\r
+class TINYXML2_LIB XMLPrinter : public XMLVisitor\r
+{\r
+public:\r
+ /** Construct the printer. If the FILE* is specified,\r
+ this will print to the FILE. Else it will print\r
+ to memory, and the result is available in CStr().\r
+ If 'compact' is set to true, then output is created\r
+ with only required whitespace and newlines.\r
+ */\r
+ XMLPrinter( FILE* file=0, bool compact = false, int depth = 0 );\r
+ virtual ~XMLPrinter() {}\r
+\r
+ /** If streaming, write the BOM and declaration. */\r
+ void PushHeader( bool writeBOM, bool writeDeclaration );\r
+ /** If streaming, start writing an element.\r
+ The element must be closed with CloseElement()\r
+ */\r
+ void OpenElement( const char* name, bool compactMode=false );\r
+ /// If streaming, add an attribute to an open element.\r
+ void PushAttribute( const char* name, const char* value );\r
+ void PushAttribute( const char* name, int value );\r
+ void PushAttribute( const char* name, unsigned value );\r
+ void PushAttribute( const char* name, bool value );\r
+ void PushAttribute( const char* name, double value );\r
+ /// If streaming, close the Element.\r
+ virtual void CloseElement( bool compactMode=false );\r
+\r
+ /// Add a text node.\r
+ void PushText( const char* text, bool cdata=false );\r
+ /// Add a text node from an integer.\r
+ void PushText( int value );\r
+ /// Add a text node from an unsigned.\r
+ void PushText( unsigned value );\r
+ /// Add a text node from a bool.\r
+ void PushText( bool value );\r
+ /// Add a text node from a float.\r
+ void PushText( float value );\r
+ /// Add a text node from a double.\r
+ void PushText( double value );\r
+\r
+ /// Add a comment\r
+ void PushComment( const char* comment );\r
+\r
+ void PushDeclaration( const char* value );\r
+ void PushUnknown( const char* value );\r
+\r
+ virtual bool VisitEnter( const XMLDocument& /*doc*/ );\r
+ virtual bool VisitExit( const XMLDocument& /*doc*/ ) {\r
+ return true;\r
+ }\r
+\r
+ virtual bool VisitEnter( const XMLElement& element, const XMLAttribute* attribute );\r
+ virtual bool VisitExit( const XMLElement& element );\r
+\r
+ virtual bool Visit( const XMLText& text );\r
+ virtual bool Visit( const XMLComment& comment );\r
+ virtual bool Visit( const XMLDeclaration& declaration );\r
+ virtual bool Visit( const XMLUnknown& unknown );\r
+\r
+ /**\r
+ If in print to memory mode, return a pointer to\r
+ the XML file in memory.\r
+ */\r
+ const char* CStr() const {\r
+ return _buffer.Mem();\r
+ }\r
+ /**\r
+ If in print to memory mode, return the size\r
+ of the XML file in memory. (Note the size returned\r
+ includes the terminating null.)\r
+ */\r
+ int CStrSize() const {\r
+ return _buffer.Size();\r
+ }\r
+ /**\r
+ If in print to memory mode, reset the buffer to the\r
+ beginning.\r
+ */\r
+ void ClearBuffer() {\r
+ _buffer.Clear();\r
+ _buffer.Push(0);\r
+ }\r
+\r
+protected:\r
+ virtual bool CompactMode( const XMLElement& ) { return _compactMode; }\r
+\r
+ /** Prints out the space before an element. You may override to change\r
+ the space and tabs used. A PrintSpace() override should call Print().\r
+ */\r
+ virtual void PrintSpace( int depth );\r
+ void Print( const char* format, ... );\r
+\r
+ void SealElementIfJustOpened();\r
+ bool _elementJustOpened;\r
+ DynArray< const char*, 10 > _stack;\r
+\r
+private:\r
+ void PrintString( const char*, bool restrictedEntitySet ); // prints out, after detecting entities.\r
+\r
+ bool _firstElement;\r
+ FILE* _fp;\r
+ int _depth;\r
+ int _textDepth;\r
+ bool _processEntities;\r
+ bool _compactMode;\r
+\r
+ enum {\r
+ ENTITY_RANGE = 64,\r
+ BUF_SIZE = 200\r
+ };\r
+ bool _entityFlag[ENTITY_RANGE];\r
+ bool _restrictedEntityFlag[ENTITY_RANGE];\r
+\r
+ DynArray< char, 20 > _buffer;\r
+};\r
+\r
+\r
+} // tinyxml2\r
+\r
+#if defined(_MSC_VER)\r
+# pragma warning(pop)\r
+#endif\r
+\r
+#endif // TINYXML2_INCLUDED\r