TinyXML-2  8.0.0
tinyxml2.h
1 /*
2 Original code by Lee Thomason (www.grinninglizard.com)
3 
4 This software is provided 'as-is', without any express or implied
5 warranty. In no event will the authors be held liable for any
6 damages arising from the use of this software.
7 
8 Permission is granted to anyone to use this software for any
9 purpose, including commercial applications, and to alter it and
10 redistribute it freely, subject to the following restrictions:
11 
12 1. The origin of this software must not be misrepresented; you must
13 not claim that you wrote the original software. If you use this
14 software in a product, an acknowledgment in the product documentation
15 would be appreciated but is not required.
16 
17 2. Altered source versions must be plainly marked as such, and
18 must not be misrepresented as being the original software.
19 
20 3. This notice may not be removed or altered from any source
21 distribution.
22 */
23 
24 #ifndef TINYXML2_INCLUDED
25 #define TINYXML2_INCLUDED
26 
27 #if defined(ANDROID_NDK) || defined(__BORLANDC__) || defined(__QNXNTO__)
28 # include <ctype.h>
29 # include <limits.h>
30 # include <stdio.h>
31 # include <stdlib.h>
32 # include <string.h>
33 # if defined(__PS3__)
34 # include <stddef.h>
35 # endif
36 #else
37 # include <cctype>
38 # include <climits>
39 # include <cstdio>
40 # include <cstdlib>
41 # include <cstring>
42 #endif
43 #include <stdint.h>
44 
45 /*
46  TODO: intern strings instead of allocation.
47 */
48 /*
49  gcc:
50  g++ -Wall -DTINYXML2_DEBUG tinyxml2.cpp xmltest.cpp -o gccxmltest.exe
51 
52  Formatting, Artistic Style:
53  AStyle.exe --style=1tbs --indent-switches --break-closing-brackets --indent-preprocessor tinyxml2.cpp tinyxml2.h
54 */
55 
56 #if defined( _DEBUG ) || defined (__DEBUG__)
57 # ifndef TINYXML2_DEBUG
58 # define TINYXML2_DEBUG
59 # endif
60 #endif
61 
62 #ifdef _MSC_VER
63 # pragma warning(push)
64 # pragma warning(disable: 4251)
65 #endif
66 
67 #ifdef _WIN32
68 # ifdef TINYXML2_EXPORT
69 # define TINYXML2_LIB __declspec(dllexport)
70 # elif defined(TINYXML2_IMPORT)
71 # define TINYXML2_LIB __declspec(dllimport)
72 # else
73 # define TINYXML2_LIB
74 # endif
75 #elif __GNUC__ >= 4
76 # define TINYXML2_LIB __attribute__((visibility("default")))
77 #else
78 # define TINYXML2_LIB
79 #endif
80 
81 
82 #if defined(TINYXML2_DEBUG)
83 # if defined(_MSC_VER)
84 # // "(void)0," is for suppressing C4127 warning in "assert(false)", "assert(true)" and the like
85 # define TIXMLASSERT( x ) if ( !((void)0,(x))) { __debugbreak(); }
86 # elif defined (ANDROID_NDK)
87 # include <android/log.h>
88 # define TIXMLASSERT( x ) if ( !(x)) { __android_log_assert( "assert", "grinliz", "ASSERT in '%s' at %d.", __FILE__, __LINE__ ); }
89 # else
90 # include <assert.h>
91 # define TIXMLASSERT assert
92 # endif
93 #else
94 # define TIXMLASSERT( x ) {}
95 #endif
96 
97 
98 /* Versioning, past 1.0.14:
99  http://semver.org/
100 */
101 static const int TIXML2_MAJOR_VERSION = 8;
102 static const int TIXML2_MINOR_VERSION = 0;
103 static const int TIXML2_PATCH_VERSION = 0;
104 
105 #define TINYXML2_MAJOR_VERSION 8
106 #define TINYXML2_MINOR_VERSION 0
107 #define TINYXML2_PATCH_VERSION 0
108 
109 // A fixed element depth limit is problematic. There needs to be a
110 // limit to avoid a stack overflow. However, that limit varies per
111 // system, and the capacity of the stack. On the other hand, it's a trivial
112 // attack that can result from ill, malicious, or even correctly formed XML,
113 // so there needs to be a limit in place.
114 static const int TINYXML2_MAX_ELEMENT_DEPTH = 100;
115 
116 namespace tinyxml2
117 {
118 class XMLDocument;
119 class XMLElement;
120 class XMLAttribute;
121 class XMLComment;
122 class XMLText;
123 class XMLDeclaration;
124 class XMLUnknown;
125 class XMLPrinter;
126 
127 /*
128  A class that wraps strings. Normally stores the start and end
129  pointers into the XML file itself, and will apply normalization
130  and entity translation if actually read. Can also store (and memory
131  manage) a traditional char[]
132 
133  Isn't clear why TINYXML2_LIB is needed; but seems to fix #719
134 */
135 class TINYXML2_LIB StrPair
136 {
137 public:
138  enum {
139  NEEDS_ENTITY_PROCESSING = 0x01,
140  NEEDS_NEWLINE_NORMALIZATION = 0x02,
141  NEEDS_WHITESPACE_COLLAPSING = 0x04,
142 
143  TEXT_ELEMENT = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION,
144  TEXT_ELEMENT_LEAVE_ENTITIES = NEEDS_NEWLINE_NORMALIZATION,
145  ATTRIBUTE_NAME = 0,
146  ATTRIBUTE_VALUE = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION,
147  ATTRIBUTE_VALUE_LEAVE_ENTITIES = NEEDS_NEWLINE_NORMALIZATION,
148  COMMENT = NEEDS_NEWLINE_NORMALIZATION
149  };
150 
151  StrPair() : _flags( 0 ), _start( 0 ), _end( 0 ) {}
152  ~StrPair();
153 
154  void Set( char* start, char* end, int flags ) {
155  TIXMLASSERT( start );
156  TIXMLASSERT( end );
157  Reset();
158  _start = start;
159  _end = end;
160  _flags = flags | NEEDS_FLUSH;
161  }
162 
163  const char* GetStr();
164 
165  bool Empty() const {
166  return _start == _end;
167  }
168 
169  void SetInternedStr( const char* str ) {
170  Reset();
171  _start = const_cast<char*>(str);
172  }
173 
174  void SetStr( const char* str, int flags=0 );
175 
176  char* ParseText( char* in, const char* endTag, int strFlags, int* curLineNumPtr );
177  char* ParseName( char* in );
178 
179  void TransferTo( StrPair* other );
180  void Reset();
181 
182 private:
183  void CollapseWhitespace();
184 
185  enum {
186  NEEDS_FLUSH = 0x100,
187  NEEDS_DELETE = 0x200
188  };
189 
190  int _flags;
191  char* _start;
192  char* _end;
193 
194  StrPair( const StrPair& other ); // not supported
195  void operator=( const StrPair& other ); // not supported, use TransferTo()
196 };
197 
198 
199 /*
200  A dynamic array of Plain Old Data. Doesn't support constructors, etc.
201  Has a small initial memory pool, so that low or no usage will not
202  cause a call to new/delete
203 */
204 template <class T, int INITIAL_SIZE>
205 class DynArray
206 {
207 public:
208  DynArray() :
209  _mem( _pool ),
210  _allocated( INITIAL_SIZE ),
211  _size( 0 )
212  {
213  }
214 
215  ~DynArray() {
216  if ( _mem != _pool ) {
217  delete [] _mem;
218  }
219  }
220 
221  void Clear() {
222  _size = 0;
223  }
224 
225  void Push( T t ) {
226  TIXMLASSERT( _size < INT_MAX );
227  EnsureCapacity( _size+1 );
228  _mem[_size] = t;
229  ++_size;
230  }
231 
232  T* PushArr( int count ) {
233  TIXMLASSERT( count >= 0 );
234  TIXMLASSERT( _size <= INT_MAX - count );
235  EnsureCapacity( _size+count );
236  T* ret = &_mem[_size];
237  _size += count;
238  return ret;
239  }
240 
241  T Pop() {
242  TIXMLASSERT( _size > 0 );
243  --_size;
244  return _mem[_size];
245  }
246 
247  void PopArr( int count ) {
248  TIXMLASSERT( _size >= count );
249  _size -= count;
250  }
251 
252  bool Empty() const {
253  return _size == 0;
254  }
255 
256  T& operator[](int i) {
257  TIXMLASSERT( i>= 0 && i < _size );
258  return _mem[i];
259  }
260 
261  const T& operator[](int i) const {
262  TIXMLASSERT( i>= 0 && i < _size );
263  return _mem[i];
264  }
265 
266  const T& PeekTop() const {
267  TIXMLASSERT( _size > 0 );
268  return _mem[ _size - 1];
269  }
270 
271  int Size() const {
272  TIXMLASSERT( _size >= 0 );
273  return _size;
274  }
275 
276  int Capacity() const {
277  TIXMLASSERT( _allocated >= INITIAL_SIZE );
278  return _allocated;
279  }
280 
281  void SwapRemove(int i) {
282  TIXMLASSERT(i >= 0 && i < _size);
283  TIXMLASSERT(_size > 0);
284  _mem[i] = _mem[_size - 1];
285  --_size;
286  }
287 
288  const T* Mem() const {
289  TIXMLASSERT( _mem );
290  return _mem;
291  }
292 
293  T* Mem() {
294  TIXMLASSERT( _mem );
295  return _mem;
296  }
297 
298 private:
299  DynArray( const DynArray& ); // not supported
300  void operator=( const DynArray& ); // not supported
301 
302  void EnsureCapacity( int cap ) {
303  TIXMLASSERT( cap > 0 );
304  if ( cap > _allocated ) {
305  TIXMLASSERT( cap <= INT_MAX / 2 );
306  const int newAllocated = cap * 2;
307  T* newMem = new T[newAllocated];
308  TIXMLASSERT( newAllocated >= _size );
309  memcpy( newMem, _mem, sizeof(T)*_size ); // warning: not using constructors, only works for PODs
310  if ( _mem != _pool ) {
311  delete [] _mem;
312  }
313  _mem = newMem;
314  _allocated = newAllocated;
315  }
316  }
317 
318  T* _mem;
319  T _pool[INITIAL_SIZE];
320  int _allocated; // objects allocated
321  int _size; // number objects in use
322 };
323 
324 
325 /*
326  Parent virtual class of a pool for fast allocation
327  and deallocation of objects.
328 */
329 class MemPool
330 {
331 public:
332  MemPool() {}
333  virtual ~MemPool() {}
334 
335  virtual int ItemSize() const = 0;
336  virtual void* Alloc() = 0;
337  virtual void Free( void* ) = 0;
338  virtual void SetTracked() = 0;
339 };
340 
341 
342 /*
343  Template child class to create pools of the correct type.
344 */
345 template< int ITEM_SIZE >
346 class MemPoolT : public MemPool
347 {
348 public:
349  MemPoolT() : _blockPtrs(), _root(0), _currentAllocs(0), _nAllocs(0), _maxAllocs(0), _nUntracked(0) {}
350  ~MemPoolT() {
351  MemPoolT< ITEM_SIZE >::Clear();
352  }
353 
354  void Clear() {
355  // Delete the blocks.
356  while( !_blockPtrs.Empty()) {
357  Block* lastBlock = _blockPtrs.Pop();
358  delete lastBlock;
359  }
360  _root = 0;
361  _currentAllocs = 0;
362  _nAllocs = 0;
363  _maxAllocs = 0;
364  _nUntracked = 0;
365  }
366 
367  virtual int ItemSize() const {
368  return ITEM_SIZE;
369  }
370  int CurrentAllocs() const {
371  return _currentAllocs;
372  }
373 
374  virtual void* Alloc() {
375  if ( !_root ) {
376  // Need a new block.
377  Block* block = new Block();
378  _blockPtrs.Push( block );
379 
380  Item* blockItems = block->items;
381  for( int i = 0; i < ITEMS_PER_BLOCK - 1; ++i ) {
382  blockItems[i].next = &(blockItems[i + 1]);
383  }
384  blockItems[ITEMS_PER_BLOCK - 1].next = 0;
385  _root = blockItems;
386  }
387  Item* const result = _root;
388  TIXMLASSERT( result != 0 );
389  _root = _root->next;
390 
391  ++_currentAllocs;
392  if ( _currentAllocs > _maxAllocs ) {
393  _maxAllocs = _currentAllocs;
394  }
395  ++_nAllocs;
396  ++_nUntracked;
397  return result;
398  }
399 
400  virtual void Free( void* mem ) {
401  if ( !mem ) {
402  return;
403  }
404  --_currentAllocs;
405  Item* item = static_cast<Item*>( mem );
406 #ifdef TINYXML2_DEBUG
407  memset( item, 0xfe, sizeof( *item ) );
408 #endif
409  item->next = _root;
410  _root = item;
411  }
412  void Trace( const char* name ) {
413  printf( "Mempool %s watermark=%d [%dk] current=%d size=%d nAlloc=%d blocks=%d\n",
414  name, _maxAllocs, _maxAllocs * ITEM_SIZE / 1024, _currentAllocs,
415  ITEM_SIZE, _nAllocs, _blockPtrs.Size() );
416  }
417 
418  void SetTracked() {
419  --_nUntracked;
420  }
421 
422  int Untracked() const {
423  return _nUntracked;
424  }
425 
426  // This number is perf sensitive. 4k seems like a good tradeoff on my machine.
427  // The test file is large, 170k.
428  // Release: VS2010 gcc(no opt)
429  // 1k: 4000
430  // 2k: 4000
431  // 4k: 3900 21000
432  // 16k: 5200
433  // 32k: 4300
434  // 64k: 4000 21000
435  // Declared public because some compilers do not accept to use ITEMS_PER_BLOCK
436  // in private part if ITEMS_PER_BLOCK is private
437  enum { ITEMS_PER_BLOCK = (4 * 1024) / ITEM_SIZE };
438 
439 private:
440  MemPoolT( const MemPoolT& ); // not supported
441  void operator=( const MemPoolT& ); // not supported
442 
443  union Item {
444  Item* next;
445  char itemData[ITEM_SIZE];
446  };
447  struct Block {
448  Item items[ITEMS_PER_BLOCK];
449  };
450  DynArray< Block*, 10 > _blockPtrs;
451  Item* _root;
452 
453  int _currentAllocs;
454  int _nAllocs;
455  int _maxAllocs;
456  int _nUntracked;
457 };
458 
459 
460 
480 class TINYXML2_LIB XMLVisitor
481 {
482 public:
483  virtual ~XMLVisitor() {}
484 
486  virtual bool VisitEnter( const XMLDocument& /*doc*/ ) {
487  return true;
488  }
490  virtual bool VisitExit( const XMLDocument& /*doc*/ ) {
491  return true;
492  }
493 
495  virtual bool VisitEnter( const XMLElement& /*element*/, const XMLAttribute* /*firstAttribute*/ ) {
496  return true;
497  }
499  virtual bool VisitExit( const XMLElement& /*element*/ ) {
500  return true;
501  }
502 
504  virtual bool Visit( const XMLDeclaration& /*declaration*/ ) {
505  return true;
506  }
508  virtual bool Visit( const XMLText& /*text*/ ) {
509  return true;
510  }
512  virtual bool Visit( const XMLComment& /*comment*/ ) {
513  return true;
514  }
516  virtual bool Visit( const XMLUnknown& /*unknown*/ ) {
517  return true;
518  }
519 };
520 
521 // WARNING: must match XMLDocument::_errorNames[]
522 enum XMLError {
523  XML_SUCCESS = 0,
524  XML_NO_ATTRIBUTE,
525  XML_WRONG_ATTRIBUTE_TYPE,
526  XML_ERROR_FILE_NOT_FOUND,
527  XML_ERROR_FILE_COULD_NOT_BE_OPENED,
528  XML_ERROR_FILE_READ_ERROR,
529  XML_ERROR_PARSING_ELEMENT,
530  XML_ERROR_PARSING_ATTRIBUTE,
531  XML_ERROR_PARSING_TEXT,
532  XML_ERROR_PARSING_CDATA,
533  XML_ERROR_PARSING_COMMENT,
534  XML_ERROR_PARSING_DECLARATION,
535  XML_ERROR_PARSING_UNKNOWN,
536  XML_ERROR_EMPTY_DOCUMENT,
537  XML_ERROR_MISMATCHED_ELEMENT,
538  XML_ERROR_PARSING,
539  XML_CAN_NOT_CONVERT_TEXT,
540  XML_NO_TEXT_NODE,
541  XML_ELEMENT_DEPTH_EXCEEDED,
542 
543  XML_ERROR_COUNT
544 };
545 
546 
547 /*
548  Utility functionality.
549 */
550 class TINYXML2_LIB XMLUtil
551 {
552 public:
553  static const char* SkipWhiteSpace( const char* p, int* curLineNumPtr ) {
554  TIXMLASSERT( p );
555 
556  while( IsWhiteSpace(*p) ) {
557  if (curLineNumPtr && *p == '\n') {
558  ++(*curLineNumPtr);
559  }
560  ++p;
561  }
562  TIXMLASSERT( p );
563  return p;
564  }
565  static char* SkipWhiteSpace( char* const p, int* curLineNumPtr ) {
566  return const_cast<char*>( SkipWhiteSpace( const_cast<const char*>(p), curLineNumPtr ) );
567  }
568 
569  // Anything in the high order range of UTF-8 is assumed to not be whitespace. This isn't
570  // correct, but simple, and usually works.
571  static bool IsWhiteSpace( char p ) {
572  return !IsUTF8Continuation(p) && isspace( static_cast<unsigned char>(p) );
573  }
574 
575  inline static bool IsNameStartChar( unsigned char ch ) {
576  if ( ch >= 128 ) {
577  // This is a heuristic guess in attempt to not implement Unicode-aware isalpha()
578  return true;
579  }
580  if ( isalpha( ch ) ) {
581  return true;
582  }
583  return ch == ':' || ch == '_';
584  }
585 
586  inline static bool IsNameChar( unsigned char ch ) {
587  return IsNameStartChar( ch )
588  || isdigit( ch )
589  || ch == '.'
590  || ch == '-';
591  }
592 
593  inline static bool IsPrefixHex( const char* p) {
594  p = SkipWhiteSpace(p, 0);
595  return p && *p == '0' && ( *(p + 1) == 'x' || *(p + 1) == 'X');
596  }
597 
598  inline static bool StringEqual( const char* p, const char* q, int nChar=INT_MAX ) {
599  if ( p == q ) {
600  return true;
601  }
602  TIXMLASSERT( p );
603  TIXMLASSERT( q );
604  TIXMLASSERT( nChar >= 0 );
605  return strncmp( p, q, nChar ) == 0;
606  }
607 
608  inline static bool IsUTF8Continuation( const char p ) {
609  return ( p & 0x80 ) != 0;
610  }
611 
612  static const char* ReadBOM( const char* p, bool* hasBOM );
613  // p is the starting location,
614  // the UTF-8 value of the entity will be placed in value, and length filled in.
615  static const char* GetCharacterRef( const char* p, char* value, int* length );
616  static void ConvertUTF32ToUTF8( unsigned long input, char* output, int* length );
617 
618  // converts primitive types to strings
619  static void ToStr( int v, char* buffer, int bufferSize );
620  static void ToStr( unsigned v, char* buffer, int bufferSize );
621  static void ToStr( bool v, char* buffer, int bufferSize );
622  static void ToStr( float v, char* buffer, int bufferSize );
623  static void ToStr( double v, char* buffer, int bufferSize );
624  static void ToStr(int64_t v, char* buffer, int bufferSize);
625  static void ToStr(uint64_t v, char* buffer, int bufferSize);
626 
627  // converts strings to primitive types
628  static bool ToInt( const char* str, int* value );
629  static bool ToUnsigned( const char* str, unsigned* value );
630  static bool ToBool( const char* str, bool* value );
631  static bool ToFloat( const char* str, float* value );
632  static bool ToDouble( const char* str, double* value );
633  static bool ToInt64(const char* str, int64_t* value);
634  static bool ToUnsigned64(const char* str, uint64_t* value);
635  // Changes what is serialized for a boolean value.
636  // Default to "true" and "false". Shouldn't be changed
637  // unless you have a special testing or compatibility need.
638  // Be careful: static, global, & not thread safe.
639  // Be sure to set static const memory as parameters.
640  static void SetBoolSerialization(const char* writeTrue, const char* writeFalse);
641 
642 private:
643  static const char* writeBoolTrue;
644  static const char* writeBoolFalse;
645 };
646 
647 
673 class TINYXML2_LIB XMLNode
674 {
675  friend class XMLDocument;
676  friend class XMLElement;
677 public:
678 
680  const XMLDocument* GetDocument() const {
681  TIXMLASSERT( _document );
682  return _document;
683  }
686  TIXMLASSERT( _document );
687  return _document;
688  }
689 
691  virtual XMLElement* ToElement() {
692  return 0;
693  }
695  virtual XMLText* ToText() {
696  return 0;
697  }
699  virtual XMLComment* ToComment() {
700  return 0;
701  }
703  virtual XMLDocument* ToDocument() {
704  return 0;
705  }
708  return 0;
709  }
711  virtual XMLUnknown* ToUnknown() {
712  return 0;
713  }
714 
715  virtual const XMLElement* ToElement() const {
716  return 0;
717  }
718  virtual const XMLText* ToText() const {
719  return 0;
720  }
721  virtual const XMLComment* ToComment() const {
722  return 0;
723  }
724  virtual const XMLDocument* ToDocument() const {
725  return 0;
726  }
727  virtual const XMLDeclaration* ToDeclaration() const {
728  return 0;
729  }
730  virtual const XMLUnknown* ToUnknown() const {
731  return 0;
732  }
733 
743  const char* Value() const;
744 
748  void SetValue( const char* val, bool staticMem=false );
749 
751  int GetLineNum() const { return _parseLineNum; }
752 
754  const XMLNode* Parent() const {
755  return _parent;
756  }
757 
758  XMLNode* Parent() {
759  return _parent;
760  }
761 
763  bool NoChildren() const {
764  return !_firstChild;
765  }
766 
768  const XMLNode* FirstChild() const {
769  return _firstChild;
770  }
771 
772  XMLNode* FirstChild() {
773  return _firstChild;
774  }
775 
779  const XMLElement* FirstChildElement( const char* name = 0 ) const;
780 
781  XMLElement* FirstChildElement( const char* name = 0 ) {
782  return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->FirstChildElement( name ));
783  }
784 
786  const XMLNode* LastChild() const {
787  return _lastChild;
788  }
789 
790  XMLNode* LastChild() {
791  return _lastChild;
792  }
793 
797  const XMLElement* LastChildElement( const char* name = 0 ) const;
798 
799  XMLElement* LastChildElement( const char* name = 0 ) {
800  return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->LastChildElement(name) );
801  }
802 
804  const XMLNode* PreviousSibling() const {
805  return _prev;
806  }
807 
808  XMLNode* PreviousSibling() {
809  return _prev;
810  }
811 
813  const XMLElement* PreviousSiblingElement( const char* name = 0 ) const ;
814 
815  XMLElement* PreviousSiblingElement( const char* name = 0 ) {
816  return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->PreviousSiblingElement( name ) );
817  }
818 
820  const XMLNode* NextSibling() const {
821  return _next;
822  }
823 
824  XMLNode* NextSibling() {
825  return _next;
826  }
827 
829  const XMLElement* NextSiblingElement( const char* name = 0 ) const;
830 
831  XMLElement* NextSiblingElement( const char* name = 0 ) {
832  return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->NextSiblingElement( name ) );
833  }
834 
843 
844  XMLNode* LinkEndChild( XMLNode* addThis ) {
845  return InsertEndChild( addThis );
846  }
863  XMLNode* InsertAfterChild( XMLNode* afterThis, XMLNode* addThis );
864 
869 
873  void DeleteChild( XMLNode* node );
874 
884  virtual XMLNode* ShallowClone( XMLDocument* document ) const = 0;
885 
899  XMLNode* DeepClone( XMLDocument* target ) const;
900 
907  virtual bool ShallowEqual( const XMLNode* compare ) const = 0;
908 
931  virtual bool Accept( XMLVisitor* visitor ) const = 0;
932 
938  void SetUserData(void* userData) { _userData = userData; }
939 
945  void* GetUserData() const { return _userData; }
946 
947 protected:
948  explicit XMLNode( XMLDocument* );
949  virtual ~XMLNode();
950 
951  virtual char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr);
952 
953  XMLDocument* _document;
954  XMLNode* _parent;
955  mutable StrPair _value;
956  int _parseLineNum;
957 
958  XMLNode* _firstChild;
959  XMLNode* _lastChild;
960 
961  XMLNode* _prev;
962  XMLNode* _next;
963 
964  void* _userData;
965 
966 private:
967  MemPool* _memPool;
968  void Unlink( XMLNode* child );
969  static void DeleteNode( XMLNode* node );
970  void InsertChildPreamble( XMLNode* insertThis ) const;
971  const XMLElement* ToElementWithName( const char* name ) const;
972 
973  XMLNode( const XMLNode& ); // not supported
974  XMLNode& operator=( const XMLNode& ); // not supported
975 };
976 
977 
990 class TINYXML2_LIB XMLText : public XMLNode
991 {
992  friend class XMLDocument;
993 public:
994  virtual bool Accept( XMLVisitor* visitor ) const;
995 
996  virtual XMLText* ToText() {
997  return this;
998  }
999  virtual const XMLText* ToText() const {
1000  return this;
1001  }
1002 
1004  void SetCData( bool isCData ) {
1005  _isCData = isCData;
1006  }
1008  bool CData() const {
1009  return _isCData;
1010  }
1011 
1012  virtual XMLNode* ShallowClone( XMLDocument* document ) const;
1013  virtual bool ShallowEqual( const XMLNode* compare ) const;
1014 
1015 protected:
1016  explicit XMLText( XMLDocument* doc ) : XMLNode( doc ), _isCData( false ) {}
1017  virtual ~XMLText() {}
1018 
1019  char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr );
1020 
1021 private:
1022  bool _isCData;
1023 
1024  XMLText( const XMLText& ); // not supported
1025  XMLText& operator=( const XMLText& ); // not supported
1026 };
1027 
1028 
1030 class TINYXML2_LIB XMLComment : public XMLNode
1031 {
1032  friend class XMLDocument;
1033 public:
1034  virtual XMLComment* ToComment() {
1035  return this;
1036  }
1037  virtual const XMLComment* ToComment() const {
1038  return this;
1039  }
1040 
1041  virtual bool Accept( XMLVisitor* visitor ) const;
1042 
1043  virtual XMLNode* ShallowClone( XMLDocument* document ) const;
1044  virtual bool ShallowEqual( const XMLNode* compare ) const;
1045 
1046 protected:
1047  explicit XMLComment( XMLDocument* doc );
1048  virtual ~XMLComment();
1049 
1050  char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr);
1051 
1052 private:
1053  XMLComment( const XMLComment& ); // not supported
1054  XMLComment& operator=( const XMLComment& ); // not supported
1055 };
1056 
1057 
1069 class TINYXML2_LIB XMLDeclaration : public XMLNode
1070 {
1071  friend class XMLDocument;
1072 public:
1074  return this;
1075  }
1076  virtual const XMLDeclaration* ToDeclaration() const {
1077  return this;
1078  }
1079 
1080  virtual bool Accept( XMLVisitor* visitor ) const;
1081 
1082  virtual XMLNode* ShallowClone( XMLDocument* document ) const;
1083  virtual bool ShallowEqual( const XMLNode* compare ) const;
1084 
1085 protected:
1086  explicit XMLDeclaration( XMLDocument* doc );
1087  virtual ~XMLDeclaration();
1088 
1089  char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr );
1090 
1091 private:
1092  XMLDeclaration( const XMLDeclaration& ); // not supported
1093  XMLDeclaration& operator=( const XMLDeclaration& ); // not supported
1094 };
1095 
1096 
1104 class TINYXML2_LIB XMLUnknown : public XMLNode
1105 {
1106  friend class XMLDocument;
1107 public:
1108  virtual XMLUnknown* ToUnknown() {
1109  return this;
1110  }
1111  virtual const XMLUnknown* ToUnknown() const {
1112  return this;
1113  }
1114 
1115  virtual bool Accept( XMLVisitor* visitor ) const;
1116 
1117  virtual XMLNode* ShallowClone( XMLDocument* document ) const;
1118  virtual bool ShallowEqual( const XMLNode* compare ) const;
1119 
1120 protected:
1121  explicit XMLUnknown( XMLDocument* doc );
1122  virtual ~XMLUnknown();
1123 
1124  char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr );
1125 
1126 private:
1127  XMLUnknown( const XMLUnknown& ); // not supported
1128  XMLUnknown& operator=( const XMLUnknown& ); // not supported
1129 };
1130 
1131 
1132 
1139 class TINYXML2_LIB XMLAttribute
1140 {
1141  friend class XMLElement;
1142 public:
1144  const char* Name() const;
1145 
1147  const char* Value() const;
1148 
1150  int GetLineNum() const { return _parseLineNum; }
1151 
1153  const XMLAttribute* Next() const {
1154  return _next;
1155  }
1156 
1161  int IntValue() const {
1162  int i = 0;
1163  QueryIntValue(&i);
1164  return i;
1165  }
1166 
1167  int64_t Int64Value() const {
1168  int64_t i = 0;
1169  QueryInt64Value(&i);
1170  return i;
1171  }
1172 
1173  uint64_t Unsigned64Value() const {
1174  uint64_t i = 0;
1175  QueryUnsigned64Value(&i);
1176  return i;
1177  }
1178 
1180  unsigned UnsignedValue() const {
1181  unsigned i=0;
1182  QueryUnsignedValue( &i );
1183  return i;
1184  }
1186  bool BoolValue() const {
1187  bool b=false;
1188  QueryBoolValue( &b );
1189  return b;
1190  }
1192  double DoubleValue() const {
1193  double d=0;
1194  QueryDoubleValue( &d );
1195  return d;
1196  }
1198  float FloatValue() const {
1199  float f=0;
1200  QueryFloatValue( &f );
1201  return f;
1202  }
1203 
1208  XMLError QueryIntValue( int* value ) const;
1210  XMLError QueryUnsignedValue( unsigned int* value ) const;
1212  XMLError QueryInt64Value(int64_t* value) const;
1214  XMLError QueryUnsigned64Value(uint64_t* value) const;
1216  XMLError QueryBoolValue( bool* value ) const;
1218  XMLError QueryDoubleValue( double* value ) const;
1220  XMLError QueryFloatValue( float* value ) const;
1221 
1223  void SetAttribute( const char* value );
1225  void SetAttribute( int value );
1227  void SetAttribute( unsigned value );
1229  void SetAttribute(int64_t value);
1231  void SetAttribute(uint64_t value);
1233  void SetAttribute( bool value );
1235  void SetAttribute( double value );
1237  void SetAttribute( float value );
1238 
1239 private:
1240  enum { BUF_SIZE = 200 };
1241 
1242  XMLAttribute() : _name(), _value(),_parseLineNum( 0 ), _next( 0 ), _memPool( 0 ) {}
1243  virtual ~XMLAttribute() {}
1244 
1245  XMLAttribute( const XMLAttribute& ); // not supported
1246  void operator=( const XMLAttribute& ); // not supported
1247  void SetName( const char* name );
1248 
1249  char* ParseDeep( char* p, bool processEntities, int* curLineNumPtr );
1250 
1251  mutable StrPair _name;
1252  mutable StrPair _value;
1253  int _parseLineNum;
1254  XMLAttribute* _next;
1255  MemPool* _memPool;
1256 };
1257 
1258 
1263 class TINYXML2_LIB XMLElement : public XMLNode
1264 {
1265  friend class XMLDocument;
1266 public:
1268  const char* Name() const {
1269  return Value();
1270  }
1272  void SetName( const char* str, bool staticMem=false ) {
1273  SetValue( str, staticMem );
1274  }
1275 
1276  virtual XMLElement* ToElement() {
1277  return this;
1278  }
1279  virtual const XMLElement* ToElement() const {
1280  return this;
1281  }
1282  virtual bool Accept( XMLVisitor* visitor ) const;
1283 
1307  const char* Attribute( const char* name, const char* value=0 ) const;
1308 
1315  int IntAttribute(const char* name, int defaultValue = 0) const;
1317  unsigned UnsignedAttribute(const char* name, unsigned defaultValue = 0) const;
1319  int64_t Int64Attribute(const char* name, int64_t defaultValue = 0) const;
1321  uint64_t Unsigned64Attribute(const char* name, uint64_t defaultValue = 0) const;
1323  bool BoolAttribute(const char* name, bool defaultValue = false) const;
1325  double DoubleAttribute(const char* name, double defaultValue = 0) const;
1327  float FloatAttribute(const char* name, float defaultValue = 0) const;
1328 
1342  XMLError QueryIntAttribute( const char* name, int* value ) const {
1343  const XMLAttribute* a = FindAttribute( name );
1344  if ( !a ) {
1345  return XML_NO_ATTRIBUTE;
1346  }
1347  return a->QueryIntValue( value );
1348  }
1349 
1351  XMLError QueryUnsignedAttribute( const char* name, unsigned int* value ) const {
1352  const XMLAttribute* a = FindAttribute( name );
1353  if ( !a ) {
1354  return XML_NO_ATTRIBUTE;
1355  }
1356  return a->QueryUnsignedValue( value );
1357  }
1358 
1360  XMLError QueryInt64Attribute(const char* name, int64_t* value) const {
1361  const XMLAttribute* a = FindAttribute(name);
1362  if (!a) {
1363  return XML_NO_ATTRIBUTE;
1364  }
1365  return a->QueryInt64Value(value);
1366  }
1367 
1369  XMLError QueryUnsigned64Attribute(const char* name, uint64_t* value) const {
1370  const XMLAttribute* a = FindAttribute(name);
1371  if(!a) {
1372  return XML_NO_ATTRIBUTE;
1373  }
1374  return a->QueryUnsigned64Value(value);
1375  }
1376 
1378  XMLError QueryBoolAttribute( const char* name, bool* value ) const {
1379  const XMLAttribute* a = FindAttribute( name );
1380  if ( !a ) {
1381  return XML_NO_ATTRIBUTE;
1382  }
1383  return a->QueryBoolValue( value );
1384  }
1386  XMLError QueryDoubleAttribute( const char* name, double* value ) const {
1387  const XMLAttribute* a = FindAttribute( name );
1388  if ( !a ) {
1389  return XML_NO_ATTRIBUTE;
1390  }
1391  return a->QueryDoubleValue( value );
1392  }
1394  XMLError QueryFloatAttribute( const char* name, float* value ) const {
1395  const XMLAttribute* a = FindAttribute( name );
1396  if ( !a ) {
1397  return XML_NO_ATTRIBUTE;
1398  }
1399  return a->QueryFloatValue( value );
1400  }
1401 
1403  XMLError QueryStringAttribute(const char* name, const char** value) const {
1404  const XMLAttribute* a = FindAttribute(name);
1405  if (!a) {
1406  return XML_NO_ATTRIBUTE;
1407  }
1408  *value = a->Value();
1409  return XML_SUCCESS;
1410  }
1411 
1412 
1413 
1431  XMLError QueryAttribute( const char* name, int* value ) const {
1432  return QueryIntAttribute( name, value );
1433  }
1434 
1435  XMLError QueryAttribute( const char* name, unsigned int* value ) const {
1436  return QueryUnsignedAttribute( name, value );
1437  }
1438 
1439  XMLError QueryAttribute(const char* name, int64_t* value) const {
1440  return QueryInt64Attribute(name, value);
1441  }
1442 
1443  XMLError QueryAttribute(const char* name, uint64_t* value) const {
1444  return QueryUnsigned64Attribute(name, value);
1445  }
1446 
1447  XMLError QueryAttribute( const char* name, bool* value ) const {
1448  return QueryBoolAttribute( name, value );
1449  }
1450 
1451  XMLError QueryAttribute( const char* name, double* value ) const {
1452  return QueryDoubleAttribute( name, value );
1453  }
1454 
1455  XMLError QueryAttribute( const char* name, float* value ) const {
1456  return QueryFloatAttribute( name, value );
1457  }
1458 
1460  void SetAttribute( const char* name, const char* value ) {
1461  XMLAttribute* a = FindOrCreateAttribute( name );
1462  a->SetAttribute( value );
1463  }
1465  void SetAttribute( const char* name, int value ) {
1466  XMLAttribute* a = FindOrCreateAttribute( name );
1467  a->SetAttribute( value );
1468  }
1470  void SetAttribute( const char* name, unsigned value ) {
1471  XMLAttribute* a = FindOrCreateAttribute( name );
1472  a->SetAttribute( value );
1473  }
1474 
1476  void SetAttribute(const char* name, int64_t value) {
1477  XMLAttribute* a = FindOrCreateAttribute(name);
1478  a->SetAttribute(value);
1479  }
1480 
1482  void SetAttribute(const char* name, uint64_t value) {
1483  XMLAttribute* a = FindOrCreateAttribute(name);
1484  a->SetAttribute(value);
1485  }
1486 
1488  void SetAttribute( const char* name, bool value ) {
1489  XMLAttribute* a = FindOrCreateAttribute( name );
1490  a->SetAttribute( value );
1491  }
1493  void SetAttribute( const char* name, double value ) {
1494  XMLAttribute* a = FindOrCreateAttribute( name );
1495  a->SetAttribute( value );
1496  }
1498  void SetAttribute( const char* name, float value ) {
1499  XMLAttribute* a = FindOrCreateAttribute( name );
1500  a->SetAttribute( value );
1501  }
1502 
1506  void DeleteAttribute( const char* name );
1507 
1509  const XMLAttribute* FirstAttribute() const {
1510  return _rootAttribute;
1511  }
1513  const XMLAttribute* FindAttribute( const char* name ) const;
1514 
1543  const char* GetText() const;
1544 
1579  void SetText( const char* inText );
1581  void SetText( int value );
1583  void SetText( unsigned value );
1585  void SetText(int64_t value);
1587  void SetText(uint64_t value);
1589  void SetText( bool value );
1591  void SetText( double value );
1593  void SetText( float value );
1594 
1621  XMLError QueryIntText( int* ival ) const;
1623  XMLError QueryUnsignedText( unsigned* uval ) const;
1625  XMLError QueryInt64Text(int64_t* uval) const;
1627  XMLError QueryUnsigned64Text(uint64_t* uval) const;
1629  XMLError QueryBoolText( bool* bval ) const;
1631  XMLError QueryDoubleText( double* dval ) const;
1633  XMLError QueryFloatText( float* fval ) const;
1634 
1635  int IntText(int defaultValue = 0) const;
1636 
1638  unsigned UnsignedText(unsigned defaultValue = 0) const;
1640  int64_t Int64Text(int64_t defaultValue = 0) const;
1642  uint64_t Unsigned64Text(uint64_t defaultValue = 0) const;
1644  bool BoolText(bool defaultValue = false) const;
1646  double DoubleText(double defaultValue = 0) const;
1648  float FloatText(float defaultValue = 0) const;
1649 
1654  XMLElement* InsertNewChildElement(const char* name);
1656  XMLComment* InsertNewComment(const char* comment);
1658  XMLText* InsertNewText(const char* text);
1662  XMLUnknown* InsertNewUnknown(const char* text);
1663 
1664 
1665  // internal:
1666  enum ElementClosingType {
1667  OPEN, // <foo>
1668  CLOSED, // <foo/>
1669  CLOSING // </foo>
1670  };
1671  ElementClosingType ClosingType() const {
1672  return _closingType;
1673  }
1674  virtual XMLNode* ShallowClone( XMLDocument* document ) const;
1675  virtual bool ShallowEqual( const XMLNode* compare ) const;
1676 
1677 protected:
1678  char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr );
1679 
1680 private:
1681  XMLElement( XMLDocument* doc );
1682  virtual ~XMLElement();
1683  XMLElement( const XMLElement& ); // not supported
1684  void operator=( const XMLElement& ); // not supported
1685 
1686  XMLAttribute* FindOrCreateAttribute( const char* name );
1687  char* ParseAttributes( char* p, int* curLineNumPtr );
1688  static void DeleteAttribute( XMLAttribute* attribute );
1689  XMLAttribute* CreateAttribute();
1690 
1691  enum { BUF_SIZE = 200 };
1692  ElementClosingType _closingType;
1693  // The attribute list is ordered; there is no 'lastAttribute'
1694  // because the list needs to be scanned for dupes before adding
1695  // a new attribute.
1696  XMLAttribute* _rootAttribute;
1697 };
1698 
1699 
1700 enum Whitespace {
1701  PRESERVE_WHITESPACE,
1702  COLLAPSE_WHITESPACE
1703 };
1704 
1705 
1711 class TINYXML2_LIB XMLDocument : public XMLNode
1712 {
1713  friend class XMLElement;
1714  // Gives access to SetError and Push/PopDepth, but over-access for everything else.
1715  // Wishing C++ had "internal" scope.
1716  friend class XMLNode;
1717  friend class XMLText;
1718  friend class XMLComment;
1719  friend class XMLDeclaration;
1720  friend class XMLUnknown;
1721 public:
1723  XMLDocument( bool processEntities = true, Whitespace whitespaceMode = PRESERVE_WHITESPACE );
1724  ~XMLDocument();
1725 
1727  TIXMLASSERT( this == _document );
1728  return this;
1729  }
1730  virtual const XMLDocument* ToDocument() const {
1731  TIXMLASSERT( this == _document );
1732  return this;
1733  }
1734 
1745  XMLError Parse( const char* xml, size_t nBytes=static_cast<size_t>(-1) );
1746 
1752  XMLError LoadFile( const char* filename );
1753 
1765  XMLError LoadFile( FILE* );
1766 
1772  XMLError SaveFile( const char* filename, bool compact = false );
1773 
1781  XMLError SaveFile( FILE* fp, bool compact = false );
1782 
1783  bool ProcessEntities() const {
1784  return _processEntities;
1785  }
1786  Whitespace WhitespaceMode() const {
1787  return _whitespaceMode;
1788  }
1789 
1793  bool HasBOM() const {
1794  return _writeBOM;
1795  }
1798  void SetBOM( bool useBOM ) {
1799  _writeBOM = useBOM;
1800  }
1801 
1806  return FirstChildElement();
1807  }
1808  const XMLElement* RootElement() const {
1809  return FirstChildElement();
1810  }
1811 
1826  void Print( XMLPrinter* streamer=0 ) const;
1827  virtual bool Accept( XMLVisitor* visitor ) const;
1828 
1834  XMLElement* NewElement( const char* name );
1840  XMLComment* NewComment( const char* comment );
1846  XMLText* NewText( const char* text );
1858  XMLDeclaration* NewDeclaration( const char* text=0 );
1864  XMLUnknown* NewUnknown( const char* text );
1865 
1870  void DeleteNode( XMLNode* node );
1871 
1872  void ClearError() {
1873  SetError(XML_SUCCESS, 0, 0);
1874  }
1875 
1877  bool Error() const {
1878  return _errorID != XML_SUCCESS;
1879  }
1881  XMLError ErrorID() const {
1882  return _errorID;
1883  }
1884  const char* ErrorName() const;
1885  static const char* ErrorIDToName(XMLError errorID);
1886 
1890  const char* ErrorStr() const;
1891 
1893  void PrintError() const;
1894 
1896  int ErrorLineNum() const
1897  {
1898  return _errorLineNum;
1899  }
1900 
1902  void Clear();
1903 
1911  void DeepCopy(XMLDocument* target) const;
1912 
1913  // internal
1914  char* Identify( char* p, XMLNode** node );
1915 
1916  // internal
1917  void MarkInUse(const XMLNode* const);
1918 
1919  virtual XMLNode* ShallowClone( XMLDocument* /*document*/ ) const {
1920  return 0;
1921  }
1922  virtual bool ShallowEqual( const XMLNode* /*compare*/ ) const {
1923  return false;
1924  }
1925 
1926 private:
1927  XMLDocument( const XMLDocument& ); // not supported
1928  void operator=( const XMLDocument& ); // not supported
1929 
1930  bool _writeBOM;
1931  bool _processEntities;
1932  XMLError _errorID;
1933  Whitespace _whitespaceMode;
1934  mutable StrPair _errorStr;
1935  int _errorLineNum;
1936  char* _charBuffer;
1937  int _parseCurLineNum;
1938  int _parsingDepth;
1939  // Memory tracking does add some overhead.
1940  // However, the code assumes that you don't
1941  // have a bunch of unlinked nodes around.
1942  // Therefore it takes less memory to track
1943  // in the document vs. a linked list in the XMLNode,
1944  // and the performance is the same.
1945  DynArray<XMLNode*, 10> _unlinked;
1946 
1947  MemPoolT< sizeof(XMLElement) > _elementPool;
1948  MemPoolT< sizeof(XMLAttribute) > _attributePool;
1949  MemPoolT< sizeof(XMLText) > _textPool;
1950  MemPoolT< sizeof(XMLComment) > _commentPool;
1951 
1952  static const char* _errorNames[XML_ERROR_COUNT];
1953 
1954  void Parse();
1955 
1956  void SetError( XMLError error, int lineNum, const char* format, ... );
1957 
1958  // Something of an obvious security hole, once it was discovered.
1959  // Either an ill-formed XML or an excessively deep one can overflow
1960  // the stack. Track stack depth, and error out if needed.
1961  class DepthTracker {
1962  public:
1963  explicit DepthTracker(XMLDocument * document) {
1964  this->_document = document;
1965  document->PushDepth();
1966  }
1967  ~DepthTracker() {
1968  _document->PopDepth();
1969  }
1970  private:
1971  XMLDocument * _document;
1972  };
1973  void PushDepth();
1974  void PopDepth();
1975 
1976  template<class NodeType, int PoolElementSize>
1977  NodeType* CreateUnlinkedNode( MemPoolT<PoolElementSize>& pool );
1978 };
1979 
1980 template<class NodeType, int PoolElementSize>
1981 inline NodeType* XMLDocument::CreateUnlinkedNode( MemPoolT<PoolElementSize>& pool )
1982 {
1983  TIXMLASSERT( sizeof( NodeType ) == PoolElementSize );
1984  TIXMLASSERT( sizeof( NodeType ) == pool.ItemSize() );
1985  NodeType* returnNode = new (pool.Alloc()) NodeType( this );
1986  TIXMLASSERT( returnNode );
1987  returnNode->_memPool = &pool;
1988 
1989  _unlinked.Push(returnNode);
1990  return returnNode;
1991 }
1992 
2048 class TINYXML2_LIB XMLHandle
2049 {
2050 public:
2052  explicit XMLHandle( XMLNode* node ) : _node( node ) {
2053  }
2055  explicit XMLHandle( XMLNode& node ) : _node( &node ) {
2056  }
2058  XMLHandle( const XMLHandle& ref ) : _node( ref._node ) {
2059  }
2061  XMLHandle& operator=( const XMLHandle& ref ) {
2062  _node = ref._node;
2063  return *this;
2064  }
2065 
2068  return XMLHandle( _node ? _node->FirstChild() : 0 );
2069  }
2071  XMLHandle FirstChildElement( const char* name = 0 ) {
2072  return XMLHandle( _node ? _node->FirstChildElement( name ) : 0 );
2073  }
2076  return XMLHandle( _node ? _node->LastChild() : 0 );
2077  }
2079  XMLHandle LastChildElement( const char* name = 0 ) {
2080  return XMLHandle( _node ? _node->LastChildElement( name ) : 0 );
2081  }
2084  return XMLHandle( _node ? _node->PreviousSibling() : 0 );
2085  }
2087  XMLHandle PreviousSiblingElement( const char* name = 0 ) {
2088  return XMLHandle( _node ? _node->PreviousSiblingElement( name ) : 0 );
2089  }
2092  return XMLHandle( _node ? _node->NextSibling() : 0 );
2093  }
2095  XMLHandle NextSiblingElement( const char* name = 0 ) {
2096  return XMLHandle( _node ? _node->NextSiblingElement( name ) : 0 );
2097  }
2098 
2101  return _node;
2102  }
2105  return ( _node ? _node->ToElement() : 0 );
2106  }
2109  return ( _node ? _node->ToText() : 0 );
2110  }
2113  return ( _node ? _node->ToUnknown() : 0 );
2114  }
2117  return ( _node ? _node->ToDeclaration() : 0 );
2118  }
2119 
2120 private:
2121  XMLNode* _node;
2122 };
2123 
2124 
2129 class TINYXML2_LIB XMLConstHandle
2130 {
2131 public:
2132  explicit XMLConstHandle( const XMLNode* node ) : _node( node ) {
2133  }
2134  explicit XMLConstHandle( const XMLNode& node ) : _node( &node ) {
2135  }
2136  XMLConstHandle( const XMLConstHandle& ref ) : _node( ref._node ) {
2137  }
2138 
2139  XMLConstHandle& operator=( const XMLConstHandle& ref ) {
2140  _node = ref._node;
2141  return *this;
2142  }
2143 
2144  const XMLConstHandle FirstChild() const {
2145  return XMLConstHandle( _node ? _node->FirstChild() : 0 );
2146  }
2147  const XMLConstHandle FirstChildElement( const char* name = 0 ) const {
2148  return XMLConstHandle( _node ? _node->FirstChildElement( name ) : 0 );
2149  }
2150  const XMLConstHandle LastChild() const {
2151  return XMLConstHandle( _node ? _node->LastChild() : 0 );
2152  }
2153  const XMLConstHandle LastChildElement( const char* name = 0 ) const {
2154  return XMLConstHandle( _node ? _node->LastChildElement( name ) : 0 );
2155  }
2156  const XMLConstHandle PreviousSibling() const {
2157  return XMLConstHandle( _node ? _node->PreviousSibling() : 0 );
2158  }
2159  const XMLConstHandle PreviousSiblingElement( const char* name = 0 ) const {
2160  return XMLConstHandle( _node ? _node->PreviousSiblingElement( name ) : 0 );
2161  }
2162  const XMLConstHandle NextSibling() const {
2163  return XMLConstHandle( _node ? _node->NextSibling() : 0 );
2164  }
2165  const XMLConstHandle NextSiblingElement( const char* name = 0 ) const {
2166  return XMLConstHandle( _node ? _node->NextSiblingElement( name ) : 0 );
2167  }
2168 
2169 
2170  const XMLNode* ToNode() const {
2171  return _node;
2172  }
2173  const XMLElement* ToElement() const {
2174  return ( _node ? _node->ToElement() : 0 );
2175  }
2176  const XMLText* ToText() const {
2177  return ( _node ? _node->ToText() : 0 );
2178  }
2179  const XMLUnknown* ToUnknown() const {
2180  return ( _node ? _node->ToUnknown() : 0 );
2181  }
2182  const XMLDeclaration* ToDeclaration() const {
2183  return ( _node ? _node->ToDeclaration() : 0 );
2184  }
2185 
2186 private:
2187  const XMLNode* _node;
2188 };
2189 
2190 
2233 class TINYXML2_LIB XMLPrinter : public XMLVisitor
2234 {
2235 public:
2242  XMLPrinter( FILE* file=0, bool compact = false, int depth = 0 );
2243  virtual ~XMLPrinter() {}
2244 
2246  void PushHeader( bool writeBOM, bool writeDeclaration );
2250  void OpenElement( const char* name, bool compactMode=false );
2252  void PushAttribute( const char* name, const char* value );
2253  void PushAttribute( const char* name, int value );
2254  void PushAttribute( const char* name, unsigned value );
2255  void PushAttribute( const char* name, int64_t value );
2256  void PushAttribute( const char* name, uint64_t value );
2257  void PushAttribute( const char* name, bool value );
2258  void PushAttribute( const char* name, double value );
2260  virtual void CloseElement( bool compactMode=false );
2261 
2263  void PushText( const char* text, bool cdata=false );
2265  void PushText( int value );
2267  void PushText( unsigned value );
2269  void PushText( int64_t value );
2271  void PushText( uint64_t value );
2273  void PushText( bool value );
2275  void PushText( float value );
2277  void PushText( double value );
2278 
2280  void PushComment( const char* comment );
2281 
2282  void PushDeclaration( const char* value );
2283  void PushUnknown( const char* value );
2284 
2285  virtual bool VisitEnter( const XMLDocument& /*doc*/ );
2286  virtual bool VisitExit( const XMLDocument& /*doc*/ ) {
2287  return true;
2288  }
2289 
2290  virtual bool VisitEnter( const XMLElement& element, const XMLAttribute* attribute );
2291  virtual bool VisitExit( const XMLElement& element );
2292 
2293  virtual bool Visit( const XMLText& text );
2294  virtual bool Visit( const XMLComment& comment );
2295  virtual bool Visit( const XMLDeclaration& declaration );
2296  virtual bool Visit( const XMLUnknown& unknown );
2297 
2302  const char* CStr() const {
2303  return _buffer.Mem();
2304  }
2310  int CStrSize() const {
2311  return _buffer.Size();
2312  }
2317  void ClearBuffer( bool resetToFirstElement = true ) {
2318  _buffer.Clear();
2319  _buffer.Push(0);
2320  _firstElement = resetToFirstElement;
2321  }
2322 
2323 protected:
2324  virtual bool CompactMode( const XMLElement& ) { return _compactMode; }
2325 
2329  virtual void PrintSpace( int depth );
2330  virtual void Print( const char* format, ... );
2331  virtual void Write( const char* data, size_t size );
2332  virtual void Putc( char ch );
2333 
2334  inline void Write(const char* data) { Write(data, strlen(data)); }
2335 
2336  void SealElementIfJustOpened();
2337  bool _elementJustOpened;
2338  DynArray< const char*, 10 > _stack;
2339 
2340 private:
2345  void PrepareForNewNode( bool compactMode );
2346  void PrintString( const char*, bool restrictedEntitySet ); // prints out, after detecting entities.
2347 
2348  bool _firstElement;
2349  FILE* _fp;
2350  int _depth;
2351  int _textDepth;
2352  bool _processEntities;
2353  bool _compactMode;
2354 
2355  enum {
2356  ENTITY_RANGE = 64,
2357  BUF_SIZE = 200
2358  };
2359  bool _entityFlag[ENTITY_RANGE];
2360  bool _restrictedEntityFlag[ENTITY_RANGE];
2361 
2362  DynArray< char, 20 > _buffer;
2363 
2364  // Prohibit cloning, intentionally not implemented
2365  XMLPrinter( const XMLPrinter& );
2366  XMLPrinter& operator=( const XMLPrinter& );
2367 };
2368 
2369 
2370 } // tinyxml2
2371 
2372 #if defined(_MSC_VER)
2373 # pragma warning(pop)
2374 #endif
2375 
2376 #endif // TINYXML2_INCLUDED
tinyxml2::XMLElement::UnsignedAttribute
unsigned UnsignedAttribute(const char *name, unsigned defaultValue=0) const
See IntAttribute()
tinyxml2::XMLPrinter::XMLPrinter
XMLPrinter(FILE *file=0, bool compact=false, int depth=0)
tinyxml2::XMLNode::Value
const char * Value() const
tinyxml2::XMLAttribute::QueryFloatValue
XMLError QueryFloatValue(float *value) const
See QueryIntValue.
tinyxml2::XMLHandle::XMLHandle
XMLHandle(const XMLHandle &ref)
Copy constructor.
Definition: tinyxml2.h:2058
tinyxml2::XMLVisitor::Visit
virtual bool Visit(const XMLDeclaration &)
Visit a declaration.
Definition: tinyxml2.h:504
tinyxml2::XMLAttribute::IntValue
int IntValue() const
Definition: tinyxml2.h:1161
tinyxml2::XMLNode::ToElement
virtual XMLElement * ToElement()
Safely cast to an Element, or null.
Definition: tinyxml2.h:691
tinyxml2::XMLAttribute::DoubleValue
double DoubleValue() const
Query as a double. See IntValue()
Definition: tinyxml2.h:1192
tinyxml2::XMLElement::Unsigned64Text
uint64_t Unsigned64Text(uint64_t defaultValue=0) const
See QueryIntText()
tinyxml2::XMLNode::ToDocument
virtual XMLDocument * ToDocument()
Safely cast to a Document, or null.
Definition: tinyxml2.h:703
tinyxml2::XMLElement::SetAttribute
void SetAttribute(const char *name, int value)
Sets the named attribute to value.
Definition: tinyxml2.h:1465
tinyxml2::XMLNode
Definition: tinyxml2.h:674
tinyxml2::XMLElement::InsertNewDeclaration
XMLDeclaration * InsertNewDeclaration(const char *text)
See InsertNewChildElement()
tinyxml2::XMLElement::FloatText
float FloatText(float defaultValue=0) const
See QueryIntText()
tinyxml2::XMLElement::DeleteAttribute
void DeleteAttribute(const char *name)
tinyxml2::XMLNode::SetUserData
void SetUserData(void *userData)
Definition: tinyxml2.h:938
tinyxml2::XMLElement::SetName
void SetName(const char *str, bool staticMem=false)
Set the name of the element.
Definition: tinyxml2.h:1272
tinyxml2::XMLComment::ShallowClone
virtual XMLNode * ShallowClone(XMLDocument *document) const
tinyxml2::XMLPrinter::OpenElement
void OpenElement(const char *name, bool compactMode=false)
tinyxml2::XMLDocument::Clear
void Clear()
Clear the document, resetting it to the initial state.
tinyxml2::XMLPrinter::PushComment
void PushComment(const char *comment)
Add a comment.
tinyxml2::XMLHandle::ToDeclaration
XMLDeclaration * ToDeclaration()
Safe cast to XMLDeclaration. This can return null.
Definition: tinyxml2.h:2116
tinyxml2::XMLNode::Accept
virtual bool Accept(XMLVisitor *visitor) const =0
tinyxml2::XMLNode::GetLineNum
int GetLineNum() const
Gets the line number the node is in, if the document was parsed from a file.
Definition: tinyxml2.h:751
tinyxml2::XMLElement::SetText
void SetText(const char *inText)
tinyxml2::XMLText
Definition: tinyxml2.h:991
tinyxml2::XMLElement::ToElement
virtual XMLElement * ToElement()
Safely cast to an Element, or null.
Definition: tinyxml2.h:1276
tinyxml2::XMLNode::InsertEndChild
XMLNode * InsertEndChild(XMLNode *addThis)
tinyxml2::XMLElement::QueryInt64Attribute
XMLError QueryInt64Attribute(const char *name, int64_t *value) const
See QueryIntAttribute()
Definition: tinyxml2.h:1360
tinyxml2::XMLElement::QueryUnsigned64Text
XMLError QueryUnsigned64Text(uint64_t *uval) const
See QueryIntText()
tinyxml2::XMLDocument::NewComment
XMLComment * NewComment(const char *comment)
tinyxml2::XMLText::Accept
virtual bool Accept(XMLVisitor *visitor) const
tinyxml2::XMLHandle::FirstChildElement
XMLHandle FirstChildElement(const char *name=0)
Get the first child element of this handle.
Definition: tinyxml2.h:2071
tinyxml2::XMLPrinter::PushText
void PushText(unsigned value)
Add a text node from an unsigned.
tinyxml2::XMLAttribute::SetAttribute
void SetAttribute(int64_t value)
Set the attribute to value.
tinyxml2::XMLPrinter::ClearBuffer
void ClearBuffer(bool resetToFirstElement=true)
Definition: tinyxml2.h:2317
tinyxml2::XMLElement::QueryInt64Text
XMLError QueryInt64Text(int64_t *uval) const
See QueryIntText()
tinyxml2::XMLElement::QueryUnsigned64Attribute
XMLError QueryUnsigned64Attribute(const char *name, uint64_t *value) const
See QueryIntAttribute()
Definition: tinyxml2.h:1369
tinyxml2::XMLUnknown
Definition: tinyxml2.h:1105
tinyxml2::XMLAttribute::QueryDoubleValue
XMLError QueryDoubleValue(double *value) const
See QueryIntValue.
tinyxml2::XMLElement::IntAttribute
int IntAttribute(const char *name, int defaultValue=0) const
tinyxml2::XMLElement::FloatAttribute
float FloatAttribute(const char *name, float defaultValue=0) const
See IntAttribute()
tinyxml2::XMLHandle::operator=
XMLHandle & operator=(const XMLHandle &ref)
Assignment.
Definition: tinyxml2.h:2061
tinyxml2::XMLDocument::NewElement
XMLElement * NewElement(const char *name)
tinyxml2::XMLUnknown::ShallowClone
virtual XMLNode * ShallowClone(XMLDocument *document) const
tinyxml2::XMLAttribute::QueryUnsigned64Value
XMLError QueryUnsigned64Value(uint64_t *value) const
See QueryIntValue.
tinyxml2::XMLNode::ShallowEqual
virtual bool ShallowEqual(const XMLNode *compare) const =0
tinyxml2::XMLElement::InsertNewChildElement
XMLElement * InsertNewChildElement(const char *name)
tinyxml2::XMLComment::ToComment
virtual XMLComment * ToComment()
Safely cast to a Comment, or null.
Definition: tinyxml2.h:1034
tinyxml2::XMLVisitor::Visit
virtual bool Visit(const XMLUnknown &)
Visit an unknown node.
Definition: tinyxml2.h:516
tinyxml2::XMLAttribute::SetAttribute
void SetAttribute(float value)
Set the attribute to value.
tinyxml2::XMLNode::PreviousSibling
const XMLNode * PreviousSibling() const
Get the previous (left) sibling node of this node.
Definition: tinyxml2.h:804
tinyxml2::XMLElement::SetAttribute
void SetAttribute(const char *name, uint64_t value)
Sets the named attribute to value.
Definition: tinyxml2.h:1482
tinyxml2::XMLPrinter::PushText
void PushText(double value)
Add a text node from a double.
tinyxml2::XMLElement::InsertNewUnknown
XMLUnknown * InsertNewUnknown(const char *text)
See InsertNewChildElement()
tinyxml2::XMLNode::LastChildElement
const XMLElement * LastChildElement(const char *name=0) const
tinyxml2::XMLDocument::DeleteNode
void DeleteNode(XMLNode *node)
tinyxml2::XMLText::ShallowClone
virtual XMLNode * ShallowClone(XMLDocument *document) const
tinyxml2::XMLElement::Int64Text
int64_t Int64Text(int64_t defaultValue=0) const
See QueryIntText()
tinyxml2::XMLNode::Parent
const XMLNode * Parent() const
Get the parent of this node on the DOM.
Definition: tinyxml2.h:754
tinyxml2::XMLElement::Name
const char * Name() const
Get the name of an element (which is the Value() of the node.)
Definition: tinyxml2.h:1268
tinyxml2::XMLNode::DeepClone
XMLNode * DeepClone(XMLDocument *target) const
tinyxml2::XMLAttribute::SetAttribute
void SetAttribute(unsigned value)
Set the attribute to value.
tinyxml2::XMLHandle::ToUnknown
XMLUnknown * ToUnknown()
Safe cast to XMLUnknown. This can return null.
Definition: tinyxml2.h:2112
tinyxml2::XMLAttribute::FloatValue
float FloatValue() const
Query as a float. See IntValue()
Definition: tinyxml2.h:1198
tinyxml2::XMLDeclaration::ShallowEqual
virtual bool ShallowEqual(const XMLNode *compare) const
tinyxml2::XMLDocument::NewUnknown
XMLUnknown * NewUnknown(const char *text)
tinyxml2::XMLDocument::SetBOM
void SetBOM(bool useBOM)
Definition: tinyxml2.h:1798
tinyxml2::XMLAttribute::Value
const char * Value() const
The value of the attribute.
tinyxml2::XMLDocument::Parse
XMLError Parse(const char *xml, size_t nBytes=static_cast< size_t >(-1))
tinyxml2::XMLPrinter::Visit
virtual bool Visit(const XMLUnknown &unknown)
Visit an unknown node.
tinyxml2::XMLElement::SetAttribute
void SetAttribute(const char *name, double value)
Sets the named attribute to value.
Definition: tinyxml2.h:1493
tinyxml2::XMLDeclaration::Accept
virtual bool Accept(XMLVisitor *visitor) const
tinyxml2::XMLVisitor::VisitEnter
virtual bool VisitEnter(const XMLDocument &)
Visit a document.
Definition: tinyxml2.h:486
tinyxml2::XMLNode::LastChild
const XMLNode * LastChild() const
Get the last child node, or null if none exists.
Definition: tinyxml2.h:786
tinyxml2::XMLDocument
Definition: tinyxml2.h:1712
tinyxml2::XMLElement::QueryStringAttribute
XMLError QueryStringAttribute(const char *name, const char **value) const
See QueryIntAttribute()
Definition: tinyxml2.h:1403
tinyxml2::XMLHandle::PreviousSiblingElement
XMLHandle PreviousSiblingElement(const char *name=0)
Get the previous sibling element of this handle.
Definition: tinyxml2.h:2087
tinyxml2::XMLHandle::LastChildElement
XMLHandle LastChildElement(const char *name=0)
Get the last child element of this handle.
Definition: tinyxml2.h:2079
tinyxml2::XMLComment::ShallowEqual
virtual bool ShallowEqual(const XMLNode *compare) const
tinyxml2::XMLConstHandle
Definition: tinyxml2.h:2130
tinyxml2::XMLPrinter::PushText
void PushText(int64_t value)
Add a text node from a signed 64bit integer.
tinyxml2::XMLHandle::LastChild
XMLHandle LastChild()
Get the last child of this handle.
Definition: tinyxml2.h:2075
tinyxml2::XMLComment::Accept
virtual bool Accept(XMLVisitor *visitor) const
tinyxml2::XMLDocument::DeepCopy
void DeepCopy(XMLDocument *target) const
tinyxml2::XMLAttribute::QueryBoolValue
XMLError QueryBoolValue(bool *value) const
See QueryIntValue.
tinyxml2::XMLElement::InsertNewComment
XMLComment * InsertNewComment(const char *comment)
See InsertNewChildElement()
tinyxml2::XMLAttribute::Name
const char * Name() const
The name of the attribute.
tinyxml2::XMLDocument::NewDeclaration
XMLDeclaration * NewDeclaration(const char *text=0)
tinyxml2::XMLNode::FirstChildElement
const XMLElement * FirstChildElement(const char *name=0) const
tinyxml2::XMLElement::ShallowClone
virtual XMLNode * ShallowClone(XMLDocument *document) const
tinyxml2::XMLHandle::FirstChild
XMLHandle FirstChild()
Get the first child of this handle.
Definition: tinyxml2.h:2067
tinyxml2::XMLElement::SetAttribute
void SetAttribute(const char *name, float value)
Sets the named attribute to value.
Definition: tinyxml2.h:1498
tinyxml2::XMLHandle::XMLHandle
XMLHandle(XMLNode *node)
Create a handle from any node (at any depth of the tree.) This can be a null pointer.
Definition: tinyxml2.h:2052
tinyxml2::XMLText::SetCData
void SetCData(bool isCData)
Declare whether this should be CDATA or standard text.
Definition: tinyxml2.h:1004
tinyxml2::XMLPrinter::Visit
virtual bool Visit(const XMLDeclaration &declaration)
Visit a declaration.
tinyxml2::XMLAttribute::SetAttribute
void SetAttribute(int value)
Set the attribute to value.
tinyxml2::XMLNode::NoChildren
bool NoChildren() const
Returns true if this node has no children.
Definition: tinyxml2.h:763
tinyxml2::XMLDocument::ToDocument
virtual XMLDocument * ToDocument()
Safely cast to a Document, or null.
Definition: tinyxml2.h:1726
tinyxml2::XMLVisitor::VisitExit
virtual bool VisitExit(const XMLDocument &)
Visit a document.
Definition: tinyxml2.h:490
tinyxml2::XMLDeclaration
Definition: tinyxml2.h:1070
tinyxml2::XMLNode::InsertAfterChild
XMLNode * InsertAfterChild(XMLNode *afterThis, XMLNode *addThis)
tinyxml2::XMLNode::NextSibling
const XMLNode * NextSibling() const
Get the next (right) sibling node of this node.
Definition: tinyxml2.h:820
tinyxml2::XMLElement::BoolText
bool BoolText(bool defaultValue=false) const
See QueryIntText()
tinyxml2::XMLAttribute::UnsignedValue
unsigned UnsignedValue() const
Query as an unsigned integer. See IntValue()
Definition: tinyxml2.h:1180
tinyxml2::XMLPrinter::VisitEnter
virtual bool VisitEnter(const XMLElement &element, const XMLAttribute *attribute)
Visit an element.
tinyxml2::XMLElement::SetText
void SetText(bool value)
Convenience method for setting text inside an element. See SetText() for important limitations.
tinyxml2::XMLNode::ShallowClone
virtual XMLNode * ShallowClone(XMLDocument *document) const =0
tinyxml2::XMLHandle::NextSiblingElement
XMLHandle NextSiblingElement(const char *name=0)
Get the next sibling element of this handle.
Definition: tinyxml2.h:2095
tinyxml2::XMLHandle::ToText
XMLText * ToText()
Safe cast to XMLText. This can return null.
Definition: tinyxml2.h:2108
tinyxml2::XMLPrinter::CStrSize
int CStrSize() const
Definition: tinyxml2.h:2310
tinyxml2::XMLNode::PreviousSiblingElement
const XMLElement * PreviousSiblingElement(const char *name=0) const
Get the previous (left) sibling element of this node, with an optionally supplied name.
tinyxml2::XMLNode::SetValue
void SetValue(const char *val, bool staticMem=false)
tinyxml2::XMLPrinter::CloseElement
virtual void CloseElement(bool compactMode=false)
If streaming, close the Element.
tinyxml2::XMLVisitor
Definition: tinyxml2.h:481
tinyxml2::XMLElement::SetText
void SetText(float value)
Convenience method for setting text inside an element. See SetText() for important limitations.
tinyxml2::XMLAttribute::SetAttribute
void SetAttribute(bool value)
Set the attribute to value.
tinyxml2::XMLElement::Attribute
const char * Attribute(const char *name, const char *value=0) const
tinyxml2::XMLPrinter::VisitExit
virtual bool VisitExit(const XMLElement &element)
Visit an element.
tinyxml2::XMLNode::GetDocument
const XMLDocument * GetDocument() const
Get the XMLDocument that owns this XMLNode.
Definition: tinyxml2.h:680
tinyxml2::XMLPrinter::PushText
void PushText(bool value)
Add a text node from a bool.
tinyxml2::XMLPrinter::Visit
virtual bool Visit(const XMLText &text)
Visit a text node.
tinyxml2::XMLElement::DoubleText
double DoubleText(double defaultValue=0) const
See QueryIntText()
tinyxml2::XMLNode::DeleteChildren
void DeleteChildren()
tinyxml2::XMLElement::QueryIntText
XMLError QueryIntText(int *ival) const
tinyxml2::XMLDocument::SaveFile
XMLError SaveFile(const char *filename, bool compact=false)
tinyxml2::XMLText::ToText
virtual XMLText * ToText()
Safely cast to Text, or null.
Definition: tinyxml2.h:996
tinyxml2::XMLElement::FindAttribute
const XMLAttribute * FindAttribute(const char *name) const
Query a specific attribute in the list.
tinyxml2::XMLDocument::ShallowClone
virtual XMLNode * ShallowClone(XMLDocument *) const
Definition: tinyxml2.h:1919
tinyxml2::XMLElement::SetAttribute
void SetAttribute(const char *name, int64_t value)
Sets the named attribute to value.
Definition: tinyxml2.h:1476
tinyxml2::XMLDocument::ErrorLineNum
int ErrorLineNum() const
Return the line where the error occurred, or zero if unknown.
Definition: tinyxml2.h:1896
tinyxml2::XMLPrinter::PushText
void PushText(const char *text, bool cdata=false)
Add a text node.
tinyxml2::XMLPrinter::PushText
void PushText(int value)
Add a text node from an integer.
tinyxml2::XMLDocument::Print
void Print(XMLPrinter *streamer=0) const
tinyxml2::XMLDocument::PrintError
void PrintError() const
A (trivial) utility function that prints the ErrorStr() to stdout.
tinyxml2::XMLPrinter::VisitExit
virtual bool VisitExit(const XMLDocument &)
Visit a document.
Definition: tinyxml2.h:2286
tinyxml2::XMLElement::SetText
void SetText(int64_t value)
Convenience method for setting text inside an element. See SetText() for important limitations.
tinyxml2::XMLVisitor::VisitEnter
virtual bool VisitEnter(const XMLElement &, const XMLAttribute *)
Visit an element.
Definition: tinyxml2.h:495
tinyxml2::XMLPrinter
Definition: tinyxml2.h:2234
tinyxml2::XMLHandle::ToNode
XMLNode * ToNode()
Safe cast to XMLNode. This can return null.
Definition: tinyxml2.h:2100
tinyxml2::XMLUnknown::ToUnknown
virtual XMLUnknown * ToUnknown()
Safely cast to an Unknown, or null.
Definition: tinyxml2.h:1108
tinyxml2::XMLElement::QueryDoubleAttribute
XMLError QueryDoubleAttribute(const char *name, double *value) const
See QueryIntAttribute()
Definition: tinyxml2.h:1386
tinyxml2::XMLPrinter::Visit
virtual bool Visit(const XMLComment &comment)
Visit a comment node.
tinyxml2::XMLElement::SetAttribute
void SetAttribute(const char *name, bool value)
Sets the named attribute to value.
Definition: tinyxml2.h:1488
tinyxml2::XMLText::CData
bool CData() const
Returns true if this is a CDATA text element.
Definition: tinyxml2.h:1008
tinyxml2::XMLDeclaration::ToDeclaration
virtual XMLDeclaration * ToDeclaration()
Safely cast to a Declaration, or null.
Definition: tinyxml2.h:1073
tinyxml2::XMLDocument::ErrorStr
const char * ErrorStr() const
tinyxml2::XMLUnknown::ShallowEqual
virtual bool ShallowEqual(const XMLNode *compare) const
tinyxml2::XMLPrinter::PushAttribute
void PushAttribute(const char *name, const char *value)
If streaming, add an attribute to an open element.
tinyxml2::XMLDocument::Error
bool Error() const
Return true if there was an error parsing the document.
Definition: tinyxml2.h:1877
tinyxml2::XMLElement::Accept
virtual bool Accept(XMLVisitor *visitor) const
tinyxml2::XMLNode::ToDeclaration
virtual XMLDeclaration * ToDeclaration()
Safely cast to a Declaration, or null.
Definition: tinyxml2.h:707
tinyxml2::XMLVisitor::Visit
virtual bool Visit(const XMLText &)
Visit a text node.
Definition: tinyxml2.h:508
tinyxml2::XMLAttribute::SetAttribute
void SetAttribute(const char *value)
Set the attribute to a string value.
tinyxml2::XMLElement::SetText
void SetText(unsigned value)
Convenience method for setting text inside an element. See SetText() for important limitations.
tinyxml2::XMLDocument::LoadFile
XMLError LoadFile(const char *filename)
tinyxml2::XMLPrinter::PushText
void PushText(uint64_t value)
Add a text node from an unsigned 64bit integer.
tinyxml2::XMLElement::GetText
const char * GetText() const
tinyxml2::XMLElement::SetText
void SetText(int value)
Convenience method for setting text inside an element. See SetText() for important limitations.
tinyxml2::XMLNode::DeleteChild
void DeleteChild(XMLNode *node)
tinyxml2::XMLDocument::NewText
XMLText * NewText(const char *text)
tinyxml2::XMLVisitor::VisitExit
virtual bool VisitExit(const XMLElement &)
Visit an element.
Definition: tinyxml2.h:499
tinyxml2::XMLHandle
Definition: tinyxml2.h:2049
tinyxml2::XMLElement::UnsignedText
unsigned UnsignedText(unsigned defaultValue=0) const
See QueryIntText()
tinyxml2::XMLPrinter::CStr
const char * CStr() const
Definition: tinyxml2.h:2302
tinyxml2::XMLDeclaration::ShallowClone
virtual XMLNode * ShallowClone(XMLDocument *document) const
tinyxml2::XMLElement::QueryAttribute
XMLError QueryAttribute(const char *name, int *value) const
Definition: tinyxml2.h:1431
tinyxml2::XMLPrinter::VisitEnter
virtual bool VisitEnter(const XMLDocument &)
Visit a document.
tinyxml2::XMLNode::ToText
virtual XMLText * ToText()
Safely cast to Text, or null.
Definition: tinyxml2.h:695
tinyxml2::XMLElement::Unsigned64Attribute
uint64_t Unsigned64Attribute(const char *name, uint64_t defaultValue=0) const
See IntAttribute()
tinyxml2::XMLElement::QueryBoolText
XMLError QueryBoolText(bool *bval) const
See QueryIntText()
tinyxml2::XMLElement::QueryFloatText
XMLError QueryFloatText(float *fval) const
See QueryIntText()
tinyxml2::XMLNode::NextSiblingElement
const XMLElement * NextSiblingElement(const char *name=0) const
Get the next (right) sibling element of this node, with an optionally supplied name.
tinyxml2::XMLElement::QueryUnsignedAttribute
XMLError QueryUnsignedAttribute(const char *name, unsigned int *value) const
See QueryIntAttribute()
Definition: tinyxml2.h:1351
tinyxml2::XMLDocument::ShallowEqual
virtual bool ShallowEqual(const XMLNode *) const
Definition: tinyxml2.h:1922
tinyxml2::XMLNode::ToUnknown
virtual XMLUnknown * ToUnknown()
Safely cast to an Unknown, or null.
Definition: tinyxml2.h:711
tinyxml2::XMLDocument::SaveFile
XMLError SaveFile(FILE *fp, bool compact=false)
tinyxml2::XMLElement::DoubleAttribute
double DoubleAttribute(const char *name, double defaultValue=0) const
See IntAttribute()
tinyxml2::XMLUnknown::Accept
virtual bool Accept(XMLVisitor *visitor) const
tinyxml2::XMLElement::BoolAttribute
bool BoolAttribute(const char *name, bool defaultValue=false) const
See IntAttribute()
tinyxml2::XMLAttribute::GetLineNum
int GetLineNum() const
Gets the line number the attribute is in, if the document was parsed from a file.
Definition: tinyxml2.h:1150
tinyxml2::XMLAttribute::Next
const XMLAttribute * Next() const
The next attribute in the list.
Definition: tinyxml2.h:1153
tinyxml2::XMLElement::SetText
void SetText(double value)
Convenience method for setting text inside an element. See SetText() for important limitations.
tinyxml2::XMLAttribute
Definition: tinyxml2.h:1140
tinyxml2::XMLHandle::PreviousSibling
XMLHandle PreviousSibling()
Get the previous sibling of this handle.
Definition: tinyxml2.h:2083
tinyxml2::XMLPrinter::PushHeader
void PushHeader(bool writeBOM, bool writeDeclaration)
tinyxml2::XMLNode::FirstChild
const XMLNode * FirstChild() const
Get the first child node, or null if none exists.
Definition: tinyxml2.h:768
tinyxml2::XMLElement::FirstAttribute
const XMLAttribute * FirstAttribute() const
Return the first attribute in the list.
Definition: tinyxml2.h:1509
tinyxml2::XMLDocument::Accept
virtual bool Accept(XMLVisitor *visitor) const
tinyxml2::XMLElement::SetText
void SetText(uint64_t value)
Convenience method for setting text inside an element. See SetText() for important limitations.
tinyxml2::XMLText::ShallowEqual
virtual bool ShallowEqual(const XMLNode *compare) const
tinyxml2::XMLNode::InsertFirstChild
XMLNode * InsertFirstChild(XMLNode *addThis)
tinyxml2::XMLHandle::XMLHandle
XMLHandle(XMLNode &node)
Create a handle from a node.
Definition: tinyxml2.h:2055
tinyxml2::XMLAttribute::SetAttribute
void SetAttribute(uint64_t value)
Set the attribute to value.
tinyxml2::XMLDocument::XMLDocument
XMLDocument(bool processEntities=true, Whitespace whitespaceMode=PRESERVE_WHITESPACE)
constructor
tinyxml2::XMLDocument::ErrorID
XMLError ErrorID() const
Return the errorID.
Definition: tinyxml2.h:1881
tinyxml2::XMLElement::SetAttribute
void SetAttribute(const char *name, const char *value)
Sets the named attribute to value.
Definition: tinyxml2.h:1460
tinyxml2::XMLElement::Int64Attribute
int64_t Int64Attribute(const char *name, int64_t defaultValue=0) const
See IntAttribute()
tinyxml2::XMLComment
Definition: tinyxml2.h:1031
tinyxml2::XMLPrinter::PrintSpace
virtual void PrintSpace(int depth)
tinyxml2::XMLNode::GetDocument
XMLDocument * GetDocument()
Get the XMLDocument that owns this XMLNode.
Definition: tinyxml2.h:685
tinyxml2::XMLElement::InsertNewText
XMLText * InsertNewText(const char *text)
See InsertNewChildElement()
tinyxml2::XMLDocument::RootElement
XMLElement * RootElement()
Definition: tinyxml2.h:1805
tinyxml2::XMLElement::ShallowEqual
virtual bool ShallowEqual(const XMLNode *compare) const
tinyxml2::XMLDocument::LoadFile
XMLError LoadFile(FILE *)
tinyxml2::XMLElement
Definition: tinyxml2.h:1264
tinyxml2::XMLPrinter::PushText
void PushText(float value)
Add a text node from a float.
tinyxml2::XMLNode::ToComment
virtual XMLComment * ToComment()
Safely cast to a Comment, or null.
Definition: tinyxml2.h:699
tinyxml2::XMLAttribute::QueryInt64Value
XMLError QueryInt64Value(int64_t *value) const
See QueryIntValue.
tinyxml2::XMLAttribute::QueryUnsignedValue
XMLError QueryUnsignedValue(unsigned int *value) const
See QueryIntValue.
tinyxml2::XMLVisitor::Visit
virtual bool Visit(const XMLComment &)
Visit a comment node.
Definition: tinyxml2.h:512
tinyxml2::XMLElement::QueryBoolAttribute
XMLError QueryBoolAttribute(const char *name, bool *value) const
See QueryIntAttribute()
Definition: tinyxml2.h:1378
tinyxml2::XMLAttribute::BoolValue
bool BoolValue() const
Query as a boolean. See IntValue()
Definition: tinyxml2.h:1186
tinyxml2::XMLElement::QueryIntAttribute
XMLError QueryIntAttribute(const char *name, int *value) const
Definition: tinyxml2.h:1342
tinyxml2::XMLAttribute::QueryIntValue
XMLError QueryIntValue(int *value) const
tinyxml2::XMLNode::GetUserData
void * GetUserData() const
Definition: tinyxml2.h:945
tinyxml2::XMLHandle::NextSibling
XMLHandle NextSibling()
Get the next sibling of this handle.
Definition: tinyxml2.h:2091
tinyxml2::XMLDocument::HasBOM
bool HasBOM() const
Definition: tinyxml2.h:1793
tinyxml2::XMLElement::SetAttribute
void SetAttribute(const char *name, unsigned value)
Sets the named attribute to value.
Definition: tinyxml2.h:1470
tinyxml2::XMLAttribute::SetAttribute
void SetAttribute(double value)
Set the attribute to value.
tinyxml2::XMLElement::QueryFloatAttribute
XMLError QueryFloatAttribute(const char *name, float *value) const
See QueryIntAttribute()
Definition: tinyxml2.h:1394
tinyxml2::XMLElement::QueryDoubleText
XMLError QueryDoubleText(double *dval) const
See QueryIntText()
tinyxml2::XMLElement::QueryUnsignedText
XMLError QueryUnsignedText(unsigned *uval) const
See QueryIntText()
tinyxml2::XMLHandle::ToElement
XMLElement * ToElement()
Safe cast to XMLElement. This can return null.
Definition: tinyxml2.h:2104