TinyXML-2  2.1.0
 All Classes Functions Pages
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 
18 2. Altered source versions must be plainly marked as such, and
19 must not be misrepresented as being the original software.
20 
21 3. This notice may not be removed or altered from any source
22 distribution.
23 */
24 
25 #ifndef TINYXML2_INCLUDED
26 #define TINYXML2_INCLUDED
27 
28 #if defined(ANDROID_NDK) || defined(__BORLANDC__)
29 # include <ctype.h>
30 # include <limits.h>
31 # include <stdio.h>
32 # include <stdlib.h>
33 # include <string.h>
34 # include <stdarg.h>
35 #else
36 # include <cctype>
37 # include <climits>
38 # include <cstdio>
39 # include <cstdlib>
40 # include <cstring>
41 # include <cstdarg>
42 #endif
43 
44 /*
45  TODO: intern strings instead of allocation.
46 */
47 /*
48  gcc:
49  g++ -Wall -DDEBUG tinyxml2.cpp xmltest.cpp -o gccxmltest.exe
50 
51  Formatting, Artistic Style:
52  AStyle.exe --style=1tbs --indent-switches --break-closing-brackets --indent-preprocessor tinyxml2.cpp tinyxml2.h
53 */
54 
55 #if defined( _DEBUG ) || defined( DEBUG ) || defined (__DEBUG__)
56 # ifndef DEBUG
57 # define DEBUG
58 # endif
59 #endif
60 
61 #ifdef _MSC_VER
62 # pragma warning(push)
63 # pragma warning(disable: 4251)
64 #endif
65 
66 #ifdef _WIN32
67 # ifdef TINYXML2_EXPORT
68 # define TINYXML2_LIB __declspec(dllexport)
69 # elif defined(TINYXML2_IMPORT)
70 # define TINYXML2_LIB __declspec(dllimport)
71 # else
72 # define TINYXML2_LIB
73 # endif
74 #else
75 # define TINYXML2_LIB
76 #endif
77 
78 
79 #if defined(DEBUG)
80 # if defined(_MSC_VER)
81 # define TIXMLASSERT( x ) if ( !(x)) { __debugbreak(); } //if ( !(x)) WinDebugBreak()
82 # elif defined (ANDROID_NDK)
83 # include <android/log.h>
84 # define TIXMLASSERT( x ) if ( !(x)) { __android_log_assert( "assert", "grinliz", "ASSERT in '%s' at %d.", __FILE__, __LINE__ ); }
85 # else
86 # include <assert.h>
87 # define TIXMLASSERT assert
88 # endif
89 # else
90 # define TIXMLASSERT( x ) {}
91 #endif
92 
93 
94 #if defined(_MSC_VER) && (_MSC_VER >= 1400 )
95 // Microsoft visual studio, version 2005 and higher.
96 /*int _snprintf_s(
97  char *buffer,
98  size_t sizeOfBuffer,
99  size_t count,
100  const char *format [,
101  argument] ...
102 );*/
103 inline int TIXML_SNPRINTF( char* buffer, size_t size, const char* format, ... )
104 {
105  va_list va;
106  va_start( va, format );
107  int result = vsnprintf_s( buffer, size, _TRUNCATE, format, va );
108  va_end( va );
109  return result;
110 }
111 #define TIXML_SSCANF sscanf_s
112 #else
113 // GCC version 3 and higher
114 //#warning( "Using sn* functions." )
115 #define TIXML_SNPRINTF snprintf
116 #define TIXML_SSCANF sscanf
117 #endif
118 
119 /* Versioning, past 1.0.14:
120  http://semver.org/
121 */
122 static const int TIXML2_MAJOR_VERSION = 2;
123 static const int TIXML2_MINOR_VERSION = 1;
124 static const int TIXML2_PATCH_VERSION = 0;
125 
126 namespace tinyxml2
127 {
128 class XMLDocument;
129 class XMLElement;
130 class XMLAttribute;
131 class XMLComment;
132 class XMLText;
133 class XMLDeclaration;
134 class XMLUnknown;
135 class XMLPrinter;
136 
137 /*
138  A class that wraps strings. Normally stores the start and end
139  pointers into the XML file itself, and will apply normalization
140  and entity translation if actually read. Can also store (and memory
141  manage) a traditional char[]
142 */
143 class StrPair
144 {
145 public:
146  enum {
147  NEEDS_ENTITY_PROCESSING = 0x01,
148  NEEDS_NEWLINE_NORMALIZATION = 0x02,
149  COLLAPSE_WHITESPACE = 0x04,
150 
151  TEXT_ELEMENT = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION,
152  TEXT_ELEMENT_LEAVE_ENTITIES = NEEDS_NEWLINE_NORMALIZATION,
153  ATTRIBUTE_NAME = 0,
154  ATTRIBUTE_VALUE = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION,
155  ATTRIBUTE_VALUE_LEAVE_ENTITIES = NEEDS_NEWLINE_NORMALIZATION,
156  COMMENT = NEEDS_NEWLINE_NORMALIZATION
157  };
158 
159  StrPair() : _flags( 0 ), _start( 0 ), _end( 0 ) {}
160  ~StrPair();
161 
162  void Set( char* start, char* end, int flags ) {
163  Reset();
164  _start = start;
165  _end = end;
166  _flags = flags | NEEDS_FLUSH;
167  }
168 
169  const char* GetStr();
170 
171  bool Empty() const {
172  return _start == _end;
173  }
174 
175  void SetInternedStr( const char* str ) {
176  Reset();
177  _start = const_cast<char*>(str);
178  }
179 
180  void SetStr( const char* str, int flags=0 );
181 
182  char* ParseText( char* in, const char* endTag, int strFlags );
183  char* ParseName( char* in );
184 
185 private:
186  void Reset();
187  void CollapseWhitespace();
188 
189  enum {
190  NEEDS_FLUSH = 0x100,
191  NEEDS_DELETE = 0x200
192  };
193 
194  // After parsing, if *_end != 0, it can be set to zero.
195  int _flags;
196  char* _start;
197  char* _end;
198 };
199 
200 
201 /*
202  A dynamic array of Plain Old Data. Doesn't support constructors, etc.
203  Has a small initial memory pool, so that low or no usage will not
204  cause a call to new/delete
205 */
206 template <class T, int INIT>
207 class DynArray
208 {
209 public:
210  DynArray< T, INIT >() {
211  _mem = _pool;
212  _allocated = INIT;
213  _size = 0;
214  }
215 
216  ~DynArray() {
217  if ( _mem != _pool ) {
218  delete [] _mem;
219  }
220  }
221 
222  void Clear() {
223  _size = 0;
224  }
225 
226  void Push( T t ) {
227  EnsureCapacity( _size+1 );
228  _mem[_size++] = t;
229  }
230 
231  T* PushArr( int count ) {
232  EnsureCapacity( _size+count );
233  T* ret = &_mem[_size];
234  _size += count;
235  return ret;
236  }
237 
238  T Pop() {
239  return _mem[--_size];
240  }
241 
242  void PopArr( int count ) {
243  TIXMLASSERT( _size >= count );
244  _size -= count;
245  }
246 
247  bool Empty() const {
248  return _size == 0;
249  }
250 
251  T& operator[](int i) {
252  TIXMLASSERT( i>= 0 && i < _size );
253  return _mem[i];
254  }
255 
256  const T& operator[](int i) const {
257  TIXMLASSERT( i>= 0 && i < _size );
258  return _mem[i];
259  }
260 
261  const T& PeekTop() const {
262  TIXMLASSERT( _size > 0 );
263  return _mem[ _size - 1];
264  }
265 
266  int Size() const {
267  return _size;
268  }
269 
270  int Capacity() const {
271  return _allocated;
272  }
273 
274  const T* Mem() const {
275  return _mem;
276  }
277 
278  T* Mem() {
279  return _mem;
280  }
281 
282 private:
283  void EnsureCapacity( int cap ) {
284  if ( cap > _allocated ) {
285  int newAllocated = cap * 2;
286  T* newMem = new T[newAllocated];
287  memcpy( newMem, _mem, sizeof(T)*_size ); // warning: not using constructors, only works for PODs
288  if ( _mem != _pool ) {
289  delete [] _mem;
290  }
291  _mem = newMem;
292  _allocated = newAllocated;
293  }
294  }
295 
296  T* _mem;
297  T _pool[INIT];
298  int _allocated; // objects allocated
299  int _size; // number objects in use
300 };
301 
302 
303 /*
304  Parent virtual class of a pool for fast allocation
305  and deallocation of objects.
306 */
307 class MemPool
308 {
309 public:
310  MemPool() {}
311  virtual ~MemPool() {}
312 
313  virtual int ItemSize() const = 0;
314  virtual void* Alloc() = 0;
315  virtual void Free( void* ) = 0;
316  virtual void SetTracked() = 0;
317 };
318 
319 
320 /*
321  Template child class to create pools of the correct type.
322 */
323 template< int SIZE >
324 class MemPoolT : public MemPool
325 {
326 public:
327  MemPoolT() : _root(0), _currentAllocs(0), _nAllocs(0), _maxAllocs(0), _nUntracked(0) {}
328  ~MemPoolT() {
329  // Delete the blocks.
330  for( int i=0; i<_blockPtrs.Size(); ++i ) {
331  delete _blockPtrs[i];
332  }
333  }
334 
335  virtual int ItemSize() const {
336  return SIZE;
337  }
338  int CurrentAllocs() const {
339  return _currentAllocs;
340  }
341 
342  virtual void* Alloc() {
343  if ( !_root ) {
344  // Need a new block.
345  Block* block = new Block();
346  _blockPtrs.Push( block );
347 
348  for( int i=0; i<COUNT-1; ++i ) {
349  block->chunk[i].next = &block->chunk[i+1];
350  }
351  block->chunk[COUNT-1].next = 0;
352  _root = block->chunk;
353  }
354  void* result = _root;
355  _root = _root->next;
356 
357  ++_currentAllocs;
358  if ( _currentAllocs > _maxAllocs ) {
359  _maxAllocs = _currentAllocs;
360  }
361  _nAllocs++;
362  _nUntracked++;
363  return result;
364  }
365  virtual void Free( void* mem ) {
366  if ( !mem ) {
367  return;
368  }
369  --_currentAllocs;
370  Chunk* chunk = (Chunk*)mem;
371 #ifdef DEBUG
372  memset( chunk, 0xfe, sizeof(Chunk) );
373 #endif
374  chunk->next = _root;
375  _root = chunk;
376  }
377  void Trace( const char* name ) {
378  printf( "Mempool %s watermark=%d [%dk] current=%d size=%d nAlloc=%d blocks=%d\n",
379  name, _maxAllocs, _maxAllocs*SIZE/1024, _currentAllocs, SIZE, _nAllocs, _blockPtrs.Size() );
380  }
381 
382  void SetTracked() {
383  _nUntracked--;
384  }
385 
386  int Untracked() const {
387  return _nUntracked;
388  }
389 
390  // This number is perf sensitive. 4k seems like a good tradeoff on my machine.
391  // The test file is large, 170k.
392  // Release: VS2010 gcc(no opt)
393  // 1k: 4000
394  // 2k: 4000
395  // 4k: 3900 21000
396  // 16k: 5200
397  // 32k: 4300
398  // 64k: 4000 21000
399  enum { COUNT = (4*1024)/SIZE }; // Some compilers do not accept to use COUNT in private part if COUNT is private
400 
401 private:
402  union Chunk {
403  Chunk* next;
404  char mem[SIZE];
405  };
406  struct Block {
407  Chunk chunk[COUNT];
408  };
409  DynArray< Block*, 10 > _blockPtrs;
410  Chunk* _root;
411 
412  int _currentAllocs;
413  int _nAllocs;
414  int _maxAllocs;
415  int _nUntracked;
416 };
417 
418 
419 
439 class TINYXML2_LIB XMLVisitor
440 {
441 public:
442  virtual ~XMLVisitor() {}
443 
445  virtual bool VisitEnter( const XMLDocument& /*doc*/ ) {
446  return true;
447  }
449  virtual bool VisitExit( const XMLDocument& /*doc*/ ) {
450  return true;
451  }
452 
454  virtual bool VisitEnter( const XMLElement& /*element*/, const XMLAttribute* /*firstAttribute*/ ) {
455  return true;
456  }
458  virtual bool VisitExit( const XMLElement& /*element*/ ) {
459  return true;
460  }
461 
463  virtual bool Visit( const XMLDeclaration& /*declaration*/ ) {
464  return true;
465  }
467  virtual bool Visit( const XMLText& /*text*/ ) {
468  return true;
469  }
471  virtual bool Visit( const XMLComment& /*comment*/ ) {
472  return true;
473  }
475  virtual bool Visit( const XMLUnknown& /*unknown*/ ) {
476  return true;
477  }
478 };
479 
480 
481 /*
482  Utility functionality.
483 */
484 class XMLUtil
485 {
486 public:
487  // Anything in the high order range of UTF-8 is assumed to not be whitespace. This isn't
488  // correct, but simple, and usually works.
489  static const char* SkipWhiteSpace( const char* p ) {
490  while( !IsUTF8Continuation(*p) && isspace( *reinterpret_cast<const unsigned char*>(p) ) ) {
491  ++p;
492  }
493  return p;
494  }
495  static char* SkipWhiteSpace( char* p ) {
496  while( !IsUTF8Continuation(*p) && isspace( *reinterpret_cast<unsigned char*>(p) ) ) {
497  ++p;
498  }
499  return p;
500  }
501  static bool IsWhiteSpace( char p ) {
502  return !IsUTF8Continuation(p) && isspace( static_cast<unsigned char>(p) );
503  }
504 
505  inline static bool IsNameStartChar( unsigned char ch ) {
506  return ( ( ch < 128 ) ? isalpha( ch ) : 1 )
507  || ch == ':'
508  || ch == '_';
509  }
510 
511  inline static bool IsNameChar( unsigned char ch ) {
512  return IsNameStartChar( ch )
513  || isdigit( ch )
514  || ch == '.'
515  || ch == '-';
516  }
517 
518  inline static bool StringEqual( const char* p, const char* q, int nChar=INT_MAX ) {
519  int n = 0;
520  if ( p == q ) {
521  return true;
522  }
523  while( *p && *q && *p == *q && n<nChar ) {
524  ++p;
525  ++q;
526  ++n;
527  }
528  if ( (n == nChar) || ( *p == 0 && *q == 0 ) ) {
529  return true;
530  }
531  return false;
532  }
533 
534  inline static int IsUTF8Continuation( const char p ) {
535  return p & 0x80;
536  }
537 
538  static const char* ReadBOM( const char* p, bool* hasBOM );
539  // p is the starting location,
540  // the UTF-8 value of the entity will be placed in value, and length filled in.
541  static const char* GetCharacterRef( const char* p, char* value, int* length );
542  static void ConvertUTF32ToUTF8( unsigned long input, char* output, int* length );
543 
544  // converts primitive types to strings
545  static void ToStr( int v, char* buffer, int bufferSize );
546  static void ToStr( unsigned v, char* buffer, int bufferSize );
547  static void ToStr( bool v, char* buffer, int bufferSize );
548  static void ToStr( float v, char* buffer, int bufferSize );
549  static void ToStr( double v, char* buffer, int bufferSize );
550 
551  // converts strings to primitive types
552  static bool ToInt( const char* str, int* value );
553  static bool ToUnsigned( const char* str, unsigned* value );
554  static bool ToBool( const char* str, bool* value );
555  static bool ToFloat( const char* str, float* value );
556  static bool ToDouble( const char* str, double* value );
557 };
558 
559 
585 class TINYXML2_LIB XMLNode
586 {
587  friend class XMLDocument;
588  friend class XMLElement;
589 public:
590 
592  const XMLDocument* GetDocument() const {
593  return _document;
594  }
597  return _document;
598  }
599 
601  virtual XMLElement* ToElement() {
602  return 0;
603  }
605  virtual XMLText* ToText() {
606  return 0;
607  }
609  virtual XMLComment* ToComment() {
610  return 0;
611  }
613  virtual XMLDocument* ToDocument() {
614  return 0;
615  }
618  return 0;
619  }
621  virtual XMLUnknown* ToUnknown() {
622  return 0;
623  }
624 
625  virtual const XMLElement* ToElement() const {
626  return 0;
627  }
628  virtual const XMLText* ToText() const {
629  return 0;
630  }
631  virtual const XMLComment* ToComment() const {
632  return 0;
633  }
634  virtual const XMLDocument* ToDocument() const {
635  return 0;
636  }
637  virtual const XMLDeclaration* ToDeclaration() const {
638  return 0;
639  }
640  virtual const XMLUnknown* ToUnknown() const {
641  return 0;
642  }
643 
653  const char* Value() const;
654 
658  void SetValue( const char* val, bool staticMem=false );
659 
661  const XMLNode* Parent() const {
662  return _parent;
663  }
664 
665  XMLNode* Parent() {
666  return _parent;
667  }
668 
670  bool NoChildren() const {
671  return !_firstChild;
672  }
673 
675  const XMLNode* FirstChild() const {
676  return _firstChild;
677  }
678 
679  XMLNode* FirstChild() {
680  return _firstChild;
681  }
682 
686  const XMLElement* FirstChildElement( const char* value=0 ) const;
687 
688  XMLElement* FirstChildElement( const char* value=0 ) {
689  return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->FirstChildElement( value ));
690  }
691 
693  const XMLNode* LastChild() const {
694  return _lastChild;
695  }
696 
697  XMLNode* LastChild() {
698  return const_cast<XMLNode*>(const_cast<const XMLNode*>(this)->LastChild() );
699  }
700 
704  const XMLElement* LastChildElement( const char* value=0 ) const;
705 
706  XMLElement* LastChildElement( const char* value=0 ) {
707  return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->LastChildElement(value) );
708  }
709 
711  const XMLNode* PreviousSibling() const {
712  return _prev;
713  }
714 
715  XMLNode* PreviousSibling() {
716  return _prev;
717  }
718 
720  const XMLElement* PreviousSiblingElement( const char* value=0 ) const ;
721 
722  XMLElement* PreviousSiblingElement( const char* value=0 ) {
723  return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->PreviousSiblingElement( value ) );
724  }
725 
727  const XMLNode* NextSibling() const {
728  return _next;
729  }
730 
731  XMLNode* NextSibling() {
732  return _next;
733  }
734 
736  const XMLElement* NextSiblingElement( const char* value=0 ) const;
737 
738  XMLElement* NextSiblingElement( const char* value=0 ) {
739  return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->NextSiblingElement( value ) );
740  }
741 
749  XMLNode* InsertEndChild( XMLNode* addThis );
750 
751  XMLNode* LinkEndChild( XMLNode* addThis ) {
752  return InsertEndChild( addThis );
753  }
761  XMLNode* InsertFirstChild( XMLNode* addThis );
770  XMLNode* InsertAfterChild( XMLNode* afterThis, XMLNode* addThis );
771 
775  void DeleteChildren();
776 
780  void DeleteChild( XMLNode* node );
781 
791  virtual XMLNode* ShallowClone( XMLDocument* document ) const = 0;
792 
799  virtual bool ShallowEqual( const XMLNode* compare ) const = 0;
800 
823  virtual bool Accept( XMLVisitor* visitor ) const = 0;
824 
825  // internal
826  virtual char* ParseDeep( char*, StrPair* );
827 
828 protected:
829  XMLNode( XMLDocument* );
830  virtual ~XMLNode();
831  XMLNode( const XMLNode& ); // not supported
832  XMLNode& operator=( const XMLNode& ); // not supported
833 
834  XMLDocument* _document;
835  XMLNode* _parent;
836  mutable StrPair _value;
837 
838  XMLNode* _firstChild;
839  XMLNode* _lastChild;
840 
841  XMLNode* _prev;
842  XMLNode* _next;
843 
844 private:
845  MemPool* _memPool;
846  void Unlink( XMLNode* child );
847 };
848 
849 
862 class TINYXML2_LIB XMLText : public XMLNode
863 {
864  friend class XMLBase;
865  friend class XMLDocument;
866 public:
867  virtual bool Accept( XMLVisitor* visitor ) const;
868 
869  virtual XMLText* ToText() {
870  return this;
871  }
872  virtual const XMLText* ToText() const {
873  return this;
874  }
875 
877  void SetCData( bool isCData ) {
878  _isCData = isCData;
879  }
881  bool CData() const {
882  return _isCData;
883  }
884 
885  char* ParseDeep( char*, StrPair* endTag );
886  virtual XMLNode* ShallowClone( XMLDocument* document ) const;
887  virtual bool ShallowEqual( const XMLNode* compare ) const;
888 
889 protected:
890  XMLText( XMLDocument* doc ) : XMLNode( doc ), _isCData( false ) {}
891  virtual ~XMLText() {}
892  XMLText( const XMLText& ); // not supported
893  XMLText& operator=( const XMLText& ); // not supported
894 
895 private:
896  bool _isCData;
897 };
898 
899 
901 class TINYXML2_LIB XMLComment : public XMLNode
902 {
903  friend class XMLDocument;
904 public:
905  virtual XMLComment* ToComment() {
906  return this;
907  }
908  virtual const XMLComment* ToComment() const {
909  return this;
910  }
911 
912  virtual bool Accept( XMLVisitor* visitor ) const;
913 
914  char* ParseDeep( char*, StrPair* endTag );
915  virtual XMLNode* ShallowClone( XMLDocument* document ) const;
916  virtual bool ShallowEqual( const XMLNode* compare ) const;
917 
918 protected:
919  XMLComment( XMLDocument* doc );
920  virtual ~XMLComment();
921  XMLComment( const XMLComment& ); // not supported
922  XMLComment& operator=( const XMLComment& ); // not supported
923 
924 private:
925 };
926 
927 
939 class TINYXML2_LIB XMLDeclaration : public XMLNode
940 {
941  friend class XMLDocument;
942 public:
944  return this;
945  }
946  virtual const XMLDeclaration* ToDeclaration() const {
947  return this;
948  }
949 
950  virtual bool Accept( XMLVisitor* visitor ) const;
951 
952  char* ParseDeep( char*, StrPair* endTag );
953  virtual XMLNode* ShallowClone( XMLDocument* document ) const;
954  virtual bool ShallowEqual( const XMLNode* compare ) const;
955 
956 protected:
957  XMLDeclaration( XMLDocument* doc );
958  virtual ~XMLDeclaration();
959  XMLDeclaration( const XMLDeclaration& ); // not supported
960  XMLDeclaration& operator=( const XMLDeclaration& ); // not supported
961 };
962 
963 
971 class TINYXML2_LIB XMLUnknown : public XMLNode
972 {
973  friend class XMLDocument;
974 public:
975  virtual XMLUnknown* ToUnknown() {
976  return this;
977  }
978  virtual const XMLUnknown* ToUnknown() const {
979  return this;
980  }
981 
982  virtual bool Accept( XMLVisitor* visitor ) const;
983 
984  char* ParseDeep( char*, StrPair* endTag );
985  virtual XMLNode* ShallowClone( XMLDocument* document ) const;
986  virtual bool ShallowEqual( const XMLNode* compare ) const;
987 
988 protected:
989  XMLUnknown( XMLDocument* doc );
990  virtual ~XMLUnknown();
991  XMLUnknown( const XMLUnknown& ); // not supported
992  XMLUnknown& operator=( const XMLUnknown& ); // not supported
993 };
994 
995 
996 enum XMLError {
997  XML_NO_ERROR = 0,
998  XML_SUCCESS = 0,
999 
1000  XML_NO_ATTRIBUTE,
1001  XML_WRONG_ATTRIBUTE_TYPE,
1002 
1003  XML_ERROR_FILE_NOT_FOUND,
1004  XML_ERROR_FILE_COULD_NOT_BE_OPENED,
1005  XML_ERROR_FILE_READ_ERROR,
1006  XML_ERROR_ELEMENT_MISMATCH,
1007  XML_ERROR_PARSING_ELEMENT,
1008  XML_ERROR_PARSING_ATTRIBUTE,
1009  XML_ERROR_IDENTIFYING_TAG,
1010  XML_ERROR_PARSING_TEXT,
1011  XML_ERROR_PARSING_CDATA,
1012  XML_ERROR_PARSING_COMMENT,
1013  XML_ERROR_PARSING_DECLARATION,
1014  XML_ERROR_PARSING_UNKNOWN,
1015  XML_ERROR_EMPTY_DOCUMENT,
1016  XML_ERROR_MISMATCHED_ELEMENT,
1017  XML_ERROR_PARSING,
1018 
1019  XML_CAN_NOT_CONVERT_TEXT,
1020  XML_NO_TEXT_NODE
1021 };
1022 
1023 
1030 class TINYXML2_LIB XMLAttribute
1031 {
1032  friend class XMLElement;
1033 public:
1035  const char* Name() const;
1036 
1038  const char* Value() const;
1039 
1041  const XMLAttribute* Next() const {
1042  return _next;
1043  }
1044 
1049  int IntValue() const {
1050  int i=0;
1051  QueryIntValue( &i );
1052  return i;
1053  }
1055  unsigned UnsignedValue() const {
1056  unsigned i=0;
1057  QueryUnsignedValue( &i );
1058  return i;
1059  }
1061  bool BoolValue() const {
1062  bool b=false;
1063  QueryBoolValue( &b );
1064  return b;
1065  }
1067  double DoubleValue() const {
1068  double d=0;
1069  QueryDoubleValue( &d );
1070  return d;
1071  }
1073  float FloatValue() const {
1074  float f=0;
1075  QueryFloatValue( &f );
1076  return f;
1077  }
1078 
1083  XMLError QueryIntValue( int* value ) const;
1085  XMLError QueryUnsignedValue( unsigned int* value ) const;
1087  XMLError QueryBoolValue( bool* value ) const;
1089  XMLError QueryDoubleValue( double* value ) const;
1091  XMLError QueryFloatValue( float* value ) const;
1092 
1094  void SetAttribute( const char* value );
1096  void SetAttribute( int value );
1098  void SetAttribute( unsigned value );
1100  void SetAttribute( bool value );
1102  void SetAttribute( double value );
1104  void SetAttribute( float value );
1105 
1106 private:
1107  enum { BUF_SIZE = 200 };
1108 
1109  XMLAttribute() : _next( 0 ), _memPool( 0 ) {}
1110  virtual ~XMLAttribute() {}
1111 
1112  XMLAttribute( const XMLAttribute& ); // not supported
1113  void operator=( const XMLAttribute& ); // not supported
1114  void SetName( const char* name );
1115 
1116  char* ParseDeep( char* p, bool processEntities );
1117 
1118  mutable StrPair _name;
1119  mutable StrPair _value;
1120  XMLAttribute* _next;
1121  MemPool* _memPool;
1122 };
1123 
1124 
1129 class TINYXML2_LIB XMLElement : public XMLNode
1130 {
1131  friend class XMLBase;
1132  friend class XMLDocument;
1133 public:
1135  const char* Name() const {
1136  return Value();
1137  }
1139  void SetName( const char* str, bool staticMem=false ) {
1140  SetValue( str, staticMem );
1141  }
1142 
1143  virtual XMLElement* ToElement() {
1144  return this;
1145  }
1146  virtual const XMLElement* ToElement() const {
1147  return this;
1148  }
1149  virtual bool Accept( XMLVisitor* visitor ) const;
1150 
1174  const char* Attribute( const char* name, const char* value=0 ) const;
1175 
1181  int IntAttribute( const char* name ) const {
1182  int i=0;
1183  QueryIntAttribute( name, &i );
1184  return i;
1185  }
1187  unsigned UnsignedAttribute( const char* name ) const {
1188  unsigned i=0;
1189  QueryUnsignedAttribute( name, &i );
1190  return i;
1191  }
1193  bool BoolAttribute( const char* name ) const {
1194  bool b=false;
1195  QueryBoolAttribute( name, &b );
1196  return b;
1197  }
1199  double DoubleAttribute( const char* name ) const {
1200  double d=0;
1201  QueryDoubleAttribute( name, &d );
1202  return d;
1203  }
1205  float FloatAttribute( const char* name ) const {
1206  float f=0;
1207  QueryFloatAttribute( name, &f );
1208  return f;
1209  }
1210 
1224  XMLError QueryIntAttribute( const char* name, int* value ) const {
1225  const XMLAttribute* a = FindAttribute( name );
1226  if ( !a ) {
1227  return XML_NO_ATTRIBUTE;
1228  }
1229  return a->QueryIntValue( value );
1230  }
1232  XMLError QueryUnsignedAttribute( const char* name, unsigned int* value ) const {
1233  const XMLAttribute* a = FindAttribute( name );
1234  if ( !a ) {
1235  return XML_NO_ATTRIBUTE;
1236  }
1237  return a->QueryUnsignedValue( value );
1238  }
1240  XMLError QueryBoolAttribute( const char* name, bool* value ) const {
1241  const XMLAttribute* a = FindAttribute( name );
1242  if ( !a ) {
1243  return XML_NO_ATTRIBUTE;
1244  }
1245  return a->QueryBoolValue( value );
1246  }
1248  XMLError QueryDoubleAttribute( const char* name, double* value ) const {
1249  const XMLAttribute* a = FindAttribute( name );
1250  if ( !a ) {
1251  return XML_NO_ATTRIBUTE;
1252  }
1253  return a->QueryDoubleValue( value );
1254  }
1256  XMLError QueryFloatAttribute( const char* name, float* value ) const {
1257  const XMLAttribute* a = FindAttribute( name );
1258  if ( !a ) {
1259  return XML_NO_ATTRIBUTE;
1260  }
1261  return a->QueryFloatValue( value );
1262  }
1263 
1264 
1282  int QueryAttribute( const char* name, int* value ) const {
1283  return QueryIntAttribute( name, value );
1284  }
1285 
1286  int QueryAttribute( const char* name, unsigned int* value ) const {
1287  return QueryUnsignedAttribute( name, value );
1288  }
1289 
1290  int QueryAttribute( const char* name, bool* value ) const {
1291  return QueryBoolAttribute( name, value );
1292  }
1293 
1294  int QueryAttribute( const char* name, double* value ) const {
1295  return QueryDoubleAttribute( name, value );
1296  }
1297 
1298  int QueryAttribute( const char* name, float* value ) const {
1299  return QueryFloatAttribute( name, value );
1300  }
1301 
1303  void SetAttribute( const char* name, const char* value ) {
1304  XMLAttribute* a = FindOrCreateAttribute( name );
1305  a->SetAttribute( value );
1306  }
1308  void SetAttribute( const char* name, int value ) {
1309  XMLAttribute* a = FindOrCreateAttribute( name );
1310  a->SetAttribute( value );
1311  }
1313  void SetAttribute( const char* name, unsigned value ) {
1314  XMLAttribute* a = FindOrCreateAttribute( name );
1315  a->SetAttribute( value );
1316  }
1318  void SetAttribute( const char* name, bool value ) {
1319  XMLAttribute* a = FindOrCreateAttribute( name );
1320  a->SetAttribute( value );
1321  }
1323  void SetAttribute( const char* name, double value ) {
1324  XMLAttribute* a = FindOrCreateAttribute( name );
1325  a->SetAttribute( value );
1326  }
1328  void SetAttribute( const char* name, float value ) {
1329  XMLAttribute* a = FindOrCreateAttribute( name );
1330  a->SetAttribute( value );
1331  }
1332 
1336  void DeleteAttribute( const char* name );
1337 
1339  const XMLAttribute* FirstAttribute() const {
1340  return _rootAttribute;
1341  }
1343  const XMLAttribute* FindAttribute( const char* name ) const;
1344 
1373  const char* GetText() const;
1374 
1409  void SetText( const char* inText );
1411  void SetText( int value );
1413  void SetText( unsigned value );
1415  void SetText( bool value );
1417  void SetText( double value );
1419  void SetText( float value );
1420 
1447  XMLError QueryIntText( int* ival ) const;
1449  XMLError QueryUnsignedText( unsigned* uval ) const;
1451  XMLError QueryBoolText( bool* bval ) const;
1453  XMLError QueryDoubleText( double* dval ) const;
1455  XMLError QueryFloatText( float* fval ) const;
1456 
1457  // internal:
1458  enum {
1459  OPEN, // <foo>
1460  CLOSED, // <foo/>
1461  CLOSING // </foo>
1462  };
1463  int ClosingType() const {
1464  return _closingType;
1465  }
1466  char* ParseDeep( char* p, StrPair* endTag );
1467  virtual XMLNode* ShallowClone( XMLDocument* document ) const;
1468  virtual bool ShallowEqual( const XMLNode* compare ) const;
1469 
1470 private:
1471  XMLElement( XMLDocument* doc );
1472  virtual ~XMLElement();
1473  XMLElement( const XMLElement& ); // not supported
1474  void operator=( const XMLElement& ); // not supported
1475 
1476  XMLAttribute* FindAttribute( const char* name );
1477  XMLAttribute* FindOrCreateAttribute( const char* name );
1478  //void LinkAttribute( XMLAttribute* attrib );
1479  char* ParseAttributes( char* p );
1480 
1481  enum { BUF_SIZE = 200 };
1482  int _closingType;
1483  // The attribute list is ordered; there is no 'lastAttribute'
1484  // because the list needs to be scanned for dupes before adding
1485  // a new attribute.
1486  XMLAttribute* _rootAttribute;
1487 };
1488 
1489 
1490 enum Whitespace {
1491  PRESERVE_WHITESPACE,
1492  COLLAPSE_WHITESPACE
1493 };
1494 
1495 
1501 class TINYXML2_LIB XMLDocument : public XMLNode
1502 {
1503  friend class XMLElement;
1504 public:
1506  XMLDocument( bool processEntities = true, Whitespace = PRESERVE_WHITESPACE );
1507  ~XMLDocument();
1508 
1510  return this;
1511  }
1512  virtual const XMLDocument* ToDocument() const {
1513  return this;
1514  }
1515 
1526  XMLError Parse( const char* xml, size_t nBytes=(size_t)(-1) );
1527 
1533  XMLError LoadFile( const char* filename );
1534 
1542  XMLError LoadFile( FILE* );
1543 
1549  XMLError SaveFile( const char* filename, bool compact = false );
1550 
1558  XMLError SaveFile( FILE* fp, bool compact = false );
1559 
1560  bool ProcessEntities() const {
1561  return _processEntities;
1562  }
1563  Whitespace WhitespaceMode() const {
1564  return _whitespace;
1565  }
1566 
1570  bool HasBOM() const {
1571  return _writeBOM;
1572  }
1575  void SetBOM( bool useBOM ) {
1576  _writeBOM = useBOM;
1577  }
1578 
1583  return FirstChildElement();
1584  }
1585  const XMLElement* RootElement() const {
1586  return FirstChildElement();
1587  }
1588 
1603  void Print( XMLPrinter* streamer=0 ) const;
1604  virtual bool Accept( XMLVisitor* visitor ) const;
1605 
1611  XMLElement* NewElement( const char* name );
1617  XMLComment* NewComment( const char* comment );
1623  XMLText* NewText( const char* text );
1635  XMLDeclaration* NewDeclaration( const char* text=0 );
1641  XMLUnknown* NewUnknown( const char* text );
1642 
1647  void DeleteNode( XMLNode* node ) {
1648  node->_parent->DeleteChild( node );
1649  }
1650 
1651  void SetError( XMLError error, const char* str1, const char* str2 );
1652 
1654  bool Error() const {
1655  return _errorID != XML_NO_ERROR;
1656  }
1658  XMLError ErrorID() const {
1659  return _errorID;
1660  }
1662  const char* GetErrorStr1() const {
1663  return _errorStr1;
1664  }
1666  const char* GetErrorStr2() const {
1667  return _errorStr2;
1668  }
1670  void PrintError() const;
1671 
1673  void Clear();
1674 
1675  // internal
1676  char* Identify( char* p, XMLNode** node );
1677 
1678  virtual XMLNode* ShallowClone( XMLDocument* /*document*/ ) const {
1679  return 0;
1680  }
1681  virtual bool ShallowEqual( const XMLNode* /*compare*/ ) const {
1682  return false;
1683  }
1684 
1685 private:
1686  XMLDocument( const XMLDocument& ); // not supported
1687  void operator=( const XMLDocument& ); // not supported
1688 
1689  bool _writeBOM;
1690  bool _processEntities;
1691  XMLError _errorID;
1692  Whitespace _whitespace;
1693  const char* _errorStr1;
1694  const char* _errorStr2;
1695  char* _charBuffer;
1696 
1697  MemPoolT< sizeof(XMLElement) > _elementPool;
1698  MemPoolT< sizeof(XMLAttribute) > _attributePool;
1699  MemPoolT< sizeof(XMLText) > _textPool;
1700  MemPoolT< sizeof(XMLComment) > _commentPool;
1701 };
1702 
1703 
1759 class TINYXML2_LIB XMLHandle
1760 {
1761 public:
1763  XMLHandle( XMLNode* node ) {
1764  _node = node;
1765  }
1767  XMLHandle( XMLNode& node ) {
1768  _node = &node;
1769  }
1771  XMLHandle( const XMLHandle& ref ) {
1772  _node = ref._node;
1773  }
1775  XMLHandle& operator=( const XMLHandle& ref ) {
1776  _node = ref._node;
1777  return *this;
1778  }
1779 
1782  return XMLHandle( _node ? _node->FirstChild() : 0 );
1783  }
1785  XMLHandle FirstChildElement( const char* value=0 ) {
1786  return XMLHandle( _node ? _node->FirstChildElement( value ) : 0 );
1787  }
1790  return XMLHandle( _node ? _node->LastChild() : 0 );
1791  }
1793  XMLHandle LastChildElement( const char* _value=0 ) {
1794  return XMLHandle( _node ? _node->LastChildElement( _value ) : 0 );
1795  }
1798  return XMLHandle( _node ? _node->PreviousSibling() : 0 );
1799  }
1801  XMLHandle PreviousSiblingElement( const char* _value=0 ) {
1802  return XMLHandle( _node ? _node->PreviousSiblingElement( _value ) : 0 );
1803  }
1806  return XMLHandle( _node ? _node->NextSibling() : 0 );
1807  }
1809  XMLHandle NextSiblingElement( const char* _value=0 ) {
1810  return XMLHandle( _node ? _node->NextSiblingElement( _value ) : 0 );
1811  }
1812 
1815  return _node;
1816  }
1819  return ( ( _node && _node->ToElement() ) ? _node->ToElement() : 0 );
1820  }
1823  return ( ( _node && _node->ToText() ) ? _node->ToText() : 0 );
1824  }
1827  return ( ( _node && _node->ToUnknown() ) ? _node->ToUnknown() : 0 );
1828  }
1831  return ( ( _node && _node->ToDeclaration() ) ? _node->ToDeclaration() : 0 );
1832  }
1833 
1834 private:
1835  XMLNode* _node;
1836 };
1837 
1838 
1843 class TINYXML2_LIB XMLConstHandle
1844 {
1845 public:
1846  XMLConstHandle( const XMLNode* node ) {
1847  _node = node;
1848  }
1849  XMLConstHandle( const XMLNode& node ) {
1850  _node = &node;
1851  }
1852  XMLConstHandle( const XMLConstHandle& ref ) {
1853  _node = ref._node;
1854  }
1855 
1856  XMLConstHandle& operator=( const XMLConstHandle& ref ) {
1857  _node = ref._node;
1858  return *this;
1859  }
1860 
1861  const XMLConstHandle FirstChild() const {
1862  return XMLConstHandle( _node ? _node->FirstChild() : 0 );
1863  }
1864  const XMLConstHandle FirstChildElement( const char* value=0 ) const {
1865  return XMLConstHandle( _node ? _node->FirstChildElement( value ) : 0 );
1866  }
1867  const XMLConstHandle LastChild() const {
1868  return XMLConstHandle( _node ? _node->LastChild() : 0 );
1869  }
1870  const XMLConstHandle LastChildElement( const char* _value=0 ) const {
1871  return XMLConstHandle( _node ? _node->LastChildElement( _value ) : 0 );
1872  }
1873  const XMLConstHandle PreviousSibling() const {
1874  return XMLConstHandle( _node ? _node->PreviousSibling() : 0 );
1875  }
1876  const XMLConstHandle PreviousSiblingElement( const char* _value=0 ) const {
1877  return XMLConstHandle( _node ? _node->PreviousSiblingElement( _value ) : 0 );
1878  }
1879  const XMLConstHandle NextSibling() const {
1880  return XMLConstHandle( _node ? _node->NextSibling() : 0 );
1881  }
1882  const XMLConstHandle NextSiblingElement( const char* _value=0 ) const {
1883  return XMLConstHandle( _node ? _node->NextSiblingElement( _value ) : 0 );
1884  }
1885 
1886 
1887  const XMLNode* ToNode() const {
1888  return _node;
1889  }
1890  const XMLElement* ToElement() const {
1891  return ( ( _node && _node->ToElement() ) ? _node->ToElement() : 0 );
1892  }
1893  const XMLText* ToText() const {
1894  return ( ( _node && _node->ToText() ) ? _node->ToText() : 0 );
1895  }
1896  const XMLUnknown* ToUnknown() const {
1897  return ( ( _node && _node->ToUnknown() ) ? _node->ToUnknown() : 0 );
1898  }
1899  const XMLDeclaration* ToDeclaration() const {
1900  return ( ( _node && _node->ToDeclaration() ) ? _node->ToDeclaration() : 0 );
1901  }
1902 
1903 private:
1904  const XMLNode* _node;
1905 };
1906 
1907 
1950 class TINYXML2_LIB XMLPrinter : public XMLVisitor
1951 {
1952 public:
1959  XMLPrinter( FILE* file=0, bool compact = false, int depth = 0 );
1960  virtual ~XMLPrinter() {}
1961 
1963  void PushHeader( bool writeBOM, bool writeDeclaration );
1967  void OpenElement( const char* name, bool compactMode=false );
1969  void PushAttribute( const char* name, const char* value );
1970  void PushAttribute( const char* name, int value );
1971  void PushAttribute( const char* name, unsigned value );
1972  void PushAttribute( const char* name, bool value );
1973  void PushAttribute( const char* name, double value );
1975  virtual void CloseElement( bool compactMode=false );
1976 
1978  void PushText( const char* text, bool cdata=false );
1980  void PushText( int value );
1982  void PushText( unsigned value );
1984  void PushText( bool value );
1986  void PushText( float value );
1988  void PushText( double value );
1989 
1991  void PushComment( const char* comment );
1992 
1993  void PushDeclaration( const char* value );
1994  void PushUnknown( const char* value );
1995 
1996  virtual bool VisitEnter( const XMLDocument& /*doc*/ );
1997  virtual bool VisitExit( const XMLDocument& /*doc*/ ) {
1998  return true;
1999  }
2000 
2001  virtual bool VisitEnter( const XMLElement& element, const XMLAttribute* attribute );
2002  virtual bool VisitExit( const XMLElement& element );
2003 
2004  virtual bool Visit( const XMLText& text );
2005  virtual bool Visit( const XMLComment& comment );
2006  virtual bool Visit( const XMLDeclaration& declaration );
2007  virtual bool Visit( const XMLUnknown& unknown );
2008 
2013  const char* CStr() const {
2014  return _buffer.Mem();
2015  }
2021  int CStrSize() const {
2022  return _buffer.Size();
2023  }
2028  void ClearBuffer() {
2029  _buffer.Clear();
2030  _buffer.Push(0);
2031  }
2032 
2033 protected:
2034  virtual bool CompactMode( const XMLElement& ) { return _compactMode; };
2035 
2039  virtual void PrintSpace( int depth );
2040  void Print( const char* format, ... );
2041 
2042  void SealElement();
2043  bool _elementJustOpened;
2044  DynArray< const char*, 10 > _stack;
2045 
2046 private:
2047  void PrintString( const char*, bool restrictedEntitySet ); // prints out, after detecting entities.
2048 
2049  bool _firstElement;
2050  FILE* _fp;
2051  int _depth;
2052  int _textDepth;
2053  bool _processEntities;
2054  bool _compactMode;
2055 
2056  enum {
2057  ENTITY_RANGE = 64,
2058  BUF_SIZE = 200
2059  };
2060  bool _entityFlag[ENTITY_RANGE];
2061  bool _restrictedEntityFlag[ENTITY_RANGE];
2062 
2063  DynArray< char, 20 > _buffer;
2064 #ifdef _MSC_VER
2065  DynArray< char, 20 > _accumulator;
2066 #endif
2067 };
2068 
2069 
2070 } // tinyxml2
2071 
2072 #if defined(_MSC_VER)
2073 # pragma warning(pop)
2074 #endif
2075 
2076 #endif // TINYXML2_INCLUDED
bool CData() const
Returns true if this is a CDATA text element.
Definition: tinyxml2.h:881
const XMLNode * Parent() const
Get the parent of this node on the DOM.
Definition: tinyxml2.h:661
virtual bool VisitExit(const XMLDocument &)
Visit a document.
Definition: tinyxml2.h:449
virtual bool ShallowEqual(const XMLNode *) const
Definition: tinyxml2.h:1681
XMLText * ToText()
Safe cast to XMLText. This can return null.
Definition: tinyxml2.h:1822
XMLError QueryBoolAttribute(const char *name, bool *value) const
See QueryIntAttribute()
Definition: tinyxml2.h:1240
XMLElement * ToElement()
Safe cast to XMLElement. This can return null.
Definition: tinyxml2.h:1818
virtual XMLElement * ToElement()
Safely cast to an Element, or null.
Definition: tinyxml2.h:601
double DoubleValue() const
Query as a double. See IntValue()
Definition: tinyxml2.h:1067
virtual XMLText * ToText()
Safely cast to Text, or null.
Definition: tinyxml2.h:605
bool NoChildren() const
Returns true if this node has no children.
Definition: tinyxml2.h:670
XMLError ErrorID() const
Return the errorID.
Definition: tinyxml2.h:1658
int CStrSize() const
Definition: tinyxml2.h:2021
virtual XMLDocument * ToDocument()
Safely cast to a Document, or null.
Definition: tinyxml2.h:1509
const XMLNode * LastChild() const
Get the last child node, or null if none exists.
Definition: tinyxml2.h:693
XMLUnknown * ToUnknown()
Safe cast to XMLUnknown. This can return null.
Definition: tinyxml2.h:1826
XMLHandle(const XMLHandle &ref)
Copy constructor.
Definition: tinyxml2.h:1771
XMLHandle FirstChild()
Get the first child of this handle.
Definition: tinyxml2.h:1781
void SetCData(bool isCData)
Declare whether this should be CDATA or standard text.
Definition: tinyxml2.h:877
XMLHandle LastChild()
Get the last child of this handle.
Definition: tinyxml2.h:1789
Definition: tinyxml2.h:1759
Definition: tinyxml2.h:939
XMLError QueryUnsignedAttribute(const char *name, unsigned int *value) const
See QueryIntAttribute()
Definition: tinyxml2.h:1232
XMLElement * RootElement()
Definition: tinyxml2.h:1582
const char * Name() const
Get the name of an element (which is the Value() of the node.)
Definition: tinyxml2.h:1135
virtual XMLText * ToText()
Safely cast to Text, or null.
Definition: tinyxml2.h:869
XMLHandle(XMLNode &node)
Create a handle from a node.
Definition: tinyxml2.h:1767
void SetName(const char *str, bool staticMem=false)
Set the name of the element.
Definition: tinyxml2.h:1139
void SetBOM(bool useBOM)
Definition: tinyxml2.h:1575
XMLHandle(XMLNode *node)
Create a handle from any node (at any depth of the tree.) This can be a null pointer.
Definition: tinyxml2.h:1763
XMLError QueryIntValue(int *value) const
double DoubleAttribute(const char *name) const
See IntAttribute()
Definition: tinyxml2.h:1199
int QueryAttribute(const char *name, int *value) const
Definition: tinyxml2.h:1282
void ClearBuffer()
Definition: tinyxml2.h:2028
virtual XMLComment * ToComment()
Safely cast to a Comment, or null.
Definition: tinyxml2.h:905
virtual XMLElement * ToElement()
Safely cast to an Element, or null.
Definition: tinyxml2.h:1143
Definition: tinyxml2.h:126
bool HasBOM() const
Definition: tinyxml2.h:1570
XMLNode * ToNode()
Safe cast to XMLNode. This can return null.
Definition: tinyxml2.h:1814
unsigned UnsignedAttribute(const char *name) const
See IntAttribute()
Definition: tinyxml2.h:1187
void DeleteNode(XMLNode *node)
Definition: tinyxml2.h:1647
bool BoolAttribute(const char *name) const
See IntAttribute()
Definition: tinyxml2.h:1193
bool BoolValue() const
Query as a boolean. See IntValue()
Definition: tinyxml2.h:1061
Definition: tinyxml2.h:901
virtual XMLDeclaration * ToDeclaration()
Safely cast to a Declaration, or null.
Definition: tinyxml2.h:943
void DeleteChild(XMLNode *node)
XMLError QueryFloatAttribute(const char *name, float *value) const
See QueryIntAttribute()
Definition: tinyxml2.h:1256
virtual bool Visit(const XMLDeclaration &)
Visit a declaration.
Definition: tinyxml2.h:463
virtual bool Visit(const XMLUnknown &)
Visit an unknown node.
Definition: tinyxml2.h:475
void SetAttribute(const char *name, unsigned value)
Sets the named attribute to value.
Definition: tinyxml2.h:1313
Definition: tinyxml2.h:1129
XMLHandle NextSibling()
Get the next sibling of this handle.
Definition: tinyxml2.h:1805
XMLError QueryUnsignedValue(unsigned int *value) const
See QueryIntValue.
virtual XMLUnknown * ToUnknown()
Safely cast to an Unknown, or null.
Definition: tinyxml2.h:975
XMLError QueryFloatValue(float *value) const
See QueryIntValue.
XMLHandle PreviousSibling()
Get the previous sibling of this handle.
Definition: tinyxml2.h:1797
Definition: tinyxml2.h:1843
XMLHandle & operator=(const XMLHandle &ref)
Assignment.
Definition: tinyxml2.h:1775
virtual bool VisitExit(const XMLDocument &)
Visit a document.
Definition: tinyxml2.h:1997
virtual bool VisitEnter(const XMLElement &, const XMLAttribute *)
Visit an element.
Definition: tinyxml2.h:454
const XMLDocument * GetDocument() const
Get the XMLDocument that owns this XMLNode.
Definition: tinyxml2.h:592
virtual XMLNode * ShallowClone(XMLDocument *) const
Definition: tinyxml2.h:1678
XMLHandle FirstChildElement(const char *value=0)
Get the first child element of this handle.
Definition: tinyxml2.h:1785
virtual bool VisitEnter(const XMLDocument &)
Visit a document.
Definition: tinyxml2.h:445
Definition: tinyxml2.h:971
const XMLNode * NextSibling() const
Get the next (right) sibling node of this node.
Definition: tinyxml2.h:727
virtual XMLDocument * ToDocument()
Safely cast to a Document, or null.
Definition: tinyxml2.h:613
Definition: tinyxml2.h:1030
float FloatAttribute(const char *name) const
See IntAttribute()
Definition: tinyxml2.h:1205
const char * GetErrorStr2() const
Return a possibly helpful secondary diagnostic location or string.
Definition: tinyxml2.h:1666
void SetAttribute(const char *name, bool value)
Sets the named attribute to value.
Definition: tinyxml2.h:1318
XMLDeclaration * ToDeclaration()
Safe cast to XMLDeclaration. This can return null.
Definition: tinyxml2.h:1830
unsigned UnsignedValue() const
Query as an unsigned integer. See IntValue()
Definition: tinyxml2.h:1055
XMLHandle NextSiblingElement(const char *_value=0)
Get the next sibling element of this handle.
Definition: tinyxml2.h:1809
void SetAttribute(const char *value)
Set the attribute to a string value.
void SetAttribute(const char *name, const char *value)
Sets the named attribute to value.
Definition: tinyxml2.h:1303
virtual bool VisitExit(const XMLElement &)
Visit an element.
Definition: tinyxml2.h:458
Definition: tinyxml2.h:1950
Definition: tinyxml2.h:1501
const char * CStr() const
Definition: tinyxml2.h:2013
XMLError QueryIntAttribute(const char *name, int *value) const
Definition: tinyxml2.h:1224
void SetAttribute(const char *name, double value)
Sets the named attribute to value.
Definition: tinyxml2.h:1323
int IntValue() const
Definition: tinyxml2.h:1049
virtual bool Visit(const XMLComment &)
Visit a comment node.
Definition: tinyxml2.h:471
const XMLAttribute * Next() const
The next attribute in the list.
Definition: tinyxml2.h:1041
const char * GetErrorStr1() const
Return a possibly helpful diagnostic location or string.
Definition: tinyxml2.h:1662
XMLError QueryDoubleValue(double *value) const
See QueryIntValue.
bool Error() const
Return true if there was an error parsing the document.
Definition: tinyxml2.h:1654
Definition: tinyxml2.h:585
const XMLNode * PreviousSibling() const
Get the previous (left) sibling node of this node.
Definition: tinyxml2.h:711
float FloatValue() const
Query as a float. See IntValue()
Definition: tinyxml2.h:1073
XMLError QueryBoolValue(bool *value) const
See QueryIntValue.
XMLHandle PreviousSiblingElement(const char *_value=0)
Get the previous sibling element of this handle.
Definition: tinyxml2.h:1801
virtual bool Visit(const XMLText &)
Visit a text node.
Definition: tinyxml2.h:467
Definition: tinyxml2.h:862
Definition: tinyxml2.h:439
XMLDocument * GetDocument()
Get the XMLDocument that owns this XMLNode.
Definition: tinyxml2.h:596
virtual XMLUnknown * ToUnknown()
Safely cast to an Unknown, or null.
Definition: tinyxml2.h:621
XMLError QueryDoubleAttribute(const char *name, double *value) const
See QueryIntAttribute()
Definition: tinyxml2.h:1248
void SetAttribute(const char *name, float value)
Sets the named attribute to value.
Definition: tinyxml2.h:1328
const XMLNode * FirstChild() const
Get the first child node, or null if none exists.
Definition: tinyxml2.h:675
virtual XMLDeclaration * ToDeclaration()
Safely cast to a Declaration, or null.
Definition: tinyxml2.h:617
const XMLAttribute * FirstAttribute() const
Return the first attribute in the list.
Definition: tinyxml2.h:1339
int IntAttribute(const char *name) const
Definition: tinyxml2.h:1181
void SetAttribute(const char *name, int value)
Sets the named attribute to value.
Definition: tinyxml2.h:1308
XMLHandle LastChildElement(const char *_value=0)
Get the last child element of this handle.
Definition: tinyxml2.h:1793
virtual XMLComment * ToComment()
Safely cast to a Comment, or null.
Definition: tinyxml2.h:609