blob: 18555ca72377e7826102d636cfbae1f120b1d921 [file] [log] [blame]
Lee Thomason (grinliz)28129862012-02-25 21:11:20 -08001/*
2Original code by Lee Thomason (www.grinninglizard.com)
3
4This software is provided 'as-is', without any express or implied
5warranty. In no event will the authors be held liable for any
6damages arising from the use of this software.
7
8Permission is granted to anyone to use this software for any
9purpose, including commercial applications, and to alter it and
10redistribute it freely, subject to the following restrictions:
11
121. The origin of this software must not be misrepresented; you must
13not claim that you wrote the original software. If you use this
14software in a product, an acknowledgment in the product documentation
15would be appreciated but is not required.
16
172. Altered source versions must be plainly marked as such, and
18must not be misrepresented as being the original software.
19
203. This notice may not be removed or altered from any source
21distribution.
22*/
Lee Thomason (grinliz)9c38d132012-02-24 21:50:50 -080023
Lee Thomason7d00b9a2012-02-27 17:54:22 -080024#ifndef TINYXML2_INCLUDED
U-Lama\Leee13c3e62011-12-28 14:36:55 -080025#define TINYXML2_INCLUDED
26
Lee Thomason5e3803c2012-04-16 08:57:05 -070027#include <cctype>
28#include <climits>
29#include <cstdio>
30#include <cstring>
31#include <cstdarg>
Lee Thomason (grinliz)6a22be22012-04-04 12:39:05 -070032
Lee Thomason7d00b9a2012-02-27 17:54:22 -080033/*
Lee Thomason7d00b9a2012-02-27 17:54:22 -080034 TODO: intern strings instead of allocation.
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -080035*/
Lee Thomason (grinliz)9b093cc2012-02-25 21:30:18 -080036/*
37 gcc: g++ -Wall tinyxml2.cpp xmltest.cpp -o gccxmltest.exe
38*/
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -080039
U-Lama\Lee4cee6112011-12-31 14:58:18 -080040#if defined( _DEBUG ) || defined( DEBUG ) || defined (__DEBUG__)
41 #ifndef DEBUG
42 #define DEBUG
43 #endif
44#endif
45
46
47#if defined(DEBUG)
48 #if defined(_MSC_VER)
Guillermo A. Amaral68b0c872012-03-24 11:07:19 -070049 #define TIXMLASSERT( x ) if ( !(x)) { __debugbreak(); } //if ( !(x)) WinDebugBreak()
U-Lama\Lee4cee6112011-12-31 14:58:18 -080050 #elif defined (ANDROID_NDK)
51 #include <android/log.h>
52 #define TIXMLASSERT( x ) if ( !(x)) { __android_log_assert( "assert", "grinliz", "ASSERT in '%s' at %d.", __FILE__, __LINE__ ); }
53 #else
54 #include <assert.h>
55 #define TIXMLASSERT assert
56 #endif
57#else
58 #define TIXMLASSERT( x ) {}
59#endif
60
U-Lama\Leee13c3e62011-12-28 14:36:55 -080061
Lee Thomason1a1d4a72012-02-15 09:09:25 -080062#if defined(_MSC_VER) && (_MSC_VER >= 1400 )
63 // Microsoft visual studio, version 2005 and higher.
Lee Thomason (grinliz)598c13e2012-04-06 21:18:23 -070064 /*int _snprintf_s(
65 char *buffer,
66 size_t sizeOfBuffer,
67 size_t count,
68 const char *format [,
69 argument] ...
70 );*/
71 inline int TIXML_SNPRINTF( char* buffer, size_t size, const char* format, ... ) {
72 va_list va;
73 va_start( va, format );
74 int result = vsnprintf_s( buffer, size, _TRUNCATE, format, va );
75 va_end( va );
76 return result;
77 }
Lee Thomason1a1d4a72012-02-15 09:09:25 -080078 #define TIXML_SSCANF sscanf_s
Lee Thomason (grinliz)b9e791f2012-04-06 21:27:10 -070079#else
U-Stream\Leeae25a442012-02-17 17:48:16 -080080 // GCC version 3 and higher
Lee Thomason1a1d4a72012-02-15 09:09:25 -080081 //#warning( "Using sn* functions." )
82 #define TIXML_SNPRINTF snprintf
83 #define TIXML_SSCANF sscanf
Lee Thomason1a1d4a72012-02-15 09:09:25 -080084#endif
Lee Thomason1ff38e02012-02-14 18:18:16 -080085
Lee Thomason (grinliz)390e9782012-07-01 21:22:53 -070086static const int TIXML2_MAJOR_VERSION = 1;
87static const int TIXML2_MINOR_VERSION = 0;
Lee Thomason21be8822012-07-15 17:27:22 -070088static const int TIXML2_PATCH_VERSION = 6;
Lee Thomason1ff38e02012-02-14 18:18:16 -080089
U-Lama\Leee13c3e62011-12-28 14:36:55 -080090namespace tinyxml2
91{
Lee Thomasonce0763e2012-01-11 15:43:54 -080092class XMLDocument;
Lee Thomason8a5dfee2012-01-18 17:43:40 -080093class XMLElement;
94class XMLAttribute;
95class XMLComment;
96class XMLNode;
Lee Thomason5492a1c2012-01-23 15:32:10 -080097class XMLText;
Lee Thomason50f97b22012-02-11 16:33:40 -080098class XMLDeclaration;
99class XMLUnknown;
U-Lama\Leee13c3e62011-12-28 14:36:55 -0800100
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -0800101class XMLPrinter;
Lee Thomason5cae8972012-01-24 18:03:07 -0800102
U-Stream\Leeae25a442012-02-17 17:48:16 -0800103/*
104 A class that wraps strings. Normally stores the start and end
105 pointers into the XML file itself, and will apply normalization
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -0800106 and entity translation if actually read. Can also store (and memory
U-Stream\Leeae25a442012-02-17 17:48:16 -0800107 manage) a traditional char[]
108*/
Lee Thomason39ede242012-01-20 11:27:56 -0800109class StrPair
110{
Lee Thomasond34f52c2012-01-20 12:55:24 -0800111public:
Lee Thomason39ede242012-01-20 11:27:56 -0800112 enum {
Lee Thomasone4422302012-01-20 17:59:50 -0800113 NEEDS_ENTITY_PROCESSING = 0x01,
Lee Thomason18d68bd2012-01-26 18:17:26 -0800114 NEEDS_NEWLINE_NORMALIZATION = 0x02,
115
116 TEXT_ELEMENT = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION,
Lee Thomason6f381b72012-03-02 12:59:39 -0800117 TEXT_ELEMENT_LEAVE_ENTITIES = NEEDS_NEWLINE_NORMALIZATION,
Lee Thomason18d68bd2012-01-26 18:17:26 -0800118 ATTRIBUTE_NAME = 0,
119 ATTRIBUTE_VALUE = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION,
Lee Thomason6f381b72012-03-02 12:59:39 -0800120 ATTRIBUTE_VALUE_LEAVE_ENTITIES = NEEDS_NEWLINE_NORMALIZATION,
Guillermo A. Amaralb42ba362012-03-20 00:15:30 -0700121 COMMENT = NEEDS_NEWLINE_NORMALIZATION
Lee Thomason39ede242012-01-20 11:27:56 -0800122 };
123
124 StrPair() : flags( 0 ), start( 0 ), end( 0 ) {}
Lee Thomason1a1d4a72012-02-15 09:09:25 -0800125 ~StrPair();
126
Lee Thomason5ce89412012-03-20 13:23:44 -0700127 void Set( char* _start, char* _end, int _flags ) {
Lee Thomason1a1d4a72012-02-15 09:09:25 -0800128 Reset();
Lee Thomason5ce89412012-03-20 13:23:44 -0700129 this->start = _start; this->end = _end; this->flags = _flags | NEEDS_FLUSH;
Lee Thomason39ede242012-01-20 11:27:56 -0800130 }
131 const char* GetStr();
Lee Thomasone4422302012-01-20 17:59:50 -0800132 bool Empty() const { return start == end; }
Lee Thomason39ede242012-01-20 11:27:56 -0800133
Guillermo A. Amaral9a6c6b82012-03-24 17:13:25 -0700134 void SetInternedStr( const char* str ) { Reset(); this->start = const_cast<char*>(str); }
Lee Thomason1a1d4a72012-02-15 09:09:25 -0800135 void SetStr( const char* str, int flags=0 );
136
Lee Thomason78a773d2012-07-02 10:10:19 -0700137 char* ParseText( char* in, const char* endTag, int strFlags );
Lee Thomason56bdd022012-02-09 18:16:58 -0800138 char* ParseName( char* in );
139
Lee Thomason2c85a712012-01-31 08:24:24 -0800140
Lee Thomason39ede242012-01-20 11:27:56 -0800141private:
Lee Thomason1a1d4a72012-02-15 09:09:25 -0800142 void Reset();
143
Lee Thomasone4422302012-01-20 17:59:50 -0800144 enum {
Lee Thomason1a1d4a72012-02-15 09:09:25 -0800145 NEEDS_FLUSH = 0x100,
146 NEEDS_DELETE = 0x200
Lee Thomasone4422302012-01-20 17:59:50 -0800147 };
148
Lee Thomason39ede242012-01-20 11:27:56 -0800149 // After parsing, if *end != 0, it can be set to zero.
150 int flags;
Lee Thomasone4422302012-01-20 17:59:50 -0800151 char* start;
Lee Thomason39ede242012-01-20 11:27:56 -0800152 char* end;
153};
154
U-Lama\Lee560bd472011-12-28 19:42:49 -0800155
U-Stream\Leeae25a442012-02-17 17:48:16 -0800156/*
157 A dynamic array of Plain Old Data. Doesn't support constructors, etc.
158 Has a small initial memory pool, so that low or no usage will not
159 cause a call to new/delete
160*/
Lee Thomason2c85a712012-01-31 08:24:24 -0800161template <class T, int INIT>
162class DynArray
163{
164public:
165 DynArray< T, INIT >()
166 {
167 mem = pool;
168 allocated = INIT;
169 size = 0;
170 }
171 ~DynArray()
172 {
173 if ( mem != pool ) {
Lee Thomasona2ae54e2012-05-18 13:47:48 -0700174 delete [] mem;
Lee Thomason2c85a712012-01-31 08:24:24 -0800175 }
176 }
177 void Push( T t )
178 {
179 EnsureCapacity( size+1 );
180 mem[size++] = t;
181 }
182
183 T* PushArr( int count )
184 {
185 EnsureCapacity( size+count );
186 T* ret = &mem[size];
187 size += count;
188 return ret;
189 }
190 T Pop() {
191 return mem[--size];
192 }
193 void PopArr( int count )
194 {
195 TIXMLASSERT( size >= count );
196 size -= count;
197 }
198
U-Stream\Leeae25a442012-02-17 17:48:16 -0800199 bool Empty() const { return size == 0; }
200 T& operator[](int i) { TIXMLASSERT( i>= 0 && i < size ); return mem[i]; }
201 const T& operator[](int i) const { TIXMLASSERT( i>= 0 && i < size ); return mem[i]; }
202 int Size() const { return size; }
203 int Capacity() const { return allocated; }
204 const T* Mem() const { return mem; }
205 T* Mem() { return mem; }
Lee Thomason2c85a712012-01-31 08:24:24 -0800206
207
208private:
209 void EnsureCapacity( int cap ) {
210 if ( cap > allocated ) {
211 int newAllocated = cap * 2;
212 T* newMem = new T[newAllocated];
213 memcpy( newMem, mem, sizeof(T)*size ); // warning: not using constructors, only works for PODs
214 if ( mem != pool ) delete [] mem;
215 mem = newMem;
216 allocated = newAllocated;
217 }
218 }
219
220 T* mem;
221 T pool[INIT];
222 int allocated; // objects allocated
223 int size; // number objects in use
224};
225
Lee Thomason50adb4c2012-02-13 15:07:09 -0800226
U-Stream\Leeae25a442012-02-17 17:48:16 -0800227/*
Thomas Roß08bdf502012-05-12 14:21:23 +0200228 Parent virtual class of a pool for fast allocation
U-Stream\Leeae25a442012-02-17 17:48:16 -0800229 and deallocation of objects.
230*/
Lee Thomasond1983222012-02-06 08:41:24 -0800231class MemPool
232{
233public:
234 MemPool() {}
235 virtual ~MemPool() {}
236
237 virtual int ItemSize() const = 0;
238 virtual void* Alloc() = 0;
239 virtual void Free( void* ) = 0;
240};
241
Lee Thomason50adb4c2012-02-13 15:07:09 -0800242
U-Stream\Leeae25a442012-02-17 17:48:16 -0800243/*
244 Template child class to create pools of the correct type.
245*/
Lee Thomasond1983222012-02-06 08:41:24 -0800246template< int SIZE >
247class MemPoolT : public MemPool
248{
249public:
Lee Thomason455c9d42012-02-06 09:14:14 -0800250 MemPoolT() : root(0), currentAllocs(0), nAllocs(0), maxAllocs(0) {}
Lee Thomasond1983222012-02-06 08:41:24 -0800251 ~MemPoolT() {
252 // Delete the blocks.
253 for( int i=0; i<blockPtrs.Size(); ++i ) {
254 delete blockPtrs[i];
255 }
256 }
257
258 virtual int ItemSize() const { return SIZE; }
Lee Thomason455c9d42012-02-06 09:14:14 -0800259 int CurrentAllocs() const { return currentAllocs; }
Lee Thomasond1983222012-02-06 08:41:24 -0800260
261 virtual void* Alloc() {
262 if ( !root ) {
263 // Need a new block.
264 Block* block = new Block();
265 blockPtrs.Push( block );
266
267 for( int i=0; i<COUNT-1; ++i ) {
268 block->chunk[i].next = &block->chunk[i+1];
269 }
270 block->chunk[COUNT-1].next = 0;
271 root = block->chunk;
272 }
273 void* result = root;
274 root = root->next;
Lee Thomason455c9d42012-02-06 09:14:14 -0800275
276 ++currentAllocs;
277 if ( currentAllocs > maxAllocs ) maxAllocs = currentAllocs;
278 nAllocs++;
Lee Thomasond1983222012-02-06 08:41:24 -0800279 return result;
280 }
281 virtual void Free( void* mem ) {
282 if ( !mem ) return;
Lee Thomason455c9d42012-02-06 09:14:14 -0800283 --currentAllocs;
Lee Thomasond1983222012-02-06 08:41:24 -0800284 Chunk* chunk = (Chunk*)mem;
285 memset( chunk, 0xfe, sizeof(Chunk) );
286 chunk->next = root;
287 root = chunk;
288 }
Lee Thomason455c9d42012-02-06 09:14:14 -0800289 void Trace( const char* name ) {
Lee Thomason43f59302012-02-06 18:18:11 -0800290 printf( "Mempool %s watermark=%d [%dk] current=%d size=%d nAlloc=%d blocks=%d\n",
291 name, maxAllocs, maxAllocs*SIZE/1024, currentAllocs, SIZE, nAllocs, blockPtrs.Size() );
Lee Thomason455c9d42012-02-06 09:14:14 -0800292 }
Lee Thomasond1983222012-02-06 08:41:24 -0800293
294private:
295 enum { COUNT = 1024/SIZE };
296 union Chunk {
297 Chunk* next;
298 char mem[SIZE];
299 };
300 struct Block {
301 Chunk chunk[COUNT];
302 };
303 DynArray< Block*, 10 > blockPtrs;
304 Chunk* root;
Lee Thomason455c9d42012-02-06 09:14:14 -0800305
306 int currentAllocs;
307 int nAllocs;
308 int maxAllocs;
Lee Thomasond1983222012-02-06 08:41:24 -0800309};
310
Lee Thomason2c85a712012-01-31 08:24:24 -0800311
Lee Thomason56bdd022012-02-09 18:16:58 -0800312
313/**
314 Implements the interface to the "Visitor pattern" (see the Accept() method.)
315 If you call the Accept() method, it requires being passed a XMLVisitor
316 class to handle callbacks. For nodes that contain other nodes (Document, Element)
Thomas Roß08bdf502012-05-12 14:21:23 +0200317 you will get called with a VisitEnter/VisitExit pair. Nodes that are always leafs
Lee Thomason56bdd022012-02-09 18:16:58 -0800318 are simply called with Visit().
319
320 If you return 'true' from a Visit method, recursive parsing will continue. If you return
Thomas Roß08bdf502012-05-12 14:21:23 +0200321 false, <b>no children of this node or its sibilings</b> will be visited.
Lee Thomason56bdd022012-02-09 18:16:58 -0800322
323 All flavors of Visit methods have a default implementation that returns 'true' (continue
324 visiting). You need to only override methods that are interesting to you.
325
Thomas Roß08bdf502012-05-12 14:21:23 +0200326 Generally Accept() is called on the TiXmlDocument, although all nodes support visiting.
Lee Thomason56bdd022012-02-09 18:16:58 -0800327
328 You should never change the document from a callback.
329
330 @sa XMLNode::Accept()
331*/
332class XMLVisitor
U-Lama\Leee13c3e62011-12-28 14:36:55 -0800333{
334public:
Lee Thomason56bdd022012-02-09 18:16:58 -0800335 virtual ~XMLVisitor() {}
Lee Thomasond1983222012-02-06 08:41:24 -0800336
Lee Thomason56bdd022012-02-09 18:16:58 -0800337 /// Visit a document.
338 virtual bool VisitEnter( const XMLDocument& /*doc*/ ) { return true; }
339 /// Visit a document.
340 virtual bool VisitExit( const XMLDocument& /*doc*/ ) { return true; }
341
342 /// Visit an element.
343 virtual bool VisitEnter( const XMLElement& /*element*/, const XMLAttribute* /*firstAttribute*/ ) { return true; }
344 /// Visit an element.
345 virtual bool VisitExit( const XMLElement& /*element*/ ) { return true; }
346
Thomas Roß08bdf502012-05-12 14:21:23 +0200347 /// Visit a declaration.
Lee Thomason50f97b22012-02-11 16:33:40 -0800348 virtual bool Visit( const XMLDeclaration& /*declaration*/ ) { return true; }
Thomas Roß08bdf502012-05-12 14:21:23 +0200349 /// Visit a text node.
Lee Thomason56bdd022012-02-09 18:16:58 -0800350 virtual bool Visit( const XMLText& /*text*/ ) { return true; }
Thomas Roß08bdf502012-05-12 14:21:23 +0200351 /// Visit a comment node.
Lee Thomason56bdd022012-02-09 18:16:58 -0800352 virtual bool Visit( const XMLComment& /*comment*/ ) { return true; }
Thomas Roß08bdf502012-05-12 14:21:23 +0200353 /// Visit an unknown node.
Lee Thomason50f97b22012-02-11 16:33:40 -0800354 virtual bool Visit( const XMLUnknown& /*unknown*/ ) { return true; }
Lee Thomason56bdd022012-02-09 18:16:58 -0800355};
356
357
U-Stream\Leeae25a442012-02-17 17:48:16 -0800358/*
359 Utility functionality.
360*/
Lee Thomason56bdd022012-02-09 18:16:58 -0800361class XMLUtil
362{
Lee Thomasond1983222012-02-06 08:41:24 -0800363public:
Lee Thomason56bdd022012-02-09 18:16:58 -0800364 // Anything in the high order range of UTF-8 is assumed to not be whitespace. This isn't
365 // correct, but simple, and usually works.
Lee Thomason (grinliz)390e9782012-07-01 21:22:53 -0700366 static const char* SkipWhiteSpace( const char* p ) { while( !IsUTF8Continuation(*p) && isspace( *reinterpret_cast<const unsigned char*>(p) ) ) { ++p; } return p; }
367 static char* SkipWhiteSpace( char* p ) { while( !IsUTF8Continuation(*p) && isspace( *reinterpret_cast<unsigned char*>(p) ) ) { ++p; } return p; }
U-Lama\Lee4cee6112011-12-31 14:58:18 -0800368
369 inline static bool StringEqual( const char* p, const char* q, int nChar=INT_MAX ) {
370 int n = 0;
Lee Thomasond34f52c2012-01-20 12:55:24 -0800371 if ( p == q ) {
372 return true;
373 }
U-Lama\Lee4cee6112011-12-31 14:58:18 -0800374 while( *p && *q && *p == *q && n<nChar ) {
375 ++p; ++q; ++n;
376 }
377 if ( (n == nChar) || ( *p == 0 && *q == 0 ) ) {
378 return true;
379 }
380 return false;
381 }
Guillermo A. Amaralb42ba362012-03-20 00:15:30 -0700382 inline static int IsUTF8Continuation( const char p ) { return p & 0x80; }
Lee Thomason56bdd022012-02-09 18:16:58 -0800383 inline static int IsAlphaNum( unsigned char anyByte ) { return ( anyByte < 128 ) ? isalnum( anyByte ) : 1; }
384 inline static int IsAlpha( unsigned char anyByte ) { return ( anyByte < 128 ) ? isalpha( anyByte ) : 1; }
Lee Thomason (grinliz)68db57e2012-02-21 09:08:12 -0800385
386 static const char* ReadBOM( const char* p, bool* hasBOM );
387 // p is the starting location,
388 // the UTF-8 value of the entity will be placed in value, and length filled in.
Lee Thomasond6277762012-02-22 16:00:12 -0800389 static const char* GetCharacterRef( const char* p, char* value, int* length );
390 static void ConvertUTF32ToUTF8( unsigned long input, char* output, int* length );
Lee Thomason21be8822012-07-15 17:27:22 -0700391
392 // converts primitive types to strings
393 static void ToStr( int v, char* buffer, int bufferSize );
394 static void ToStr( unsigned v, char* buffer, int bufferSize );
395 static void ToStr( bool v, char* buffer, int bufferSize );
396 static void ToStr( float v, char* buffer, int bufferSize );
397 static void ToStr( double v, char* buffer, int bufferSize );
398
399 // converts strings to primitive types
400 static bool ToInt( const char* str, int* value );
401 static bool ToUnsigned( const char* str, unsigned* value );
402 static bool ToBool( const char* str, bool* value );
403 static bool ToFloat( const char* str, float* value );
404 static bool ToDouble( const char* str, double* value );
Lee Thomason8a5dfee2012-01-18 17:43:40 -0800405};
406
Lee Thomason5cae8972012-01-24 18:03:07 -0800407
Lee Thomason (grinliz)9c38d132012-02-24 21:50:50 -0800408/** XMLNode is a base class for every object that is in the
409 XML Document Object Model (DOM), except XMLAttributes.
410 Nodes have siblings, a parent, and children which can
411 be navigated. A node is always in a XMLDocument.
Lee Thomason3a682622012-03-25 13:19:40 -0700412 The type of a XMLNode can be queried, and it can
Lee Thomason (grinliz)9c38d132012-02-24 21:50:50 -0800413 be cast to its more defined type.
414
Thomas Roß08bdf502012-05-12 14:21:23 +0200415 A XMLDocument allocates memory for all its Nodes.
Lee Thomason (grinliz)9c38d132012-02-24 21:50:50 -0800416 When the XMLDocument gets deleted, all its Nodes
417 will also be deleted.
418
419 @verbatim
420 A Document can contain: Element (container or leaf)
421 Comment (leaf)
422 Unknown (leaf)
423 Declaration( leaf )
424
425 An Element can contain: Element (container or leaf)
426 Text (leaf)
427 Attributes (not on tree)
428 Comment (leaf)
429 Unknown (leaf)
430
431 @endverbatim
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -0800432*/
Lee Thomasond1983222012-02-06 08:41:24 -0800433class XMLNode
Lee Thomason8a5dfee2012-01-18 17:43:40 -0800434{
435 friend class XMLDocument;
436 friend class XMLElement;
437public:
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -0800438
439 /// Get the XMLDocument that owns this XMLNode.
Lee Thomason751da522012-02-10 08:50:51 -0800440 const XMLDocument* GetDocument() const { return document; }
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -0800441 /// Get the XMLDocument that owns this XMLNode.
Lee Thomason56bdd022012-02-09 18:16:58 -0800442 XMLDocument* GetDocument() { return document; }
Lee Thomason8a5dfee2012-01-18 17:43:40 -0800443
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -0800444 virtual XMLElement* ToElement() { return 0; } ///< Safely cast to an Element, or null.
445 virtual XMLText* ToText() { return 0; } ///< Safely cast to Text, or null.
446 virtual XMLComment* ToComment() { return 0; } ///< Safely cast to a Comment, or null.
447 virtual XMLDocument* ToDocument() { return 0; } ///< Safely cast to a Document, or null.
448 virtual XMLDeclaration* ToDeclaration() { return 0; } ///< Safely cast to a Declaration, or null.
449 virtual XMLUnknown* ToUnknown() { return 0; } ///< Safely cast to an Unknown, or null.
Lee Thomason8a5dfee2012-01-18 17:43:40 -0800450
Lee Thomason50f97b22012-02-11 16:33:40 -0800451 virtual const XMLElement* ToElement() const { return 0; }
452 virtual const XMLText* ToText() const { return 0; }
453 virtual const XMLComment* ToComment() const { return 0; }
454 virtual const XMLDocument* ToDocument() const { return 0; }
455 virtual const XMLDeclaration* ToDeclaration() const { return 0; }
456 virtual const XMLUnknown* ToUnknown() const { return 0; }
Lee Thomason751da522012-02-10 08:50:51 -0800457
Lee Thomason (grinliz)9c38d132012-02-24 21:50:50 -0800458 /** The meaning of 'value' changes for the specific type.
459 @verbatim
Thomas Roß08bdf502012-05-12 14:21:23 +0200460 Document: empty
Lee Thomason (grinliz)9c38d132012-02-24 21:50:50 -0800461 Element: name of the element
462 Comment: the comment text
463 Unknown: the tag contents
464 Text: the text string
465 @endverbatim
466 */
Lee Thomason2c85a712012-01-31 08:24:24 -0800467 const char* Value() const { return value.GetStr(); }
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -0800468 /** Set the Value of an XML node.
469 @sa Value()
470 */
Lee Thomason1a1d4a72012-02-15 09:09:25 -0800471 void SetValue( const char* val, bool staticMem=false );
Lee Thomason2c85a712012-01-31 08:24:24 -0800472
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -0800473 /// Get the parent of this node on the DOM.
Lee Thomason751da522012-02-10 08:50:51 -0800474 const XMLNode* Parent() const { return parent; }
475 XMLNode* Parent() { return parent; }
476
Lee Thomason50f97b22012-02-11 16:33:40 -0800477 /// Returns true if this node has no children.
478 bool NoChildren() const { return !firstChild; }
Lee Thomason751da522012-02-10 08:50:51 -0800479
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -0800480 /// Get the first child node, or null if none exists.
Lee Thomason56bdd022012-02-09 18:16:58 -0800481 const XMLNode* FirstChild() const { return firstChild; }
482 XMLNode* FirstChild() { return firstChild; }
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -0800483 /** Get the first child element, or optionally the first child
484 element with the specified name.
485 */
Lee Thomason56bdd022012-02-09 18:16:58 -0800486 const XMLElement* FirstChildElement( const char* value=0 ) const;
Lee Thomason5ce89412012-03-20 13:23:44 -0700487 XMLElement* FirstChildElement( const char* _value=0 ) { return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->FirstChildElement( _value )); }
Lee Thomason3f57d272012-01-11 15:30:03 -0800488
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -0800489 /// Get the last child node, or null if none exists.
Lee Thomason56bdd022012-02-09 18:16:58 -0800490 const XMLNode* LastChild() const { return lastChild; }
491 XMLNode* LastChild() { return const_cast<XMLNode*>(const_cast<const XMLNode*>(this)->LastChild() ); }
Lee Thomason2c85a712012-01-31 08:24:24 -0800492
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -0800493 /** Get the last child element or optionally the last child
494 element with the specified name.
495 */
Lee Thomason56bdd022012-02-09 18:16:58 -0800496 const XMLElement* LastChildElement( const char* value=0 ) const;
Lee Thomason5ce89412012-03-20 13:23:44 -0700497 XMLElement* LastChildElement( const char* _value=0 ) { return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->LastChildElement(_value) ); }
Lee Thomason56bdd022012-02-09 18:16:58 -0800498
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -0800499 /// Get the previous (left) sibling node of this node.
Lee Thomason56bdd022012-02-09 18:16:58 -0800500 const XMLNode* PreviousSibling() const { return prev; }
501 XMLNode* PreviousSibling() { return prev; }
502
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -0800503 /// Get the previous (left) sibling element of this node, with an opitionally supplied name.
Lee Thomason7d00b9a2012-02-27 17:54:22 -0800504 const XMLElement* PreviousSiblingElement( const char* value=0 ) const ;
Lee Thomason5ce89412012-03-20 13:23:44 -0700505 XMLElement* PreviousSiblingElement( const char* _value=0 ) { return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->PreviousSiblingElement( _value ) ); }
Lee Thomason56bdd022012-02-09 18:16:58 -0800506
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -0800507 /// Get the next (right) sibling node of this node.
Lee Thomason56bdd022012-02-09 18:16:58 -0800508 const XMLNode* NextSibling() const { return next; }
509 XMLNode* NextSibling() { return next; }
510
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -0800511 /// Get the next (right) sibling element of this node, with an opitionally supplied name.
Lee Thomason7d00b9a2012-02-27 17:54:22 -0800512 const XMLElement* NextSiblingElement( const char* value=0 ) const;
Lee Thomason5ce89412012-03-20 13:23:44 -0700513 XMLElement* NextSiblingElement( const char* _value=0 ) { return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->NextSiblingElement( _value ) ); }
Lee Thomason56bdd022012-02-09 18:16:58 -0800514
Lee Thomason1ff38e02012-02-14 18:18:16 -0800515 /**
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -0800516 Add a child node as the last (right) child.
Lee Thomason1ff38e02012-02-14 18:18:16 -0800517 */
Lee Thomason56bdd022012-02-09 18:16:58 -0800518 XMLNode* InsertEndChild( XMLNode* addThis );
Lee Thomason618dbf82012-02-28 12:34:27 -0800519
520 XMLNode* LinkEndChild( XMLNode* addThis ) { return InsertEndChild( addThis ); }
Lee Thomason1ff38e02012-02-14 18:18:16 -0800521 /**
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -0800522 Add a child node as the first (left) child.
Lee Thomason1ff38e02012-02-14 18:18:16 -0800523 */
Lee Thomason56bdd022012-02-09 18:16:58 -0800524 XMLNode* InsertFirstChild( XMLNode* addThis );
Lee Thomason1ff38e02012-02-14 18:18:16 -0800525 /**
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -0800526 Add a node after the specified child node.
Lee Thomason1ff38e02012-02-14 18:18:16 -0800527 */
Lee Thomason56bdd022012-02-09 18:16:58 -0800528 XMLNode* InsertAfterChild( XMLNode* afterThis, XMLNode* addThis );
529
U-Stream\Leeae25a442012-02-17 17:48:16 -0800530 /**
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -0800531 Delete all the children of this node.
U-Stream\Leeae25a442012-02-17 17:48:16 -0800532 */
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -0800533 void DeleteChildren();
U-Stream\Leeae25a442012-02-17 17:48:16 -0800534
535 /**
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -0800536 Delete a child of this node.
U-Stream\Leeae25a442012-02-17 17:48:16 -0800537 */
Lee Thomason56bdd022012-02-09 18:16:58 -0800538 void DeleteChild( XMLNode* node );
539
Lee Thomason7d00b9a2012-02-27 17:54:22 -0800540 /**
541 Make a copy of this node, but not its children.
542 You may pass in a Document pointer that will be
543 the owner of the new Node. If the 'document' is
544 null, then the node returned will be allocated
545 from the current Document. (this->GetDocument())
546
547 Note: if called on a XMLDocument, this will return null.
548 */
549 virtual XMLNode* ShallowClone( XMLDocument* document ) const = 0;
550
551 /**
552 Test if 2 nodes are the same, but don't test children.
553 The 2 nodes do not need to be in the same Document.
554
555 Note: if called on a XMLDocument, this will return false.
556 */
557 virtual bool ShallowEqual( const XMLNode* compare ) const = 0;
558
Thomas Roß08bdf502012-05-12 14:21:23 +0200559 /** Accept a hierarchical visit of the nodes in the TinyXML DOM. Every node in the
Lee Thomason (grinliz)9c38d132012-02-24 21:50:50 -0800560 XML tree will be conditionally visited and the host will be called back
561 via the TiXmlVisitor interface.
562
563 This is essentially a SAX interface for TinyXML. (Note however it doesn't re-parse
564 the XML for the callbacks, so the performance of TinyXML is unchanged by using this
565 interface versus any other.)
566
567 The interface has been based on ideas from:
568
569 - http://www.saxproject.org/
570 - http://c2.com/cgi/wiki?HierarchicalVisitorPattern
571
572 Which are both good references for "visiting".
573
574 An example of using Accept():
575 @verbatim
576 TiXmlPrinter printer;
577 tinyxmlDoc.Accept( &printer );
578 const char* xmlcstr = printer.CStr();
579 @endverbatim
580 */
Lee Thomason56bdd022012-02-09 18:16:58 -0800581 virtual bool Accept( XMLVisitor* visitor ) const = 0;
Lee Thomason56bdd022012-02-09 18:16:58 -0800582
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -0800583 // internal
Lee Thomason (grinliz)7468f112012-02-24 08:56:50 -0800584 virtual char* ParseDeep( char*, StrPair* );
Lee Thomason3f57d272012-01-11 15:30:03 -0800585
Lee Thomason8a5dfee2012-01-18 17:43:40 -0800586protected:
587 XMLNode( XMLDocument* );
Lee Thomasond1983222012-02-06 08:41:24 -0800588 virtual ~XMLNode();
Lee Thomason50adb4c2012-02-13 15:07:09 -0800589 XMLNode( const XMLNode& ); // not supported
PKEuSc28ba3a2012-07-16 03:08:47 -0700590 XMLNode& operator=( const XMLNode& ); // not supported
Lee Thomasond1983222012-02-06 08:41:24 -0800591
Lee Thomason3f57d272012-01-11 15:30:03 -0800592 XMLDocument* document;
593 XMLNode* parent;
Lee Thomason50adb4c2012-02-13 15:07:09 -0800594 mutable StrPair value;
Lee Thomason3f57d272012-01-11 15:30:03 -0800595
596 XMLNode* firstChild;
597 XMLNode* lastChild;
598
599 XMLNode* prev;
600 XMLNode* next;
601
U-Lama\Lee4cee6112011-12-31 14:58:18 -0800602private:
Lee Thomasond1983222012-02-06 08:41:24 -0800603 MemPool* memPool;
Lee Thomason18d68bd2012-01-26 18:17:26 -0800604 void Unlink( XMLNode* child );
U-Lama\Lee4cee6112011-12-31 14:58:18 -0800605};
606
607
Lee Thomason (grinliz)9c38d132012-02-24 21:50:50 -0800608/** XML text.
609
610 Note that a text node can have child element nodes, for example:
611 @verbatim
612 <root>This is <b>bold</b></root>
613 @endverbatim
614
615 A text node can have 2 ways to output the next. "normal" output
616 and CDATA. It will default to the mode it was parsed from the XML file and
617 you generally want to leave it alone, but you can change the output mode with
618 SetCDATA() and query it with CDATA().
619*/
Lee Thomason5492a1c2012-01-23 15:32:10 -0800620class XMLText : public XMLNode
621{
Lee Thomason2c85a712012-01-31 08:24:24 -0800622 friend class XMLBase;
623 friend class XMLDocument;
Lee Thomason5492a1c2012-01-23 15:32:10 -0800624public:
Lee Thomason56bdd022012-02-09 18:16:58 -0800625 virtual bool Accept( XMLVisitor* visitor ) const;
Lee Thomason50adb4c2012-02-13 15:07:09 -0800626
Lee Thomason751da522012-02-10 08:50:51 -0800627 virtual XMLText* ToText() { return this; }
628 virtual const XMLText* ToText() const { return this; }
Lee Thomason5492a1c2012-01-23 15:32:10 -0800629
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -0800630 /// Declare whether this should be CDATA or standard text.
Lee Thomason5ce89412012-03-20 13:23:44 -0700631 void SetCData( bool _isCData ) { this->isCData = _isCData; }
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -0800632 /// Returns true if this is a CDATA text element.
Lee Thomason50f97b22012-02-11 16:33:40 -0800633 bool CData() const { return isCData; }
634
Lee Thomason (grinliz)7468f112012-02-24 08:56:50 -0800635 char* ParseDeep( char*, StrPair* endTag );
Lee Thomason7d00b9a2012-02-27 17:54:22 -0800636 virtual XMLNode* ShallowClone( XMLDocument* document ) const;
637 virtual bool ShallowEqual( const XMLNode* compare ) const;
638
Lee Thomason5492a1c2012-01-23 15:32:10 -0800639
640protected:
Lee Thomason50f97b22012-02-11 16:33:40 -0800641 XMLText( XMLDocument* doc ) : XMLNode( doc ), isCData( false ) {}
642 virtual ~XMLText() {}
Lee Thomason50adb4c2012-02-13 15:07:09 -0800643 XMLText( const XMLText& ); // not supported
PKEuSc28ba3a2012-07-16 03:08:47 -0700644 XMLText& operator=( const XMLText& ); // not supported
Lee Thomason5492a1c2012-01-23 15:32:10 -0800645
646private:
Lee Thomason50f97b22012-02-11 16:33:40 -0800647 bool isCData;
Lee Thomason5492a1c2012-01-23 15:32:10 -0800648};
649
650
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -0800651/** An XML Comment. */
U-Lama\Lee4cee6112011-12-31 14:58:18 -0800652class XMLComment : public XMLNode
653{
Lee Thomason2c85a712012-01-31 08:24:24 -0800654 friend class XMLDocument;
Lee Thomason3f57d272012-01-11 15:30:03 -0800655public:
Lee Thomason751da522012-02-10 08:50:51 -0800656 virtual XMLComment* ToComment() { return this; }
657 virtual const XMLComment* ToComment() const { return this; }
Lee Thomasonce0763e2012-01-11 15:43:54 -0800658
Lee Thomason56bdd022012-02-09 18:16:58 -0800659 virtual bool Accept( XMLVisitor* visitor ) const;
Lee Thomason8a5dfee2012-01-18 17:43:40 -0800660
Lee Thomason (grinliz)7468f112012-02-24 08:56:50 -0800661 char* ParseDeep( char*, StrPair* endTag );
Lee Thomason7d00b9a2012-02-27 17:54:22 -0800662 virtual XMLNode* ShallowClone( XMLDocument* document ) const;
663 virtual bool ShallowEqual( const XMLNode* compare ) const;
Lee Thomasonce0763e2012-01-11 15:43:54 -0800664
Lee Thomason8a5dfee2012-01-18 17:43:40 -0800665protected:
Lee Thomason2c85a712012-01-31 08:24:24 -0800666 XMLComment( XMLDocument* doc );
Lee Thomasond1983222012-02-06 08:41:24 -0800667 virtual ~XMLComment();
Lee Thomason50adb4c2012-02-13 15:07:09 -0800668 XMLComment( const XMLComment& ); // not supported
PKEuSc28ba3a2012-07-16 03:08:47 -0700669 XMLComment& operator=( const XMLComment& ); // not supported
Lee Thomason8a5dfee2012-01-18 17:43:40 -0800670
Lee Thomason3f57d272012-01-11 15:30:03 -0800671private:
U-Lama\Lee4cee6112011-12-31 14:58:18 -0800672};
U-Lama\Leee13c3e62011-12-28 14:36:55 -0800673
674
Lee Thomason (grinliz)9c38d132012-02-24 21:50:50 -0800675/** In correct XML the declaration is the first entry in the file.
676 @verbatim
677 <?xml version="1.0" standalone="yes"?>
678 @endverbatim
679
680 TinyXML2 will happily read or write files without a declaration,
681 however.
682
683 The text of the declaration isn't interpreted. It is parsed
684 and written as a string.
685*/
Lee Thomason50f97b22012-02-11 16:33:40 -0800686class XMLDeclaration : public XMLNode
687{
688 friend class XMLDocument;
689public:
690 virtual XMLDeclaration* ToDeclaration() { return this; }
691 virtual const XMLDeclaration* ToDeclaration() const { return this; }
692
693 virtual bool Accept( XMLVisitor* visitor ) const;
694
Lee Thomason (grinliz)7468f112012-02-24 08:56:50 -0800695 char* ParseDeep( char*, StrPair* endTag );
Lee Thomason7d00b9a2012-02-27 17:54:22 -0800696 virtual XMLNode* ShallowClone( XMLDocument* document ) const;
697 virtual bool ShallowEqual( const XMLNode* compare ) const;
Lee Thomason50f97b22012-02-11 16:33:40 -0800698
699protected:
700 XMLDeclaration( XMLDocument* doc );
701 virtual ~XMLDeclaration();
Lee Thomason50adb4c2012-02-13 15:07:09 -0800702 XMLDeclaration( const XMLDeclaration& ); // not supported
PKEuSc28ba3a2012-07-16 03:08:47 -0700703 XMLDeclaration& operator=( const XMLDeclaration& ); // not supported
Lee Thomason50f97b22012-02-11 16:33:40 -0800704};
705
706
Lee Thomason (grinliz)9c38d132012-02-24 21:50:50 -0800707/** Any tag that tinyXml doesn't recognize is saved as an
708 unknown. It is a tag of text, but should not be modified.
709 It will be written back to the XML, unchanged, when the file
710 is saved.
711
712 DTD tags get thrown into TiXmlUnknowns.
713*/
Lee Thomason50f97b22012-02-11 16:33:40 -0800714class XMLUnknown : public XMLNode
715{
716 friend class XMLDocument;
717public:
718 virtual XMLUnknown* ToUnknown() { return this; }
719 virtual const XMLUnknown* ToUnknown() const { return this; }
720
721 virtual bool Accept( XMLVisitor* visitor ) const;
722
Lee Thomason (grinliz)7468f112012-02-24 08:56:50 -0800723 char* ParseDeep( char*, StrPair* endTag );
Lee Thomason7d00b9a2012-02-27 17:54:22 -0800724 virtual XMLNode* ShallowClone( XMLDocument* document ) const;
725 virtual bool ShallowEqual( const XMLNode* compare ) const;
Lee Thomason50f97b22012-02-11 16:33:40 -0800726
727protected:
728 XMLUnknown( XMLDocument* doc );
729 virtual ~XMLUnknown();
Lee Thomason50adb4c2012-02-13 15:07:09 -0800730 XMLUnknown( const XMLUnknown& ); // not supported
PKEuSc28ba3a2012-07-16 03:08:47 -0700731 XMLUnknown& operator=( const XMLUnknown& ); // not supported
Lee Thomason50f97b22012-02-11 16:33:40 -0800732};
733
734
Lee Thomason1ff38e02012-02-14 18:18:16 -0800735enum {
Lee Thomason (grinliz)68db57e2012-02-21 09:08:12 -0800736 XML_NO_ERROR = 0,
Lee Thomason7d00b9a2012-02-27 17:54:22 -0800737 XML_SUCCESS = 0,
Lee Thomason (grinliz)68db57e2012-02-21 09:08:12 -0800738
Guillermo A. Amaral2eb70032012-03-20 11:26:57 -0700739 XML_NO_ATTRIBUTE,
740 XML_WRONG_ATTRIBUTE_TYPE,
Lee Thomason (grinliz)68db57e2012-02-21 09:08:12 -0800741
Guillermo A. Amaral2eb70032012-03-20 11:26:57 -0700742 XML_ERROR_FILE_NOT_FOUND,
Lee Thomason7f7b1622012-03-24 12:49:03 -0700743 XML_ERROR_FILE_COULD_NOT_BE_OPENED,
Lee Thomasona3efec02012-06-15 14:30:44 -0700744 XML_ERROR_FILE_READ_ERROR,
Guillermo A. Amaral2eb70032012-03-20 11:26:57 -0700745 XML_ERROR_ELEMENT_MISMATCH,
746 XML_ERROR_PARSING_ELEMENT,
747 XML_ERROR_PARSING_ATTRIBUTE,
748 XML_ERROR_IDENTIFYING_TAG,
749 XML_ERROR_PARSING_TEXT,
750 XML_ERROR_PARSING_CDATA,
751 XML_ERROR_PARSING_COMMENT,
752 XML_ERROR_PARSING_DECLARATION,
753 XML_ERROR_PARSING_UNKNOWN,
754 XML_ERROR_EMPTY_DOCUMENT,
755 XML_ERROR_MISMATCHED_ELEMENT,
Lee Thomason21be8822012-07-15 17:27:22 -0700756 XML_ERROR_PARSING,
757
758 XML_CAN_NOT_CONVERT_TEXT,
759 XML_NO_TEXT_NODE
Lee Thomason1ff38e02012-02-14 18:18:16 -0800760};
761
762
Lee Thomason (grinliz)9c38d132012-02-24 21:50:50 -0800763/** An attribute is a name-value pair. Elements have an arbitrary
764 number of attributes, each with a unique name.
765
766 @note The attributes are not XMLNodes. You may only query the
767 Next() attribute in a list.
768*/
Lee Thomason56bdd022012-02-09 18:16:58 -0800769class XMLAttribute
Lee Thomason8a5dfee2012-01-18 17:43:40 -0800770{
771 friend class XMLElement;
772public:
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -0800773 const char* Name() const { return name.GetStr(); } ///< The name of the attribute.
774 const char* Value() const { return value.GetStr(); } ///< The value of the attribute.
775 const XMLAttribute* Next() const { return next; } ///< The next attribute in the list.
Lee Thomason8a5dfee2012-01-18 17:43:40 -0800776
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -0800777 /** IntAttribute interprets the attribute as an integer, and returns the value.
778 If the value isn't an integer, 0 will be returned. There is no error checking;
779 use QueryIntAttribute() if you need error checking.
780 */
Lee Thomason7d00b9a2012-02-27 17:54:22 -0800781 int IntValue() const { int i=0; QueryIntValue( &i ); return i; }
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -0800782 /// Query as an unsigned integer. See IntAttribute()
Lee Thomason7d00b9a2012-02-27 17:54:22 -0800783 unsigned UnsignedValue() const { unsigned i=0; QueryUnsignedValue( &i ); return i; }
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -0800784 /// Query as a boolean. See IntAttribute()
Lee Thomason7d00b9a2012-02-27 17:54:22 -0800785 bool BoolValue() const { bool b=false; QueryBoolValue( &b ); return b; }
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -0800786 /// Query as a double. See IntAttribute()
Lee Thomason7d00b9a2012-02-27 17:54:22 -0800787 double DoubleValue() const { double d=0; QueryDoubleValue( &d ); return d; }
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -0800788 /// Query as a float. See IntAttribute()
Lee Thomason7d00b9a2012-02-27 17:54:22 -0800789 float FloatValue() const { float f=0; QueryFloatValue( &f ); return f; }
U-Stream\Leeae25a442012-02-17 17:48:16 -0800790
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -0800791 /** QueryIntAttribute interprets the attribute as an integer, and returns the value
792 in the provided paremeter. The function will return XML_NO_ERROR on success,
Guillermo A. Amaral2eb70032012-03-20 11:26:57 -0700793 and XML_WRONG_ATTRIBUTE_TYPE if the conversion is not successful.
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -0800794 */
Lee Thomason7d00b9a2012-02-27 17:54:22 -0800795 int QueryIntValue( int* value ) const;
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -0800796 /// See QueryIntAttribute
Lee Thomason7d00b9a2012-02-27 17:54:22 -0800797 int QueryUnsignedValue( unsigned int* value ) const;
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -0800798 /// See QueryIntAttribute
Lee Thomason7d00b9a2012-02-27 17:54:22 -0800799 int QueryBoolValue( bool* value ) const;
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -0800800 /// See QueryIntAttribute
Lee Thomason7d00b9a2012-02-27 17:54:22 -0800801 int QueryDoubleValue( double* value ) const;
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -0800802 /// See QueryIntAttribute
Lee Thomason7d00b9a2012-02-27 17:54:22 -0800803 int QueryFloatValue( float* value ) const;
Lee Thomason50adb4c2012-02-13 15:07:09 -0800804
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -0800805 /// Set the attribute to a string value.
Lee Thomason1ff38e02012-02-14 18:18:16 -0800806 void SetAttribute( const char* value );
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -0800807 /// Set the attribute to value.
Lee Thomason1ff38e02012-02-14 18:18:16 -0800808 void SetAttribute( int value );
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -0800809 /// Set the attribute to value.
Lee Thomason1ff38e02012-02-14 18:18:16 -0800810 void SetAttribute( unsigned value );
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -0800811 /// Set the attribute to value.
Lee Thomason1ff38e02012-02-14 18:18:16 -0800812 void SetAttribute( bool value );
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -0800813 /// Set the attribute to value.
Lee Thomason1ff38e02012-02-14 18:18:16 -0800814 void SetAttribute( double value );
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -0800815 /// Set the attribute to value.
Lee Thomason1a1d4a72012-02-15 09:09:25 -0800816 void SetAttribute( float value );
Lee Thomason50adb4c2012-02-13 15:07:09 -0800817
Lee Thomason8a5dfee2012-01-18 17:43:40 -0800818private:
Lee Thomason1a1d4a72012-02-15 09:09:25 -0800819 enum { BUF_SIZE = 200 };
U-Stream\Lee09a11c52012-02-17 08:31:16 -0800820
Lee Thomason (grinliz)9b093cc2012-02-25 21:30:18 -0800821 XMLAttribute() : next( 0 ) {}
Lee Thomasond1983222012-02-06 08:41:24 -0800822 virtual ~XMLAttribute() {}
Lee Thomason50adb4c2012-02-13 15:07:09 -0800823 XMLAttribute( const XMLAttribute& ); // not supported
824 void operator=( const XMLAttribute& ); // not supported
U-Stream\Lee09a11c52012-02-17 08:31:16 -0800825 void SetName( const char* name );
Lee Thomason50adb4c2012-02-13 15:07:09 -0800826
Lee Thomason6f381b72012-03-02 12:59:39 -0800827 char* ParseDeep( char* p, bool processEntities );
Lee Thomason8a5dfee2012-01-18 17:43:40 -0800828
Lee Thomason751da522012-02-10 08:50:51 -0800829 mutable StrPair name;
830 mutable StrPair value;
Lee Thomason8a5dfee2012-01-18 17:43:40 -0800831 XMLAttribute* next;
Lee Thomason43f59302012-02-06 18:18:11 -0800832 MemPool* memPool;
Lee Thomason8a5dfee2012-01-18 17:43:40 -0800833};
834
835
Lee Thomason (grinliz)9c38d132012-02-24 21:50:50 -0800836/** The element is a container class. It has a value, the element name,
837 and can contain other elements, text, comments, and unknowns.
838 Elements also contain an arbitrary number of attributes.
839*/
Lee Thomason8a5dfee2012-01-18 17:43:40 -0800840class XMLElement : public XMLNode
841{
Lee Thomason2c85a712012-01-31 08:24:24 -0800842 friend class XMLBase;
843 friend class XMLDocument;
Lee Thomason8a5dfee2012-01-18 17:43:40 -0800844public:
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -0800845 /// Get the name of an element (which is the Value() of the node.)
Lee Thomason2c85a712012-01-31 08:24:24 -0800846 const char* Name() const { return Value(); }
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -0800847 /// Set the name of the element.
Lee Thomason1a1d4a72012-02-15 09:09:25 -0800848 void SetName( const char* str, bool staticMem=false ) { SetValue( str, staticMem ); }
Lee Thomason2c85a712012-01-31 08:24:24 -0800849
Lee Thomason751da522012-02-10 08:50:51 -0800850 virtual XMLElement* ToElement() { return this; }
851 virtual const XMLElement* ToElement() const { return this; }
Lee Thomason56bdd022012-02-09 18:16:58 -0800852 virtual bool Accept( XMLVisitor* visitor ) const;
Lee Thomason8a5dfee2012-01-18 17:43:40 -0800853
Lee Thomason (grinliz)9c38d132012-02-24 21:50:50 -0800854 /** Given an attribute name, Attribute() returns the value
Lee Thomason92258152012-03-24 13:05:39 -0700855 for the attribute of that name, or null if none
856 exists. For example:
857
858 @verbatim
859 const char* value = ele->Attribute( "foo" );
860 @endverbatim
861
862 The 'value' parameter is normally null. However, if specified,
863 the attribute will only be returned if the 'name' and 'value'
864 match. This allow you to write code:
Lee Thomason8ba7f7d2012-03-24 13:04:04 -0700865
866 @verbatim
867 if ( ele->Attribute( "foo", "bar" ) ) callFooIsBar();
868 @endverbatim
869
870 rather than:
871 @verbatim
872 if ( ele->Attribute( "foo" ) ) {
873 if ( strcmp( ele->Attribute( "foo" ), "bar" ) == 0 ) callFooIsBar();
874 }
875 @endverbatim
Lee Thomason (grinliz)9c38d132012-02-24 21:50:50 -0800876 */
Lee Thomason8ba7f7d2012-03-24 13:04:04 -0700877 const char* Attribute( const char* name, const char* value=0 ) const;
Lee Thomason751da522012-02-10 08:50:51 -0800878
Lee Thomason (grinliz)9c38d132012-02-24 21:50:50 -0800879 /** Given an attribute name, IntAttribute() returns the value
880 of the attribute interpreted as an integer. 0 will be
881 returned if there is an error. For a method with error
882 checking, see QueryIntAttribute()
883 */
U-Stream\Lee09a11c52012-02-17 08:31:16 -0800884 int IntAttribute( const char* name ) const { int i=0; QueryIntAttribute( name, &i ); return i; }
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -0800885 /// See IntAttribute()
U-Stream\Lee09a11c52012-02-17 08:31:16 -0800886 unsigned UnsignedAttribute( const char* name ) const{ unsigned i=0; QueryUnsignedAttribute( name, &i ); return i; }
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -0800887 /// See IntAttribute()
U-Stream\Lee09a11c52012-02-17 08:31:16 -0800888 bool BoolAttribute( const char* name ) const { bool b=false; QueryBoolAttribute( name, &b ); return b; }
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -0800889 /// See IntAttribute()
Thomas Roß08bdf502012-05-12 14:21:23 +0200890 double DoubleAttribute( const char* name ) const { double d=0; QueryDoubleAttribute( name, &d ); return d; }
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -0800891 /// See IntAttribute()
Thomas Roß08bdf502012-05-12 14:21:23 +0200892 float FloatAttribute( const char* name ) const { float f=0; QueryFloatAttribute( name, &f ); return f; }
U-Stream\Lee09a11c52012-02-17 08:31:16 -0800893
Lee Thomason (grinliz)9c38d132012-02-24 21:50:50 -0800894 /** Given an attribute name, QueryIntAttribute() returns
Guillermo A. Amaral2eb70032012-03-20 11:26:57 -0700895 XML_NO_ERROR, XML_WRONG_ATTRIBUTE_TYPE if the conversion
896 can't be performed, or XML_NO_ATTRIBUTE if the attribute
Lee Thomason (grinliz)9c38d132012-02-24 21:50:50 -0800897 doesn't exist. If successful, the result of the conversion
898 will be written to 'value'. If not successful, nothing will
899 be written to 'value'. This allows you to provide default
900 value:
901
902 @verbatim
903 int value = 10;
904 QueryIntAttribute( "foo", &value ); // if "foo" isn't found, value will still be 10
905 @endverbatim
906 */
Thomas Roß08bdf502012-05-12 14:21:23 +0200907 int QueryIntAttribute( const char* name, int* _value ) const { const XMLAttribute* a = FindAttribute( name ); if ( !a ) return XML_NO_ATTRIBUTE; return a->QueryIntValue( _value ); }
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -0800908 /// See QueryIntAttribute()
Guillermo A. Amaral9a6c6b82012-03-24 17:13:25 -0700909 int QueryUnsignedAttribute( const char* name, unsigned int* _value ) const { const XMLAttribute* a = FindAttribute( name ); if ( !a ) return XML_NO_ATTRIBUTE; return a->QueryUnsignedValue( _value ); }
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -0800910 /// See QueryIntAttribute()
Guillermo A. Amaral9a6c6b82012-03-24 17:13:25 -0700911 int QueryBoolAttribute( const char* name, bool* _value ) const { const XMLAttribute* a = FindAttribute( name ); if ( !a ) return XML_NO_ATTRIBUTE; return a->QueryBoolValue( _value ); }
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -0800912 /// See QueryIntAttribute()
Guillermo A. Amaral9a6c6b82012-03-24 17:13:25 -0700913 int QueryDoubleAttribute( const char* name, double* _value ) const { const XMLAttribute* a = FindAttribute( name ); if ( !a ) return XML_NO_ATTRIBUTE; return a->QueryDoubleValue( _value ); }
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -0800914 /// See QueryIntAttribute()
Thomas Roß08bdf502012-05-12 14:21:23 +0200915 int QueryFloatAttribute( const char* name, float* _value ) const { const XMLAttribute* a = FindAttribute( name ); if ( !a ) return XML_NO_ATTRIBUTE; return a->QueryFloatValue( _value ); }
Lee Thomason50f97b22012-02-11 16:33:40 -0800916
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -0800917 /// Sets the named attribute to value.
Guillermo A. Amaral9a6c6b82012-03-24 17:13:25 -0700918 void SetAttribute( const char* name, const char* _value ) { XMLAttribute* a = FindOrCreateAttribute( name ); a->SetAttribute( _value ); }
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -0800919 /// Sets the named attribute to value.
Guillermo A. Amaral9a6c6b82012-03-24 17:13:25 -0700920 void SetAttribute( const char* name, int _value ) { XMLAttribute* a = FindOrCreateAttribute( name ); a->SetAttribute( _value ); }
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -0800921 /// Sets the named attribute to value.
Guillermo A. Amaral9a6c6b82012-03-24 17:13:25 -0700922 void SetAttribute( const char* name, unsigned _value ) { XMLAttribute* a = FindOrCreateAttribute( name ); a->SetAttribute( _value ); }
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -0800923 /// Sets the named attribute to value.
Guillermo A. Amaral9a6c6b82012-03-24 17:13:25 -0700924 void SetAttribute( const char* name, bool _value ) { XMLAttribute* a = FindOrCreateAttribute( name ); a->SetAttribute( _value ); }
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -0800925 /// Sets the named attribute to value.
Thomas Roß08bdf502012-05-12 14:21:23 +0200926 void SetAttribute( const char* name, double _value ) { XMLAttribute* a = FindOrCreateAttribute( name ); a->SetAttribute( _value ); }
Lee Thomason50f97b22012-02-11 16:33:40 -0800927
U-Stream\Leeae25a442012-02-17 17:48:16 -0800928 /**
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -0800929 Delete an attribute.
U-Stream\Leeae25a442012-02-17 17:48:16 -0800930 */
931 void DeleteAttribute( const char* name );
Lee Thomason751da522012-02-10 08:50:51 -0800932
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -0800933 /// Return the first attribute in the list.
Lee Thomason751da522012-02-10 08:50:51 -0800934 const XMLAttribute* FirstAttribute() const { return rootAttribute; }
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -0800935 /// Query a specific attribute in the list.
Lee Thomason1a1d4a72012-02-15 09:09:25 -0800936 const XMLAttribute* FindAttribute( const char* name ) const;
Lee Thomason751da522012-02-10 08:50:51 -0800937
Lee Thomason (grinliz)9c38d132012-02-24 21:50:50 -0800938 /** Convenience function for easy access to the text inside an element. Although easy
939 and concise, GetText() is limited compared to getting the TiXmlText child
940 and accessing it directly.
941
942 If the first child of 'this' is a TiXmlText, the GetText()
943 returns the character string of the Text node, else null is returned.
944
945 This is a convenient method for getting the text of simple contained text:
946 @verbatim
947 <foo>This is text</foo>
Lee Thomason21be8822012-07-15 17:27:22 -0700948 const char* str = fooElement->GetText();
Lee Thomason (grinliz)9c38d132012-02-24 21:50:50 -0800949 @endverbatim
950
951 'str' will be a pointer to "This is text".
952
953 Note that this function can be misleading. If the element foo was created from
954 this XML:
955 @verbatim
Lee Thomason21be8822012-07-15 17:27:22 -0700956 <foo><b>This is text</b></foo>
Lee Thomason (grinliz)9c38d132012-02-24 21:50:50 -0800957 @endverbatim
958
959 then the value of str would be null. The first child node isn't a text node, it is
960 another element. From this XML:
961 @verbatim
Lee Thomason21be8822012-07-15 17:27:22 -0700962 <foo>This is <b>text</b></foo>
Lee Thomason (grinliz)9c38d132012-02-24 21:50:50 -0800963 @endverbatim
964 GetText() will return "This is ".
965 */
Lee Thomason50f97b22012-02-11 16:33:40 -0800966 const char* GetText() const;
Lee Thomason751da522012-02-10 08:50:51 -0800967
Lee Thomason21be8822012-07-15 17:27:22 -0700968 /**
969 Convenience method to query the value of a child text node. This is probably best
970 shown by example. Given you have a document is this form:
971 @verbatim
972 <point>
973 <x>1</x>
974 <y>1.4</y>
975 </point>
976 @endverbatim
977
978 The QueryIntText() and similar functions provide a safe and easier way to get to the
979 "value" of x and y.
980
981 @verbatim
982 int x = 0;
983 float y = 0; // types of x and y are contrived for example
984 const XMLElement* xElement = pointElement->FirstChildElement( "x" );
985 const XMLElement* yElement = pointElement->FirstChildElement( "y" );
986 xElement->QueryIntText( &x );
987 yElement->QueryFloatText( &y );
988 @endverbatim
989
990 @returns XML_SUCCESS (0) on success, XML_CAN_NOT_CONVERT_TEXT if the text cannot be converted
991 to the requested type, and XML_NO_TEXT_NODE if there is no child text to query.
992
993 */
994 int QueryIntText( int* _value ) const;
995 /// See QueryIntText()
996 int QueryUnsignedText( unsigned* _value ) const;
997 /// See QueryIntText()
998 int QueryBoolText( bool* _value ) const;
999 /// See QueryIntText()
1000 int QueryDoubleText( double* _value ) const;
1001 /// See QueryIntText()
1002 int QueryFloatText( float* _value ) const;
1003
Lee Thomason2c85a712012-01-31 08:24:24 -08001004 // internal:
Lee Thomason (grinliz)46a14cf2012-02-23 22:27:28 -08001005 enum {
1006 OPEN, // <foo>
1007 CLOSED, // <foo/>
1008 CLOSING // </foo>
1009 };
1010 int ClosingType() const { return closingType; }
Lee Thomason (grinliz)7468f112012-02-24 08:56:50 -08001011 char* ParseDeep( char* p, StrPair* endTag );
Lee Thomason7d00b9a2012-02-27 17:54:22 -08001012 virtual XMLNode* ShallowClone( XMLDocument* document ) const;
1013 virtual bool ShallowEqual( const XMLNode* compare ) const;
Lee Thomason8a5dfee2012-01-18 17:43:40 -08001014
Lee Thomason50adb4c2012-02-13 15:07:09 -08001015private:
Lee Thomason2c85a712012-01-31 08:24:24 -08001016 XMLElement( XMLDocument* doc );
Lee Thomasond1983222012-02-06 08:41:24 -08001017 virtual ~XMLElement();
Lee Thomason50adb4c2012-02-13 15:07:09 -08001018 XMLElement( const XMLElement& ); // not supported
1019 void operator=( const XMLElement& ); // not supported
Lee Thomason8a5dfee2012-01-18 17:43:40 -08001020
Lee Thomason1a1d4a72012-02-15 09:09:25 -08001021 XMLAttribute* FindAttribute( const char* name );
1022 XMLAttribute* FindOrCreateAttribute( const char* name );
Lee Thomason5e3803c2012-04-16 08:57:05 -07001023 //void LinkAttribute( XMLAttribute* attrib );
Lee Thomason (grinliz)46a14cf2012-02-23 22:27:28 -08001024 char* ParseAttributes( char* p );
Lee Thomason67d61312012-01-24 16:01:51 -08001025
Lee Thomason (grinliz)46a14cf2012-02-23 22:27:28 -08001026 int closingType;
Lee Thomason5e3803c2012-04-16 08:57:05 -07001027 // The attribute list is ordered; there is no 'lastAttribute'
1028 // because the list needs to be scanned for dupes before adding
1029 // a new attribute.
Lee Thomason8a5dfee2012-01-18 17:43:40 -08001030 XMLAttribute* rootAttribute;
Lee Thomason8a5dfee2012-01-18 17:43:40 -08001031};
1032
1033
Thomas Roß08bdf502012-05-12 14:21:23 +02001034/** A Document binds together all the functionality.
Lee Thomason (grinliz)9c38d132012-02-24 21:50:50 -08001035 It can be saved, loaded, and printed to the screen.
1036 All Nodes are connected and allocated to a Document.
1037 If the Document is deleted, all its Nodes are also deleted.
1038*/
Lee Thomason67d61312012-01-24 16:01:51 -08001039class XMLDocument : public XMLNode
U-Lama\Leee13c3e62011-12-28 14:36:55 -08001040{
Lee Thomasond1983222012-02-06 08:41:24 -08001041 friend class XMLElement;
U-Lama\Leee13c3e62011-12-28 14:36:55 -08001042public:
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -08001043 /// constructor
Lee Thomason6f381b72012-03-02 12:59:39 -08001044 XMLDocument( bool processEntities = true );
Lee Thomason3f57d272012-01-11 15:30:03 -08001045 ~XMLDocument();
U-Lama\Leee13c3e62011-12-28 14:36:55 -08001046
Lee Thomason751da522012-02-10 08:50:51 -08001047 virtual XMLDocument* ToDocument() { return this; }
1048 virtual const XMLDocument* ToDocument() const { return this; }
Lee Thomason56bdd022012-02-09 18:16:58 -08001049
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -08001050 /**
1051 Parse an XML file from a character string.
1052 Returns XML_NO_ERROR (0) on success, or
1053 an errorID.
1054 */
Lee Thomason (grinliz)bd0a8ac2012-02-20 20:14:33 -08001055 int Parse( const char* xml );
Lee Thomasond11cd162012-04-12 08:35:36 -07001056
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -08001057 /**
1058 Load an XML file from disk.
1059 Returns XML_NO_ERROR (0) on success, or
1060 an errorID.
Lee Thomasond11cd162012-04-12 08:35:36 -07001061 */
Lee Thomason (grinliz)68db57e2012-02-21 09:08:12 -08001062 int LoadFile( const char* filename );
Lee Thomasond11cd162012-04-12 08:35:36 -07001063
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -08001064 /**
1065 Load an XML file from disk. You are responsible
1066 for providing and closing the FILE*.
1067
1068 Returns XML_NO_ERROR (0) on success, or
1069 an errorID.
Lee Thomasond11cd162012-04-12 08:35:36 -07001070 */
Lee Thomason (grinliz)68db57e2012-02-21 09:08:12 -08001071 int LoadFile( FILE* );
Lee Thomasond11cd162012-04-12 08:35:36 -07001072
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -08001073 /**
1074 Save the XML file to disk.
Ken Miller81da1fb2012-04-09 23:32:26 -05001075 Returns XML_NO_ERROR (0) on success, or
1076 an errorID.
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -08001077 */
Robert Reif312a20f2012-09-08 19:33:57 -04001078 int SaveFile( const char* filename, bool compact = false );
Lee Thomasond11cd162012-04-12 08:35:36 -07001079
Ken Miller81da1fb2012-04-09 23:32:26 -05001080 /**
Thomas Roß08bdf502012-05-12 14:21:23 +02001081 Save the XML file to disk. You are responsible
Ken Miller81da1fb2012-04-09 23:32:26 -05001082 for providing and closing the FILE*.
1083
1084 Returns XML_NO_ERROR (0) on success, or
1085 an errorID.
1086 */
Robert Reif312a20f2012-09-08 19:33:57 -04001087 int SaveFile( FILE* fp, bool compact = false );
Lee Thomason (grinliz)68db57e2012-02-21 09:08:12 -08001088
Lee Thomason6f381b72012-03-02 12:59:39 -08001089 bool ProcessEntities() const { return processEntities; }
1090
1091 /**
1092 Returns true if this document has a leading Byte Order Mark of UTF8.
1093 */
Lee Thomason (grinliz)68db57e2012-02-21 09:08:12 -08001094 bool HasBOM() const { return writeBOM; }
Lee Thomasonf68c4382012-04-28 14:37:11 -07001095 /** Sets whether to write the BOM when writing the file.
1096 */
1097 void SetBOM( bool useBOM ) { writeBOM = useBOM; }
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -08001098
1099 /** Return the root element of DOM. Equivalent to FirstChildElement().
1100 To get the first node, use FirstChild().
1101 */
Lee Thomasond6277762012-02-22 16:00:12 -08001102 XMLElement* RootElement() { return FirstChildElement(); }
1103 const XMLElement* RootElement() const { return FirstChildElement(); }
Lee Thomason18d68bd2012-01-26 18:17:26 -08001104
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -08001105 /** Print the Document. If the Printer is not provided, it will
1106 print to stdout. If you provide Printer, this can print to a file:
1107 @verbatim
1108 XMLPrinter printer( fp );
1109 doc.Print( &printer );
1110 @endverbatim
1111
1112 Or you can use a printer to print to memory:
1113 @verbatim
1114 XMLPrinter printer;
1115 doc->Print( &printer );
Lee Thomason (grinliz)28129862012-02-25 21:11:20 -08001116 // printer.CStr() has a const char* to the XML
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -08001117 @endverbatim
1118 */
1119 void Print( XMLPrinter* streamer=0 );
Lee Thomason56bdd022012-02-09 18:16:58 -08001120 virtual bool Accept( XMLVisitor* visitor ) const;
U-Lama\Leee13c3e62011-12-28 14:36:55 -08001121
Lee Thomason1ff38e02012-02-14 18:18:16 -08001122 /**
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -08001123 Create a new Element associated with
1124 this Document. The memory for the Element
1125 is managed by the Document.
Lee Thomason1ff38e02012-02-14 18:18:16 -08001126 */
Lee Thomason2c85a712012-01-31 08:24:24 -08001127 XMLElement* NewElement( const char* name );
Lee Thomason1ff38e02012-02-14 18:18:16 -08001128 /**
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -08001129 Create a new Comment associated with
1130 this Document. The memory for the Comment
1131 is managed by the Document.
Lee Thomason1ff38e02012-02-14 18:18:16 -08001132 */
1133 XMLComment* NewComment( const char* comment );
1134 /**
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -08001135 Create a new Text associated with
1136 this Document. The memory for the Text
1137 is managed by the Document.
Lee Thomason1ff38e02012-02-14 18:18:16 -08001138 */
1139 XMLText* NewText( const char* text );
Lee Thomason7d00b9a2012-02-27 17:54:22 -08001140 /**
1141 Create a new Declaration associated with
1142 this Document. The memory for the object
1143 is managed by the Document.
Lee Thomasonf68c4382012-04-28 14:37:11 -07001144
1145 If the 'text' param is null, the standard
1146 declaration is used.:
1147 @verbatim
1148 <?xml version="1.0" encoding="UTF-8"?>
1149 @endverbatim
Lee Thomason7d00b9a2012-02-27 17:54:22 -08001150 */
Lee Thomasonf68c4382012-04-28 14:37:11 -07001151 XMLDeclaration* NewDeclaration( const char* text=0 );
Lee Thomason7d00b9a2012-02-27 17:54:22 -08001152 /**
1153 Create a new Unknown associated with
1154 this Document. The memory for the object
1155 is managed by the Document.
1156 */
1157 XMLUnknown* NewUnknown( const char* text );
Lee Thomason2c85a712012-01-31 08:24:24 -08001158
U-Stream\Leeae25a442012-02-17 17:48:16 -08001159 /**
Thomas Roß08bdf502012-05-12 14:21:23 +02001160 Delete a node associated with this document.
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -08001161 It will be unlinked from the DOM.
U-Stream\Leeae25a442012-02-17 17:48:16 -08001162 */
1163 void DeleteNode( XMLNode* node ) { node->parent->DeleteChild( node ); }
1164
Lee Thomason67d61312012-01-24 16:01:51 -08001165 void SetError( int error, const char* str1, const char* str2 );
Lee Thomason18d68bd2012-01-26 18:17:26 -08001166
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -08001167 /// Return true if there was an error parsing the document.
Lee Thomason (grinliz)68db57e2012-02-21 09:08:12 -08001168 bool Error() const { return errorID != XML_NO_ERROR; }
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -08001169 /// Return the errorID.
Lee Thomason (grinliz)68db57e2012-02-21 09:08:12 -08001170 int ErrorID() const { return errorID; }
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -08001171 /// Return a possibly helpful diagnostic location or string.
Lee Thomason18d68bd2012-01-26 18:17:26 -08001172 const char* GetErrorStr1() const { return errorStr1; }
Thomas Roß08bdf502012-05-12 14:21:23 +02001173 /// Return a possibly helpful secondary diagnostic location or string.
Lee Thomason18d68bd2012-01-26 18:17:26 -08001174 const char* GetErrorStr2() const { return errorStr2; }
Thomas Roß08bdf502012-05-12 14:21:23 +02001175 /// If there is an error, print it to stdout.
Lee Thomason (grinliz)bd0a8ac2012-02-20 20:14:33 -08001176 void PrintError() const;
Lee Thomason8a5dfee2012-01-18 17:43:40 -08001177
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -08001178 // internal
Lee Thomasond1983222012-02-06 08:41:24 -08001179 char* Identify( char* p, XMLNode** node );
Lee Thomason2c85a712012-01-31 08:24:24 -08001180
Lee Thomason6f381b72012-03-02 12:59:39 -08001181 virtual XMLNode* ShallowClone( XMLDocument* /*document*/ ) const { return 0; }
1182 virtual bool ShallowEqual( const XMLNode* /*compare*/ ) const { return false; }
Lee Thomason7d00b9a2012-02-27 17:54:22 -08001183
Lee Thomason3f57d272012-01-11 15:30:03 -08001184private:
Lee Thomason50adb4c2012-02-13 15:07:09 -08001185 XMLDocument( const XMLDocument& ); // not supported
1186 void operator=( const XMLDocument& ); // not supported
Lee Thomason18d68bd2012-01-26 18:17:26 -08001187 void InitDocument();
1188
Lee Thomason (grinliz)68db57e2012-02-21 09:08:12 -08001189 bool writeBOM;
Lee Thomason6f381b72012-03-02 12:59:39 -08001190 bool processEntities;
Lee Thomason7c913cd2012-01-26 18:32:34 -08001191 int errorID;
Lee Thomason18d68bd2012-01-26 18:17:26 -08001192 const char* errorStr1;
1193 const char* errorStr2;
1194 char* charBuffer;
Lee Thomasond1983222012-02-06 08:41:24 -08001195
1196 MemPoolT< sizeof(XMLElement) > elementPool;
1197 MemPoolT< sizeof(XMLAttribute) > attributePool;
1198 MemPoolT< sizeof(XMLText) > textPool;
1199 MemPoolT< sizeof(XMLComment) > commentPool;
Lee Thomason5cae8972012-01-24 18:03:07 -08001200};
1201
Lee Thomason7c913cd2012-01-26 18:32:34 -08001202
Lee Thomason3ffdd392012-03-28 17:27:55 -07001203/**
1204 A XMLHandle is a class that wraps a node pointer with null checks; this is
Lee Thomason (grinliz)ae209f62012-04-04 22:00:07 -07001205 an incredibly useful thing. Note that XMLHandle is not part of the TinyXML
Lee Thomason3ffdd392012-03-28 17:27:55 -07001206 DOM structure. It is a separate utility class.
1207
1208 Take an example:
1209 @verbatim
1210 <Document>
1211 <Element attributeA = "valueA">
1212 <Child attributeB = "value1" />
1213 <Child attributeB = "value2" />
1214 </Element>
Thomas Roß08bdf502012-05-12 14:21:23 +02001215 </Document>
Lee Thomason3ffdd392012-03-28 17:27:55 -07001216 @endverbatim
1217
1218 Assuming you want the value of "attributeB" in the 2nd "Child" element, it's very
1219 easy to write a *lot* of code that looks like:
1220
1221 @verbatim
Lee Thomason (grinliz)ae209f62012-04-04 22:00:07 -07001222 XMLElement* root = document.FirstChildElement( "Document" );
Lee Thomason3ffdd392012-03-28 17:27:55 -07001223 if ( root )
1224 {
Lee Thomason (grinliz)ae209f62012-04-04 22:00:07 -07001225 XMLElement* element = root->FirstChildElement( "Element" );
Lee Thomason3ffdd392012-03-28 17:27:55 -07001226 if ( element )
1227 {
Lee Thomason (grinliz)ae209f62012-04-04 22:00:07 -07001228 XMLElement* child = element->FirstChildElement( "Child" );
Lee Thomason3ffdd392012-03-28 17:27:55 -07001229 if ( child )
1230 {
Lee Thomason (grinliz)ae209f62012-04-04 22:00:07 -07001231 XMLElement* child2 = child->NextSiblingElement( "Child" );
Lee Thomason3ffdd392012-03-28 17:27:55 -07001232 if ( child2 )
1233 {
1234 // Finally do something useful.
1235 @endverbatim
1236
Lee Thomason (grinliz)ae209f62012-04-04 22:00:07 -07001237 And that doesn't even cover "else" cases. XMLHandle addresses the verbosity
1238 of such code. A XMLHandle checks for null pointers so it is perfectly safe
Lee Thomason3ffdd392012-03-28 17:27:55 -07001239 and correct to use:
1240
1241 @verbatim
Lee Thomasondb0bbb62012-04-04 15:47:04 -07001242 XMLHandle docHandle( &document );
1243 XMLElement* child2 = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).FirstChild().NextSibling().ToElement();
Lee Thomason3ffdd392012-03-28 17:27:55 -07001244 if ( child2 )
1245 {
1246 // do something useful
1247 @endverbatim
1248
1249 Which is MUCH more concise and useful.
1250
1251 It is also safe to copy handles - internally they are nothing more than node pointers.
1252 @verbatim
Lee Thomason (grinliz)ae209f62012-04-04 22:00:07 -07001253 XMLHandle handleCopy = handle;
Lee Thomason3ffdd392012-03-28 17:27:55 -07001254 @endverbatim
Lee Thomason (grinliz)ae209f62012-04-04 22:00:07 -07001255
1256 See also XMLConstHandle, which is the same as XMLHandle, but operates on const objects.
Lee Thomason3ffdd392012-03-28 17:27:55 -07001257*/
1258class XMLHandle
1259{
1260public:
1261 /// Create a handle from any node (at any depth of the tree.) This can be a null pointer.
Lee Thomason8b899812012-04-04 15:58:16 -07001262 XMLHandle( XMLNode* _node ) { node = _node; }
Lee Thomason (grinliz)ae209f62012-04-04 22:00:07 -07001263 /// Create a handle from a node.
Lee Thomason8b899812012-04-04 15:58:16 -07001264 XMLHandle( XMLNode& _node ) { node = &_node; }
Lee Thomason (grinliz)ae209f62012-04-04 22:00:07 -07001265 /// Copy constructor
Lee Thomason8b899812012-04-04 15:58:16 -07001266 XMLHandle( const XMLHandle& ref ) { node = ref.node; }
Lee Thomason (grinliz)ae209f62012-04-04 22:00:07 -07001267 /// Assignment
PKEuSc28ba3a2012-07-16 03:08:47 -07001268 XMLHandle& operator=( const XMLHandle& ref ) { node = ref.node; return *this; }
Lee Thomason3ffdd392012-03-28 17:27:55 -07001269
Lee Thomason (grinliz)ae209f62012-04-04 22:00:07 -07001270 /// Get the first child of this handle.
Lee Thomason8b899812012-04-04 15:58:16 -07001271 XMLHandle FirstChild() { return XMLHandle( node ? node->FirstChild() : 0 ); }
Lee Thomason (grinliz)ae209f62012-04-04 22:00:07 -07001272 /// Get the first child element of this handle.
Lee Thomason8b899812012-04-04 15:58:16 -07001273 XMLHandle FirstChildElement( const char* value=0 ) { return XMLHandle( node ? node->FirstChildElement( value ) : 0 ); }
Lee Thomason (grinliz)ae209f62012-04-04 22:00:07 -07001274 /// Get the last child of this handle.
Lee Thomason8b899812012-04-04 15:58:16 -07001275 XMLHandle LastChild() { return XMLHandle( node ? node->LastChild() : 0 ); }
Lee Thomason (grinliz)ae209f62012-04-04 22:00:07 -07001276 /// Get the last child element of this handle.
Lee Thomason8b899812012-04-04 15:58:16 -07001277 XMLHandle LastChildElement( const char* _value=0 ) { return XMLHandle( node ? node->LastChildElement( _value ) : 0 ); }
Lee Thomason (grinliz)ae209f62012-04-04 22:00:07 -07001278 /// Get the previous sibling of this handle.
Lee Thomason8b899812012-04-04 15:58:16 -07001279 XMLHandle PreviousSibling() { return XMLHandle( node ? node->PreviousSibling() : 0 ); }
Lee Thomason (grinliz)ae209f62012-04-04 22:00:07 -07001280 /// Get the previous sibling element of this handle.
Lee Thomason5708f812012-03-28 17:46:41 -07001281 XMLHandle PreviousSiblingElement( const char* _value=0 ) { return XMLHandle( node ? node->PreviousSiblingElement( _value ) : 0 ); }
Lee Thomason (grinliz)ae209f62012-04-04 22:00:07 -07001282 /// Get the next sibling of this handle.
Lee Thomason8b899812012-04-04 15:58:16 -07001283 XMLHandle NextSibling() { return XMLHandle( node ? node->NextSibling() : 0 ); }
Lee Thomason (grinliz)ae209f62012-04-04 22:00:07 -07001284 /// Get the next sibling element of this handle.
Lee Thomason8b899812012-04-04 15:58:16 -07001285 XMLHandle NextSiblingElement( const char* _value=0 ) { return XMLHandle( node ? node->NextSiblingElement( _value ) : 0 ); }
Lee Thomason3ffdd392012-03-28 17:27:55 -07001286
Lee Thomason (grinliz)ae209f62012-04-04 22:00:07 -07001287 /// Safe cast to XMLNode. This can return null.
Lee Thomason8b899812012-04-04 15:58:16 -07001288 XMLNode* ToNode() { return node; }
Lee Thomason (grinliz)ae209f62012-04-04 22:00:07 -07001289 /// Safe cast to XMLElement. This can return null.
Lee Thomason3ffdd392012-03-28 17:27:55 -07001290 XMLElement* ToElement() { return ( ( node && node->ToElement() ) ? node->ToElement() : 0 ); }
Lee Thomason (grinliz)ae209f62012-04-04 22:00:07 -07001291 /// Safe cast to XMLText. This can return null.
Lee Thomason3ffdd392012-03-28 17:27:55 -07001292 XMLText* ToText() { return ( ( node && node->ToText() ) ? node->ToText() : 0 ); }
Lee Thomason (grinliz)ae209f62012-04-04 22:00:07 -07001293 /// Safe cast to XMLUnknown. This can return null.
Lee Thomason3ffdd392012-03-28 17:27:55 -07001294 XMLUnknown* ToUnknown() { return ( ( node && node->ToUnknown() ) ? node->ToUnknown() : 0 ); }
Lee Thomason (grinliz)ae209f62012-04-04 22:00:07 -07001295 /// Safe cast to XMLDeclaration. This can return null.
Lee Thomason3ffdd392012-03-28 17:27:55 -07001296 XMLDeclaration* ToDeclaration() { return ( ( node && node->ToDeclaration() ) ? node->ToDeclaration() : 0 ); }
Lee Thomason3ffdd392012-03-28 17:27:55 -07001297
1298private:
1299 XMLNode* node;
1300};
1301
Lee Thomason (grinliz)2a1cd272012-02-24 17:37:53 -08001302
1303/**
Lee Thomason (grinliz)ae209f62012-04-04 22:00:07 -07001304 A variant of the XMLHandle class for working with const XMLNodes and Documents. It is the
1305 same in all regards, except for the 'const' qualifiers. See XMLHandle for API.
Lee Thomason8b899812012-04-04 15:58:16 -07001306*/
1307class XMLConstHandle
1308{
1309public:
1310 XMLConstHandle( const XMLNode* _node ) { node = _node; }
1311 XMLConstHandle( const XMLNode& _node ) { node = &_node; }
1312 XMLConstHandle( const XMLConstHandle& ref ) { node = ref.node; }
1313
PKEuSc28ba3a2012-07-16 03:08:47 -07001314 XMLConstHandle& operator=( const XMLConstHandle& ref ) { node = ref.node; return *this; }
Lee Thomason8b899812012-04-04 15:58:16 -07001315
1316 const XMLConstHandle FirstChild() const { return XMLConstHandle( node ? node->FirstChild() : 0 ); }
1317 const XMLConstHandle FirstChildElement( const char* value=0 ) const { return XMLConstHandle( node ? node->FirstChildElement( value ) : 0 ); }
1318 const XMLConstHandle LastChild() const { return XMLConstHandle( node ? node->LastChild() : 0 ); }
1319 const XMLConstHandle LastChildElement( const char* _value=0 ) const { return XMLConstHandle( node ? node->LastChildElement( _value ) : 0 ); }
1320 const XMLConstHandle PreviousSibling() const { return XMLConstHandle( node ? node->PreviousSibling() : 0 ); }
1321 const XMLConstHandle PreviousSiblingElement( const char* _value=0 ) const { return XMLConstHandle( node ? node->PreviousSiblingElement( _value ) : 0 ); }
1322 const XMLConstHandle NextSibling() const { return XMLConstHandle( node ? node->NextSibling() : 0 ); }
1323 const XMLConstHandle NextSiblingElement( const char* _value=0 ) const { return XMLConstHandle( node ? node->NextSiblingElement( _value ) : 0 ); }
1324
1325
1326 const XMLNode* ToNode() const { return node; }
1327 const XMLElement* ToElement() const { return ( ( node && node->ToElement() ) ? node->ToElement() : 0 ); }
1328 const XMLText* ToText() const { return ( ( node && node->ToText() ) ? node->ToText() : 0 ); }
1329 const XMLUnknown* ToUnknown() const { return ( ( node && node->ToUnknown() ) ? node->ToUnknown() : 0 ); }
Lee Thomason (grinliz)bd0a8ac2012-02-20 20:14:33 -08001330 const XMLDeclaration* ToDeclaration() const { return ( ( node && node->ToDeclaration() ) ? node->ToDeclaration() : 0 ); }
1331
Lee Thomason5cae8972012-01-24 18:03:07 -08001332private:
Lee Thomason8b899812012-04-04 15:58:16 -07001333 const XMLNode* node;
Lee Thomason56bdd022012-02-09 18:16:58 -08001334};
Lee Thomason6f381b72012-03-02 12:59:39 -08001335
U-Lama\Leee13c3e62011-12-28 14:36:55 -08001336
1337/**
1338 Printing functionality. The XMLPrinter gives you more
1339 options than the XMLDocument::Print() method.
1340
1341 It can:
1342 -# Print to memory.
Thomas Roß08bdf502012-05-12 14:21:23 +02001343 -# Print to a file you provide.
U-Lama\Leee13c3e62011-12-28 14:36:55 -08001344 -# Print XML without a XMLDocument.
1345
1346 Print to Memory
1347
1348 @verbatim
1349 XMLPrinter printer;
1350 doc->Print( &printer );
Thomas Roß08bdf502012-05-12 14:21:23 +02001351 SomeFunction( printer.CStr() );
U-Lama\Leee13c3e62011-12-28 14:36:55 -08001352 @endverbatim
1353
1354 Print to a File
1355
1356 You provide the file pointer.
1357 @verbatim
1358 XMLPrinter printer( fp );
1359 doc.Print( &printer );
1360 @endverbatim
1361
1362 Print without a XMLDocument
1363
1364 When loading, an XML parser is very useful. However, sometimes
1365 when saving, it just gets in the way. The code is often set up
1366 for streaming, and constructing the DOM is just overhead.
1367
1368 The Printer supports the streaming case. The following code
1369 prints out a trivially simple XML file without ever creating
1370 an XML document.
1371
1372 @verbatim
1373 XMLPrinter printer( fp );
1374 printer.OpenElement( "foo" );
1375 printer.PushAttribute( "foo", "bar" );
1376 printer.CloseElement();
1377 @endverbatim
1378*/
1379class XMLPrinter : public XMLVisitor
1380{
1381public:
1382 /** Construct the printer. If the FILE* is specified,
1383 this will print to the FILE. Else it will print
Lee Thomason4cd85342012-06-04 17:02:37 -07001384 to memory, and the result is available in CStr().
1385 If 'compact' is set to true, then output is created
1386 with only required whitespace and newlines.
U-Lama\Leee13c3e62011-12-28 14:36:55 -08001387 */
sniperbat25900882012-05-28 17:22:07 +08001388 XMLPrinter( FILE* file=0, bool compact = false );
U-Lama\Leee13c3e62011-12-28 14:36:55 -08001389 ~XMLPrinter() {}
1390
1391 /** If streaming, write the BOM and declaration. */
1392 void PushHeader( bool writeBOM, bool writeDeclaration );
1393 /** If streaming, start writing an element.
1394 The element must be closed with CloseElement()
1395 */
1396 void OpenElement( const char* name );
1397 /// If streaming, add an attribute to an open element.
1398 void PushAttribute( const char* name, const char* value );
1399 void PushAttribute( const char* name, int value );
1400 void PushAttribute( const char* name, unsigned value );
1401 void PushAttribute( const char* name, bool value );
1402 void PushAttribute( const char* name, double value );
1403 /// If streaming, close the Element.
1404 void CloseElement();
1405
1406 /// Add a text node.
1407 void PushText( const char* text, bool cdata=false );
Lee Thomason21be8822012-07-15 17:27:22 -07001408 /// Add a text node from an integer.
1409 void PushText( int value );
1410 /// Add a text node from an unsigned.
1411 void PushText( unsigned value );
1412 /// Add a text node from a bool.
1413 void PushText( bool value );
1414 /// Add a text node from a float.
1415 void PushText( float value );
1416 /// Add a text node from a double.
1417 void PushText( double value );
1418
1419 /// Add a comment
U-Lama\Leee13c3e62011-12-28 14:36:55 -08001420 void PushComment( const char* comment );
1421
1422 void PushDeclaration( const char* value );
1423 void PushUnknown( const char* value );
1424
1425 virtual bool VisitEnter( const XMLDocument& /*doc*/ );
1426 virtual bool VisitExit( const XMLDocument& /*doc*/ ) { return true; }
1427
1428 virtual bool VisitEnter( const XMLElement& element, const XMLAttribute* attribute );
1429 virtual bool VisitExit( const XMLElement& element );
1430
1431 virtual bool Visit( const XMLText& text );
1432 virtual bool Visit( const XMLComment& comment );
1433 virtual bool Visit( const XMLDeclaration& declaration );
1434 virtual bool Visit( const XMLUnknown& unknown );
1435
1436 /**
1437 If in print to memory mode, return a pointer to
1438 the XML file in memory.
1439 */
1440 const char* CStr() const { return buffer.Mem(); }
sniperbate01e7862012-05-21 12:45:36 +08001441 /**
Lee Thomason (grinliz)48ea0bc2012-05-26 14:41:14 -07001442 If in print to memory mode, return the size
1443 of the XML file in memory. (Note the size returned
1444 includes the terminating null.)
sniperbate01e7862012-05-21 12:45:36 +08001445 */
Lee Thomasonc78dc012012-06-12 13:12:15 -07001446 int CStrSize() const { return buffer.Size(); }
U-Lama\Leee13c3e62011-12-28 14:36:55 -08001447
1448private:
Lee Thomason7d00b9a2012-02-27 17:54:22 -08001449 void SealElement();
1450 void PrintSpace( int depth );
U-Lama\Leee13c3e62011-12-28 14:36:55 -08001451 void PrintString( const char*, bool restrictedEntitySet ); // prints out, after detecting entities.
1452 void Print( const char* format, ... );
1453
1454 bool elementJustOpened;
1455 bool firstElement;
1456 FILE* fp;
1457 int depth;
1458 int textDepth;
1459 bool processEntities;
sniperbat25900882012-05-28 17:22:07 +08001460 bool compactMode;
U-Lama\Leee13c3e62011-12-28 14:36:55 -08001461
1462 enum {
1463 ENTITY_RANGE = 64,
1464 BUF_SIZE = 200
1465 };
1466 bool entityFlag[ENTITY_RANGE];
1467 bool restrictedEntityFlag[ENTITY_RANGE];
1468
1469 DynArray< const char*, 10 > stack;
PKEuSe736f292012-07-16 03:27:55 -07001470 DynArray< char, 20 > buffer;
1471#ifdef _MSC_VER
1472 DynArray< char, 20 > accumulator;
1473#endif
U-Lama\Leee13c3e62011-12-28 14:36:55 -08001474};
1475
1476
Guillermo A. Amaralb42ba362012-03-20 00:15:30 -07001477} // tinyxml2
U-Lama\Leee13c3e62011-12-28 14:36:55 -08001478
1479
U-Lama\Leee13c3e62011-12-28 14:36:55 -08001480#endif // TINYXML2_INCLUDED