docs/tinyxml2_8h_source.html
| TinyXML-2 10.0.0 |
Loading...
Searching...
No Matches
tinyxml2.h
1/*
2Original code by Lee Thomason (www.grinninglizard.com)
3
4This software is provided 'as-is', without any express or implied
5warranty. In no event will the authors be held liable for any
6damages arising from the use of this software.
7
8Permission is granted to anyone to use this software for any
9purpose, including commercial applications, and to alter it and
10redistribute it freely, subject to the following restrictions:
11
13not claim that you wrote the original software. If you use this
14software in a product, an acknowledgment in the product documentation
15would be appreciated but is not required.
16
18must not be misrepresented as being the original software.
19
21distribution.
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 gcc:
47 g++ -Wall -DTINYXML2_DEBUG tinyxml2.cpp xmltest.cpp -o gccxmltest.exe
48
49 Formatting, Artistic Style:
50 AStyle.exe --style=1tbs --indent-switches --break-closing-brackets --indent-preprocessor tinyxml2.cpp tinyxml2.h
51*/
52
53#if defined( _DEBUG ) || defined (__DEBUG__)
54# ifndef TINYXML2_DEBUG
55# define TINYXML2_DEBUG
56# endif
57#endif
58
59#ifdef _MSC_VER
60# pragma warning(push)
61# pragma warning(disable: 4251)
62#endif
63
64#ifdef _MSC_VER
65# ifdef TINYXML2_EXPORT
66# define TINYXML2_LIB __declspec(dllexport)
67# elif defined(TINYXML2_IMPORT)
68# define TINYXML2_LIB __declspec(dllimport)
69# else
70# define TINYXML2_LIB
71# endif
72#elif __GNUC__ >= 4
73# define TINYXML2_LIB __attribute__((visibility("default")))
74#else
75# define TINYXML2_LIB
76#endif
77
78
79#if !defined(TIXMLASSERT)
80#if defined(TINYXML2_DEBUG)
81# if defined(_MSC_VER)
82# // "(void)0," is for suppressing C4127 warning in "assert(false)", "assert(true)" and the like
83# define TIXMLASSERT( x ) do { if ( !((void)0,(x))) { __debugbreak(); } } while(false)
84# elif defined (ANDROID_NDK)
85# include <android/log.h>
86# define TIXMLASSERT( x ) do { if ( !(x)) { __android_log_assert( "assert", "grinliz", "ASSERT in '%s' at %d.", __FILE__, __LINE__ ); } } while(false)
87# else
88# include <assert.h>
89# define TIXMLASSERT assert
90# endif
91#else
92# define TIXMLASSERT( x ) do {} while(false)
93#endif
94#endif
95
96/* Versioning, past 1.0.14:
98*/
99static const int TIXML2_MAJOR_VERSION = 10;
100static const int TIXML2_MINOR_VERSION = 0;
101static const int TIXML2_PATCH_VERSION = 0;
102
103#define TINYXML2_MAJOR_VERSION 10
104#define TINYXML2_MINOR_VERSION 0
105#define TINYXML2_PATCH_VERSION 0
106
107// A fixed element depth limit is problematic. There needs to be a
108// limit to avoid a stack overflow. However, that limit varies per
109// system, and the capacity of the stack. On the other hand, it's a trivial
110// attack that can result from ill, malicious, or even correctly formed XML,
111// so there needs to be a limit in place.
112static const int TINYXML2_MAX_ELEMENT_DEPTH = 500;
113
114namespace tinyxml2
115{
116class XMLDocument;
117class XMLElement;
118class XMLAttribute;
119class XMLComment;
120class XMLText;
121class XMLDeclaration;
122class XMLUnknown;
123class XMLPrinter;
124
125/*
126 A class that wraps strings. Normally stores the start and end
127 pointers into the XML file itself, and will apply normalization
128 and entity translation if actually read. Can also store (and memory
129 manage) a traditional char[]
130
131 Isn't clear why TINYXML2_LIB is needed; but seems to fix #719
132*/
133class TINYXML2_LIB StrPair
134{
135public:
136enum Mode {
137 NEEDS_ENTITY_PROCESSING = 0x01,
138 NEEDS_NEWLINE_NORMALIZATION = 0x02,
139 NEEDS_WHITESPACE_COLLAPSING = 0x04,
140
141 TEXT_ELEMENT = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION,
142 TEXT_ELEMENT_LEAVE_ENTITIES = NEEDS_NEWLINE_NORMALIZATION,
143 ATTRIBUTE_NAME = 0,
144 ATTRIBUTE_VALUE = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION,
145 ATTRIBUTE_VALUE_LEAVE_ENTITIES = NEEDS_NEWLINE_NORMALIZATION,
146 COMMENT = NEEDS_NEWLINE_NORMALIZATION
147 };
148
149 StrPair() : _flags( 0 ), _start( 0 ), _end( 0 ) {}
150 ~StrPair();
151
152void Set( char* start, char* end, int flags ) {
153 TIXMLASSERT( start );
154 TIXMLASSERT( end );
155 Reset();
156 _start = start;
157 _end = end;
158 _flags = flags | NEEDS_FLUSH;
159 }
160
161const char* GetStr();
162
163bool Empty() const {
164return _start == _end;
165 }
166
167void SetInternedStr( const char* str ) {
168 Reset();
169 _start = const_cast<char*>(str);
170 }
171
172void SetStr( const char* str, int flags=0 );
173
174char* ParseText( char* in, const char* endTag, int strFlags, int* curLineNumPtr );
175char* ParseName( char* in );
176
177void TransferTo( StrPair* other );
178void Reset();
179
180private:
181void CollapseWhitespace();
182
183enum {
184 NEEDS_FLUSH = 0x100,
185 NEEDS_DELETE = 0x200
186 };
187
188int _flags;
189char* _start;
190char* _end;
191
192 StrPair( const StrPair& other ); // not supported
193void operator=( const StrPair& other ); // not supported, use TransferTo()
194};
195
196
197/*
198 A dynamic array of Plain Old Data. Doesn't support constructors, etc.
199 Has a small initial memory pool, so that low or no usage will not
200 cause a call to new/delete
201*/
202template <class T, int INITIAL_SIZE>
203class DynArray
204{
205public:
206 DynArray() :
207 _mem( _pool ),
208 _allocated( INITIAL_SIZE ),
209 _size( 0 )
210 {
211 }
212
213 ~DynArray() {
214if ( _mem != _pool ) {
215delete [] _mem;
216 }
217 }
218
219void Clear() {
220 _size = 0;
221 }
222
223void Push( T t ) {
224 TIXMLASSERT( _size < INT_MAX );
225 EnsureCapacity( _size+1 );
226 _mem[_size] = t;
227 ++_size;
228 }
229
230 T* PushArr( int count ) {
231 TIXMLASSERT( count >= 0 );
232 TIXMLASSERT( _size <= INT_MAX - count );
233 EnsureCapacity( _size+count );
234 T* ret = &_mem[_size];
235 _size += count;
236return ret;
237 }
238
239 T Pop() {
240 TIXMLASSERT( _size > 0 );
241 --_size;
242return _mem[_size];
243 }
244
245void PopArr( int count ) {
246 TIXMLASSERT( _size >= count );
247 _size -= count;
248 }
249
250bool Empty() const {
251return _size == 0;
252 }
253
254 T& operator[](int i) {
255 TIXMLASSERT( i>= 0 && i < _size );
256return _mem[i];
257 }
258
259const T& operator[](int i) const {
260 TIXMLASSERT( i>= 0 && i < _size );
261return _mem[i];
262 }
263
264const T& PeekTop() const {
265 TIXMLASSERT( _size > 0 );
266return _mem[_size - 1];
267 }
268
269int Size() const {
270 TIXMLASSERT( _size >= 0 );
271return _size;
272 }
273
274int Capacity() const {
275 TIXMLASSERT( _allocated >= INITIAL_SIZE );
276return _allocated;
277 }
278
279void SwapRemove(int i) {
280 TIXMLASSERT(i >= 0 && i < _size);
281 TIXMLASSERT(_size > 0);
282 _mem[i] = _mem[_size - 1];
283 --_size;
284 }
285
286const T* Mem() const {
287 TIXMLASSERT( _mem );
288return _mem;
289 }
290
291 T* Mem() {
292 TIXMLASSERT( _mem );
293return _mem;
294 }
295
296private:
297 DynArray( const DynArray& ); // not supported
298void operator=( const DynArray& ); // not supported
299
300void EnsureCapacity( int cap ) {
301 TIXMLASSERT( cap > 0 );
302if ( cap > _allocated ) {
303 TIXMLASSERT( cap <= INT_MAX / 2 );
304const int newAllocated = cap * 2;
305 T* newMem = new T[static_cast<unsigned int>(newAllocated)];
306 TIXMLASSERT( newAllocated >= _size );
307 memcpy( newMem, _mem, sizeof(T)*static_cast<size_t>(_size) ); // warning: not using constructors, only works for PODs
308if ( _mem != _pool ) {
309delete [] _mem;
310 }
311 _mem = newMem;
312 _allocated = newAllocated;
313 }
314 }
315
316 T* _mem;
317 T _pool[static_cast<size_t>(INITIAL_SIZE)];
318int _allocated; // objects allocated
319int _size; // number objects in use
320};
321
322
323/*
324 Parent virtual class of a pool for fast allocation
325 and deallocation of objects.
326*/
327class MemPool
328{
329public:
330 MemPool() {}
331virtual ~MemPool() {}
332
333virtual int ItemSize() const = 0;
334virtual void* Alloc() = 0;
335virtual void Free( void* ) = 0;
336virtual void SetTracked() = 0;
337};
338
339
340/*
341 Template child class to create pools of the correct type.
342*/
343template< int ITEM_SIZE >
344class MemPoolT : public MemPool
345{
346public:
347 MemPoolT() : _blockPtrs(), _root(0), _currentAllocs(0), _nAllocs(0), _maxAllocs(0), _nUntracked(0) {}
348 ~MemPoolT() {
349 MemPoolT< ITEM_SIZE >::Clear();
350 }
351
352void Clear() {
353// Delete the blocks.
354while( !_blockPtrs.Empty()) {
355 Block* lastBlock = _blockPtrs.Pop();
356delete lastBlock;
357 }
358 _root = 0;
359 _currentAllocs = 0;
360 _nAllocs = 0;
361 _maxAllocs = 0;
362 _nUntracked = 0;
363 }
364
365virtual int ItemSize() const override{
366return ITEM_SIZE;
367 }
368int CurrentAllocs() const {
369return _currentAllocs;
370 }
371
372virtual void* Alloc() override{
373if ( !_root ) {
374// Need a new block.
375 Block* block = new Block;
376 _blockPtrs.Push( block );
377
378 Item* blockItems = block->items;
379for( int i = 0; i < ITEMS_PER_BLOCK - 1; ++i ) {
380 blockItems[i].next = &(blockItems[i + 1]);
381 }
382 blockItems[ITEMS_PER_BLOCK - 1].next = 0;
383 _root = blockItems;
384 }
385 Item* const result = _root;
386 TIXMLASSERT( result != 0 );
387 _root = _root->next;
388
389 ++_currentAllocs;
390if ( _currentAllocs > _maxAllocs ) {
391 _maxAllocs = _currentAllocs;
392 }
393 ++_nAllocs;
394 ++_nUntracked;
395return result;
396 }
397
398virtual void Free( void* mem ) override {
399if ( !mem ) {
400return;
401 }
402 --_currentAllocs;
403 Item* item = static_cast<Item*>( mem );
404#ifdef TINYXML2_DEBUG
405 memset( item, 0xfe, sizeof( *item ) );
406#endif
407 item->next = _root;
408 _root = item;
409 }
410void Trace( const char* name ) {
411 printf( "Mempool %s watermark=%d [%dk] current=%d size=%d nAlloc=%d blocks=%d\n",
412 name, _maxAllocs, _maxAllocs * ITEM_SIZE / 1024, _currentAllocs,
413 ITEM_SIZE, _nAllocs, _blockPtrs.Size() );
414 }
415
416void SetTracked() override {
417 --_nUntracked;
418 }
419
420int Untracked() const {
421return _nUntracked;
422 }
423
424// This number is perf sensitive. 4k seems like a good tradeoff on my machine.
425// The test file is large, 170k.
426// Release: VS2010 gcc(no opt)
427// 1k: 4000
428// 2k: 4000
429// 4k: 3900 21000
430// 16k: 5200
431// 32k: 4300
432// 64k: 4000 21000
433// Declared public because some compilers do not accept to use ITEMS_PER_BLOCK
434// in private part if ITEMS_PER_BLOCK is private
435enum { ITEMS_PER_BLOCK = (4 * 1024) / ITEM_SIZE };
436
437private:
438 MemPoolT( const MemPoolT& ); // not supported
439void operator=( const MemPoolT& ); // not supported
440
441union Item {
442 Item* next;
443char itemData[static_cast<size_t>(ITEM_SIZE)];
444 };
445struct Block {
446 Item items[ITEMS_PER_BLOCK];
447 };
448 DynArray< Block*, 10 > _blockPtrs;
449 Item* _root;
450
451int _currentAllocs;
452int _nAllocs;
453int _maxAllocs;
454int _nUntracked;
455};
456
457
458
478class TINYXML2_LIB XMLVisitor
479{
480public:
481virtual ~XMLVisitor() {}
482
484virtual bool VisitEnter( const XMLDocument& /*doc*/ ) {
485return true;
486 }
488virtual bool VisitExit( const XMLDocument& /*doc*/ ) {
489return true;
490 }
491
493virtual bool VisitEnter( const XMLElement& /*element*/, const XMLAttribute* /*firstAttribute*/ ) {
494return true;
495 }
497virtual bool VisitExit( const XMLElement& /*element*/ ) {
498return true;
499 }
500
502virtual bool Visit( const XMLDeclaration& /*declaration*/ ) {
503return true;
504 }
506virtual bool Visit( const XMLText& /*text*/ ) {
507return true;
508 }
510virtual bool Visit( const XMLComment& /*comment*/ ) {
511return true;
512 }
514virtual bool Visit( const XMLUnknown& /*unknown*/ ) {
515return true;
516 }
517};
518
519// WARNING: must match XMLDocument::_errorNames[]
520enum XMLError {
521 XML_SUCCESS = 0,
522 XML_NO_ATTRIBUTE,
523 XML_WRONG_ATTRIBUTE_TYPE,
524 XML_ERROR_FILE_NOT_FOUND,
525 XML_ERROR_FILE_COULD_NOT_BE_OPENED,
526 XML_ERROR_FILE_READ_ERROR,
527 XML_ERROR_PARSING_ELEMENT,
528 XML_ERROR_PARSING_ATTRIBUTE,
529 XML_ERROR_PARSING_TEXT,
530 XML_ERROR_PARSING_CDATA,
531 XML_ERROR_PARSING_COMMENT,
532 XML_ERROR_PARSING_DECLARATION,
533 XML_ERROR_PARSING_UNKNOWN,
534 XML_ERROR_EMPTY_DOCUMENT,
535 XML_ERROR_MISMATCHED_ELEMENT,
536 XML_ERROR_PARSING,
537 XML_CAN_NOT_CONVERT_TEXT,
538 XML_NO_TEXT_NODE,
539 XML_ELEMENT_DEPTH_EXCEEDED,
540
541 XML_ERROR_COUNT
542};
543
544
545/*
546 Utility functionality.
547*/
548class TINYXML2_LIB XMLUtil
549{
550public:
551static const char* SkipWhiteSpace( const char* p, int* curLineNumPtr ) {
552 TIXMLASSERT( p );
553
554while( IsWhiteSpace(*p) ) {
555if (curLineNumPtr && *p == '\n') {
556 ++(*curLineNumPtr);
557 }
558 ++p;
559 }
560 TIXMLASSERT( p );
561return p;
562 }
563static char* SkipWhiteSpace( char* const p, int* curLineNumPtr ) {
564return const_cast<char*>( SkipWhiteSpace( const_cast<const char*>(p), curLineNumPtr ) );
565 }
566
567// Anything in the high order range of UTF-8 is assumed to not be whitespace. This isn't
568// correct, but simple, and usually works.
569static bool IsWhiteSpace( char p ) {
570return !IsUTF8Continuation(p) && isspace( static_cast<unsigned char>(p) );
571 }
572
573inline static bool IsNameStartChar( unsigned char ch ) {
574if ( ch >= 128 ) {
575// This is a heuristic guess in attempt to not implement Unicode-aware isalpha()
576return true;
577 }
578if ( isalpha( ch ) ) {
579return true;
580 }
581return ch == ':' || ch == '_';
582 }
583
584inline static bool IsNameChar( unsigned char ch ) {
585return IsNameStartChar( ch )
586 || isdigit( ch )
587 || ch == '.'
588 || ch == '-';
589 }
590
591inline static bool IsPrefixHex( const char* p) {
592 p = SkipWhiteSpace(p, 0);
593return p && *p == '0' && ( *(p + 1) == 'x' || *(p + 1) == 'X');
594 }
595
596inline static bool StringEqual( const char* p, const char* q, int nChar=INT_MAX ) {
597if ( p == q ) {
598return true;
599 }
600 TIXMLASSERT( p );
601 TIXMLASSERT( q );
602 TIXMLASSERT( nChar >= 0 );
603return strncmp( p, q, static_cast<size_t>(nChar) ) == 0;
604 }
605
606inline static bool IsUTF8Continuation( const char p ) {
607return ( p & 0x80 ) != 0;
608 }
609
610static const char* ReadBOM( const char* p, bool* hasBOM );
611// p is the starting location,
612// the UTF-8 value of the entity will be placed in value, and length filled in.
613static const char* GetCharacterRef( const char* p, char* value, int* length );
614static void ConvertUTF32ToUTF8( unsigned long input, char* output, int* length );
615
616// converts primitive types to strings
617static void ToStr( int v, char* buffer, int bufferSize );
618static void ToStr( unsigned v, char* buffer, int bufferSize );
619static void ToStr( bool v, char* buffer, int bufferSize );
620static void ToStr( float v, char* buffer, int bufferSize );
621static void ToStr( double v, char* buffer, int bufferSize );
622static void ToStr(int64_t v, char* buffer, int bufferSize);
623static void ToStr(uint64_t v, char* buffer, int bufferSize);
624
625// converts strings to primitive types
626static bool ToInt( const char* str, int* value );
627static bool ToUnsigned( const char* str, unsigned* value );
628static bool ToBool( const char* str, bool* value );
629static bool ToFloat( const char* str, float* value );
630static bool ToDouble( const char* str, double* value );
631static bool ToInt64(const char* str, int64_t* value);
632static bool ToUnsigned64(const char* str, uint64_t* value);
633// Changes what is serialized for a boolean value.
634// Default to "true" and "false". Shouldn't be changed
635// unless you have a special testing or compatibility need.
636// Be careful: static, global, & not thread safe.
637// Be sure to set static const memory as parameters.
638static void SetBoolSerialization(const char* writeTrue, const char* writeFalse);
639
640private:
641static const char* writeBoolTrue;
642static const char* writeBoolFalse;
643};
644
645
672{
673friend class XMLDocument;
674friend class XMLElement;
675public:
676
678const XMLDocument* GetDocument() const {
679 TIXMLASSERT( _document );
680return _document;
681 }
683XMLDocument* GetDocument() {
684 TIXMLASSERT( _document );
685return _document;
686 }
687
689virtual XMLElement* ToElement() {
690return 0;
691 }
693virtual XMLText* ToText() {
694return 0;
695 }
697virtual XMLComment* ToComment() {
698return 0;
699 }
701virtual XMLDocument* ToDocument() {
702return 0;
703 }
705virtual XMLDeclaration* ToDeclaration() {
706return 0;
707 }
709virtual XMLUnknown* ToUnknown() {
710return 0;
711 }
712
713virtual const XMLElement* ToElement() const {
714return 0;
715 }
716virtual const XMLText* ToText() const {
717return 0;
718 }
719virtual const XMLComment* ToComment() const {
720return 0;
721 }
722virtual const XMLDocument* ToDocument() const {
723return 0;
724 }
725virtual const XMLDeclaration* ToDeclaration() const {
726return 0;
727 }
728virtual const XMLUnknown* ToUnknown() const {
729return 0;
730 }
731
732// ChildElementCount was originally suggested by msteiger on the sourceforge page for TinyXML and modified by KB1SPH for TinyXML-2.
733
734int ChildElementCount(const char *value) const;
735
736int ChildElementCount() const;
737
748
752void SetValue( const char* val, bool staticMem=false );
753
755int GetLineNum() const { return _parseLineNum; }
756
758const XMLNode* Parent() const {
759return _parent;
760 }
761
762XMLNode* Parent() {
763return _parent;
764 }
765
767bool NoChildren() const {
768return !_firstChild;
769 }
770
772const XMLNode* FirstChild() const {
773return _firstChild;
774 }
775
776XMLNode* FirstChild() {
777return _firstChild;
778 }
779
783const XMLElement* FirstChildElement( const char* name = 0 ) const;
784
785XMLElement* FirstChildElement( const char* name = 0 ) {
786return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->FirstChildElement( name ));
787 }
788
790const XMLNode* LastChild() const {
791return _lastChild;
792 }
793
794XMLNode* LastChild() {
795return _lastChild;
796 }
797
801const XMLElement* LastChildElement( const char* name = 0 ) const;
802
803XMLElement* LastChildElement( const char* name = 0 ) {
804return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->LastChildElement(name) );
805 }
806
808const XMLNode* PreviousSibling() const {
809return _prev;
810 }
811
812XMLNode* PreviousSibling() {
813return _prev;
814 }
815
817const XMLElement* PreviousSiblingElement( const char* name = 0 ) const ;
818
819XMLElement* PreviousSiblingElement( const char* name = 0 ) {
820return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->PreviousSiblingElement( name ) );
821 }
822
824const XMLNode* NextSibling() const {
825return _next;
826 }
827
828XMLNode* NextSibling() {
829return _next;
830 }
831
833const XMLElement* NextSiblingElement( const char* name = 0 ) const;
834
835XMLElement* NextSiblingElement( const char* name = 0 ) {
836return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->NextSiblingElement( name ) );
837 }
838
846XMLNode* InsertEndChild( XMLNode* addThis );
847
848XMLNode* LinkEndChild( XMLNode* addThis ) {
849return InsertEndChild( addThis );
850 }
858XMLNode* InsertFirstChild( XMLNode* addThis );
867XMLNode* InsertAfterChild( XMLNode* afterThis, XMLNode* addThis );
868
872void DeleteChildren();
873
877void DeleteChild( XMLNode* node );
878
888virtual XMLNode* ShallowClone( XMLDocument* document ) const = 0;
889
903XMLNode* DeepClone( XMLDocument* target ) const;
904
911virtual bool ShallowEqual( const XMLNode* compare ) const = 0;
912
935virtual bool Accept( XMLVisitor* visitor ) const = 0;
936
942void SetUserData(void* userData) { _userData = userData; }
943
949void* GetUserData() const { return _userData; }
950
951protected:
952explicit XMLNode( XMLDocument* );
953virtual ~XMLNode();
954
955virtual char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr);
956
957XMLDocument* _document;
958XMLNode* _parent;
959mutable StrPair _value;
960int _parseLineNum;
961
962XMLNode* _firstChild;
963XMLNode* _lastChild;
964
965XMLNode* _prev;
966XMLNode* _next;
967
968void* _userData;
969
970private:
971 MemPool* _memPool;
972void Unlink( XMLNode* child );
973static void DeleteNode( XMLNode* node );
974void InsertChildPreamble( XMLNode* insertThis ) const;
975const XMLElement* ToElementWithName( const char* name ) const;
976
977XMLNode( const XMLNode& ); // not supported
978XMLNode& operator=( const XMLNode& ); // not supported
979};
980
981
994class TINYXML2_LIB XMLText : public XMLNode
995{
996friend class XMLDocument;
997public:
998virtual bool Accept( XMLVisitor* visitor ) const override;
999
1000virtual XMLText* ToText() override {
1001return this;
1002 }
1003virtual const XMLText* ToText() const override {
1004return this;
1005 }
1006
1008void SetCData( bool isCData ) {
1009 _isCData = isCData;
1010 }
1013return _isCData;
1014 }
1015
1016virtual XMLNode* ShallowClone( XMLDocument* document ) const override;
1017virtual bool ShallowEqual( const XMLNode* compare ) const override;
1018
1019protected:
1020explicit XMLText( XMLDocument* doc ) : XMLNode( doc ), _isCData( false ) {}
1021virtual ~XMLText() {}
1022
1023char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr ) override;
1024
1025private:
1026bool _isCData;
1027
1028 XMLText( const XMLText& ); // not supported
1029 XMLText& operator=( const XMLText& ); // not supported
1030};
1031
1032
1034class TINYXML2_LIB XMLComment : public XMLNode
1035{
1036friend class XMLDocument;
1037public:
1038virtual XMLComment* ToComment() override {
1039return this;
1040 }
1041virtual const XMLComment* ToComment() const override {
1042return this;
1043 }
1044
1045virtual bool Accept( XMLVisitor* visitor ) const override;
1046
1047virtual XMLNode* ShallowClone( XMLDocument* document ) const override;
1048virtual bool ShallowEqual( const XMLNode* compare ) const override;
1049
1050protected:
1051explicit XMLComment( XMLDocument* doc );
1052virtual ~XMLComment();
1053
1054char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr) override;
1055
1056private:
1057XMLComment( const XMLComment& ); // not supported
1058XMLComment& operator=( const XMLComment& ); // not supported
1059};
1060
1061
1073class TINYXML2_LIB XMLDeclaration : public XMLNode
1074{
1075friend class XMLDocument;
1076public:
1077virtual XMLDeclaration* ToDeclaration() override {
1078return this;
1079 }
1080virtual const XMLDeclaration* ToDeclaration() const override {
1081return this;
1082 }
1083
1084virtual bool Accept( XMLVisitor* visitor ) const override;
1085
1086virtual XMLNode* ShallowClone( XMLDocument* document ) const override;
1087virtual bool ShallowEqual( const XMLNode* compare ) const override;
1088
1089protected:
1090explicit XMLDeclaration( XMLDocument* doc );
1091virtual ~XMLDeclaration();
1092
1093char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr ) override;
1094
1095private:
1096XMLDeclaration( const XMLDeclaration& ); // not supported
1097XMLDeclaration& operator=( const XMLDeclaration& ); // not supported
1098};
1099
1100
1108class TINYXML2_LIB XMLUnknown : public XMLNode
1109{
1110friend class XMLDocument;
1111public:
1112virtual XMLUnknown* ToUnknown() override {
1113return this;
1114 }
1115virtual const XMLUnknown* ToUnknown() const override {
1116return this;
1117 }
1118
1119virtual bool Accept( XMLVisitor* visitor ) const override;
1120
1121virtual XMLNode* ShallowClone( XMLDocument* document ) const override;
1122virtual bool ShallowEqual( const XMLNode* compare ) const override;
1123
1124protected:
1125explicit XMLUnknown( XMLDocument* doc );
1126virtual ~XMLUnknown();
1127
1128char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr ) override;
1129
1130private:
1131XMLUnknown( const XMLUnknown& ); // not supported
1132XMLUnknown& operator=( const XMLUnknown& ); // not supported
1133};
1134
1135
1136
1143class TINYXML2_LIB XMLAttribute
1144{
1145friend class XMLElement;
1146public:
1149
1151const char* Value() const;
1152
1154int GetLineNum() const { return _parseLineNum; }
1155
1157const XMLAttribute* Next() const {
1158return _next;
1159 }
1160
1166int i = 0;
1167 QueryIntValue(&i);
1168return i;
1169 }
1170
1171 int64_t Int64Value() const {
1172 int64_t i = 0;
1173 QueryInt64Value(&i);
1174return i;
1175 }
1176
1177 uint64_t Unsigned64Value() const {
1178 uint64_t i = 0;
1179 QueryUnsigned64Value(&i);
1180return i;
1181 }
1182
1184unsigned UnsignedValue() const {
1185unsigned i=0;
1186 QueryUnsignedValue( &i );
1187return i;
1188 }
1191bool b=false;
1192 QueryBoolValue( &b );
1193return b;
1194 }
1196doubleDoubleValue() const {
1197double d=0;
1198 QueryDoubleValue( &d );
1199return d;
1200 }
1202floatFloatValue() const {
1203float f=0;
1204 QueryFloatValue( &f );
1205return f;
1206 }
1207
1212 XMLError QueryIntValue( int* value ) const;
1214 XMLError QueryUnsignedValue( unsigned int* value ) const;
1216 XMLError QueryInt64Value(int64_t* value) const;
1218 XMLError QueryUnsigned64Value(uint64_t* value) const;
1220 XMLError QueryBoolValue( bool* value ) const;
1222 XMLError QueryDoubleValue( double* value ) const;
1224 XMLError QueryFloatValue( float* value ) const;
1225
1227void SetAttribute( const char* value );
1229void SetAttribute( int value );
1231void SetAttribute( unsigned value );
1233void SetAttribute(int64_t value);
1235void SetAttribute(uint64_t value);
1237void SetAttribute( bool value );
1239void SetAttribute( double value );
1241void SetAttribute( float value );
1242
1243private:
1244enum { BUF_SIZE = 200 };
1245
1246XMLAttribute() : _name(), _value(),_parseLineNum( 0 ), _next( 0 ), _memPool( 0 ) {}
1247virtual ~XMLAttribute() {}
1248
1249 XMLAttribute( const XMLAttribute& ); // not supported
1250void operator=( const XMLAttribute& ); // not supported
1251void SetName( const char* name );
1252
1253char* ParseDeep( char* p, bool processEntities, int* curLineNumPtr );
1254
1255mutable StrPair _name;
1256mutable StrPair _value;
1257int _parseLineNum;
1258 XMLAttribute* _next;
1259 MemPool* _memPool;
1260};
1261
1262
1267class TINYXML2_LIB XMLElement : public XMLNode
1268{
1269friend class XMLDocument;
1270public:
1272const char* Name() const {
1273return Value();
1274 }
1276void SetName( const char* str, bool staticMem=false ) {
1277 SetValue( str, staticMem );
1278 }
1279
1280virtual XMLElement* ToElement() override {
1281return this;
1282 }
1283virtual const XMLElement* ToElement() const override {
1284return this;
1285 }
1286virtual bool Accept( XMLVisitor* visitor ) const override;
1287
1311const char* Attribute( const char* name, const char* value=0 ) const;
1312
1319int IntAttribute(const char* name, int defaultValue = 0) const;
1321unsigned UnsignedAttribute(const char* name, unsigned defaultValue = 0) const;
1323 int64_t Int64Attribute(const char* name, int64_t defaultValue = 0) const;
1325 uint64_t Unsigned64Attribute(const char* name, uint64_t defaultValue = 0) const;
1327bool BoolAttribute(const char* name, bool defaultValue = false) const;
1329double DoubleAttribute(const char* name, double defaultValue = 0) const;
1331float FloatAttribute(const char* name, float defaultValue = 0) const;
1332
1346 XMLError QueryIntAttribute( const char* name, int* value ) const {
1347const XMLAttribute* a = FindAttribute( name );
1348if ( !a ) {
1349return XML_NO_ATTRIBUTE;
1350 }
1351return a->QueryIntValue( value );
1352 }
1353
1355 XMLError QueryUnsignedAttribute( const char* name, unsigned int* value ) const {
1356const XMLAttribute* a = FindAttribute( name );
1357if ( !a ) {
1358return XML_NO_ATTRIBUTE;
1359 }
1360return a->QueryUnsignedValue( value );
1361 }
1362
1364 XMLError QueryInt64Attribute(const char* name, int64_t* value) const {
1365const XMLAttribute* a = FindAttribute(name);
1366if (!a) {
1367return XML_NO_ATTRIBUTE;
1368 }
1369return a->QueryInt64Value(value);
1370 }
1371
1373 XMLError QueryUnsigned64Attribute(const char* name, uint64_t* value) const {
1374const XMLAttribute* a = FindAttribute(name);
1375if(!a) {
1376return XML_NO_ATTRIBUTE;
1377 }
1378return a->QueryUnsigned64Value(value);
1379 }
1380
1382 XMLError QueryBoolAttribute( const char* name, bool* value ) const {
1383const XMLAttribute* a = FindAttribute( name );
1384if ( !a ) {
1385return XML_NO_ATTRIBUTE;
1386 }
1387return a->QueryBoolValue( value );
1388 }
1390 XMLError QueryDoubleAttribute( const char* name, double* value ) const {
1391const XMLAttribute* a = FindAttribute( name );
1392if ( !a ) {
1393return XML_NO_ATTRIBUTE;
1394 }
1395return a->QueryDoubleValue( value );
1396 }
1398 XMLError QueryFloatAttribute( const char* name, float* value ) const {
1399const XMLAttribute* a = FindAttribute( name );
1400if ( !a ) {
1401return XML_NO_ATTRIBUTE;
1402 }
1403return a->QueryFloatValue( value );
1404 }
1405
1407 XMLError QueryStringAttribute(const char* name, const char** value) const {
1408const XMLAttribute* a = FindAttribute(name);
1409if (!a) {
1410return XML_NO_ATTRIBUTE;
1411 }
1412 *value = a->Value();
1413return XML_SUCCESS;
1414 }
1415
1416
1417
1435 XMLError QueryAttribute( const char* name, int* value ) const {
1436return QueryIntAttribute( name, value );
1437 }
1438
1439 XMLError QueryAttribute( const char* name, unsigned int* value ) const {
1440return QueryUnsignedAttribute( name, value );
1441 }
1442
1443 XMLError QueryAttribute(const char* name, int64_t* value) const {
1444return QueryInt64Attribute(name, value);
1445 }
1446
1447 XMLError QueryAttribute(const char* name, uint64_t* value) const {
1448return QueryUnsigned64Attribute(name, value);
1449 }
1450
1451 XMLError QueryAttribute( const char* name, bool* value ) const {
1452return QueryBoolAttribute( name, value );
1453 }
1454
1455 XMLError QueryAttribute( const char* name, double* value ) const {
1456return QueryDoubleAttribute( name, value );
1457 }
1458
1459 XMLError QueryAttribute( const char* name, float* value ) const {
1460return QueryFloatAttribute( name, value );
1461 }
1462
1463 XMLError QueryAttribute(const char* name, const char** value) const {
1464return QueryStringAttribute(name, value);
1465 }
1466
1468void SetAttribute( const char* name, const char* value ) {
1469XMLAttribute* a = FindOrCreateAttribute( name );
1470 a->SetAttribute( value );
1471 }
1473void SetAttribute( const char* name, int value ) {
1474XMLAttribute* a = FindOrCreateAttribute( name );
1475 a->SetAttribute( value );
1476 }
1478void SetAttribute( const char* name, unsigned value ) {
1479XMLAttribute* a = FindOrCreateAttribute( name );
1480 a->SetAttribute( value );
1481 }
1482
1484void SetAttribute(const char* name, int64_t value) {
1485XMLAttribute* a = FindOrCreateAttribute(name);
1486 a->SetAttribute(value);
1487 }
1488
1490void SetAttribute(const char* name, uint64_t value) {
1491XMLAttribute* a = FindOrCreateAttribute(name);
1492 a->SetAttribute(value);
1493 }
1494
1496void SetAttribute( const char* name, bool value ) {
1497XMLAttribute* a = FindOrCreateAttribute( name );
1498 a->SetAttribute( value );
1499 }
1501void SetAttribute( const char* name, double value ) {
1502XMLAttribute* a = FindOrCreateAttribute( name );
1503 a->SetAttribute( value );
1504 }
1506void SetAttribute( const char* name, float value ) {
1507XMLAttribute* a = FindOrCreateAttribute( name );
1508 a->SetAttribute( value );
1509 }
1510
1514void DeleteAttribute( const char* name );
1515
1517const XMLAttribute* FirstAttribute() const {
1518return _rootAttribute;
1519 }
1521const XMLAttribute* FindAttribute( const char* name ) const;
1522
1551const char* GetText() const;
1552
1587void SetText( const char* inText );
1589void SetText( int value );
1591void SetText( unsigned value );
1593void SetText(int64_t value);
1595void SetText(uint64_t value);
1597void SetText( bool value );
1599void SetText( double value );
1601void SetText( float value );
1602
1629 XMLError QueryIntText( int* ival ) const;
1631 XMLError QueryUnsignedText( unsigned* uval ) const;
1633 XMLError QueryInt64Text(int64_t* uval) const;
1635 XMLError QueryUnsigned64Text(uint64_t* uval) const;
1637 XMLError QueryBoolText( bool* bval ) const;
1639 XMLError QueryDoubleText( double* dval ) const;
1641 XMLError QueryFloatText( float* fval ) const;
1642
1643int IntText(int defaultValue = 0) const;
1644
1646unsigned UnsignedText(unsigned defaultValue = 0) const;
1648 int64_t Int64Text(int64_t defaultValue = 0) const;
1650 uint64_t Unsigned64Text(uint64_t defaultValue = 0) const;
1652bool BoolText(bool defaultValue = false) const;
1654double DoubleText(double defaultValue = 0) const;
1656float FloatText(float defaultValue = 0) const;
1657
1662XMLElement* InsertNewChildElement(const char* name);
1664XMLComment* InsertNewComment(const char* comment);
1666XMLText* InsertNewText(const char* text);
1668XMLDeclaration* InsertNewDeclaration(const char* text);
1670XMLUnknown* InsertNewUnknown(const char* text);
1671
1672
1673// internal:
1674enum ElementClosingType {
1675 OPEN, // <foo>
1676 CLOSED, // <foo/>
1677 CLOSING // </foo>
1678 };
1679 ElementClosingType ClosingType() const {
1680return _closingType;
1681 }
1682virtual XMLNode* ShallowClone( XMLDocument* document ) const override;
1683virtual bool ShallowEqual( const XMLNode* compare ) const override;
1684
1685protected:
1686char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr ) override;
1687
1688private:
1689XMLElement( XMLDocument* doc );
1690virtual ~XMLElement();
1691XMLElement( const XMLElement& ); // not supported
1692void operator=( const XMLElement& ); // not supported
1693
1694XMLAttribute* FindOrCreateAttribute( const char* name );
1695char* ParseAttributes( char* p, int* curLineNumPtr );
1696static void DeleteAttribute( XMLAttribute* attribute );
1697XMLAttribute* CreateAttribute();
1698
1699enum { BUF_SIZE = 200 };
1700 ElementClosingType _closingType;
1701// The attribute list is ordered; there is no 'lastAttribute'
1702// because the list needs to be scanned for dupes before adding
1703// a new attribute.
1704XMLAttribute* _rootAttribute;
1705};
1706
1707
1708enum Whitespace {
1709 PRESERVE_WHITESPACE,
1710 COLLAPSE_WHITESPACE,
1711 PEDANTIC_WHITESPACE
1712};
1713
1714
1720class TINYXML2_LIB XMLDocument : public XMLNode
1721{
1722friend class XMLElement;
1723// Gives access to SetError and Push/PopDepth, but over-access for everything else.
1724// Wishing C++ had "internal" scope.
1725friend class XMLNode;
1726friend class XMLText;
1727friend class XMLComment;
1728friend class XMLDeclaration;
1729friend class XMLUnknown;
1730public:
1732XMLDocument( bool processEntities = true, Whitespace whitespaceMode = PRESERVE_WHITESPACE );
1733~XMLDocument();
1734
1735virtual XMLDocument* ToDocument() override {
1736 TIXMLASSERT( this == _document );
1737return this;
1738 }
1739virtual const XMLDocument* ToDocument() const override {
1740 TIXMLASSERT( this == _document );
1741return this;
1742 }
1743
1754 XMLError Parse( const char* xml, size_t nBytes=static_cast<size_t>(-1) );
1755
1761 XMLError LoadFile( const char* filename );
1762
1774 XMLError LoadFile( FILE* );
1775
1781 XMLError SaveFile( const char* filename, bool compact = false );
1782
1790 XMLError SaveFile( FILE* fp, bool compact = false );
1791
1792bool ProcessEntities() const {
1793return _processEntities;
1794 }
1795 Whitespace WhitespaceMode() const {
1796return _whitespaceMode;
1797 }
1798
1803return _writeBOM;
1804 }
1807void SetBOM( bool useBOM ) {
1808 _writeBOM = useBOM;
1809 }
1810
1814XMLElement* RootElement() {
1815return FirstChildElement();
1816 }
1817const XMLElement* RootElement() const {
1818return FirstChildElement();
1819 }
1820
1835void Print( XMLPrinter* streamer=0 ) const;
1836virtual bool Accept( XMLVisitor* visitor ) const override;
1837
1843XMLElement* NewElement( const char* name );
1849XMLComment* NewComment( const char* comment );
1855XMLText* NewText( const char* text );
1867XMLDeclaration* NewDeclaration( const char* text=0 );
1873XMLUnknown* NewUnknown( const char* text );
1874
1879void DeleteNode( XMLNode* node );
1880
1882void ClearError();
1883
1886return _errorID != XML_SUCCESS;
1887 }
1889 XMLError ErrorID() const {
1890return _errorID;
1891 }
1892const char* ErrorName() const;
1893static const char* ErrorIDToName(XMLError errorID);
1894
1898const char* ErrorStr() const;
1899
1901void PrintError() const;
1902
1904int ErrorLineNum() const
1905{
1906return _errorLineNum;
1907 }
1908
1911
1919void DeepCopy(XMLDocument* target) const;
1920
1921// internal
1922char* Identify( char* p, XMLNode** node, bool first );
1923
1924// internal
1925void MarkInUse(const XMLNode* const);
1926
1927virtual XMLNode* ShallowClone( XMLDocument* /*document*/ ) const override{
1928return 0;
1929 }
1930virtual bool ShallowEqual( const XMLNode* /*compare*/ ) const override{
1931return false;
1932 }
1933
1934private:
1935XMLDocument( const XMLDocument& ); // not supported
1936void operator=( const XMLDocument& ); // not supported
1937
1938bool _writeBOM;
1939bool _processEntities;
1940 XMLError _errorID;
1941 Whitespace _whitespaceMode;
1942mutable StrPair _errorStr;
1943int _errorLineNum;
1944char* _charBuffer;
1945int _parseCurLineNum;
1946int _parsingDepth;
1947// Memory tracking does add some overhead.
1948// However, the code assumes that you don't
1949// have a bunch of unlinked nodes around.
1950// Therefore it takes less memory to track
1951// in the document vs. a linked list in the XMLNode,
1952// and the performance is the same.
1953 DynArray<XMLNode*, 10> _unlinked;
1954
1955 MemPoolT< sizeof(XMLElement) > _elementPool;
1956 MemPoolT< sizeof(XMLAttribute) > _attributePool;
1957 MemPoolT< sizeof(XMLText) > _textPool;
1958 MemPoolT< sizeof(XMLComment) > _commentPool;
1959
1960static const char* _errorNames[XML_ERROR_COUNT];
1961
1962void Parse();
1963
1964void SetError( XMLError error, int lineNum, const char* format, ... );
1965
1966// Something of an obvious security hole, once it was discovered.
1967// Either an ill-formed XML or an excessively deep one can overflow
1968// the stack. Track stack depth, and error out if needed.
1969class DepthTracker {
1970public:
1971explicit DepthTracker(XMLDocument * document) {
1972 this->_document = document;
1973 document->PushDepth();
1974 }
1975 ~DepthTracker() {
1976 _document->PopDepth();
1977 }
1978private:
1979 XMLDocument * _document;
1980 };
1981void PushDepth();
1982void PopDepth();
1983
1984template<class NodeType, int PoolElementSize>
1985 NodeType* CreateUnlinkedNode( MemPoolT<PoolElementSize>& pool );
1986};
1987
1988template<class NodeType, int PoolElementSize>
1989inline NodeType* XMLDocument::CreateUnlinkedNode( MemPoolT<PoolElementSize>& pool )
1990{
1991 TIXMLASSERT( sizeof( NodeType ) == PoolElementSize );
1992 TIXMLASSERT( sizeof( NodeType ) == pool.ItemSize() );
1993 NodeType* returnNode = new (pool.Alloc()) NodeType( this );
1994 TIXMLASSERT( returnNode );
1995 returnNode->_memPool = &pool;
1996
1997 _unlinked.Push(returnNode);
1998return returnNode;
1999}
2000
2056class TINYXML2_LIB XMLHandle
2057{
2058public:
2060explicit XMLHandle( XMLNode* node ) : _node( node ) {
2061 }
2063explicit XMLHandle( XMLNode& node ) : _node( &node ) {
2064 }
2066XMLHandle( const XMLHandle& ref ) : _node( ref._node ) {
2067 }
2069XMLHandle& operator=( const XMLHandle& ref ) {
2070 _node = ref._node;
2071return *this;
2072 }
2073
2076return XMLHandle( _node ? _node->FirstChild() : 0 );
2077 }
2079XMLHandle FirstChildElement( const char* name = 0 ) {
2080return XMLHandle( _node ? _node->FirstChildElement( name ) : 0 );
2081 }
2084return XMLHandle( _node ? _node->LastChild() : 0 );
2085 }
2087XMLHandle LastChildElement( const char* name = 0 ) {
2088return XMLHandle( _node ? _node->LastChildElement( name ) : 0 );
2089 }
2091XMLHandle PreviousSibling() {
2092return XMLHandle( _node ? _node->PreviousSibling() : 0 );
2093 }
2095XMLHandle PreviousSiblingElement( const char* name = 0 ) {
2096return XMLHandle( _node ? _node->PreviousSiblingElement( name ) : 0 );
2097 }
2100return XMLHandle( _node ? _node->NextSibling() : 0 );
2101 }
2103XMLHandle NextSiblingElement( const char* name = 0 ) {
2104return XMLHandle( _node ? _node->NextSiblingElement( name ) : 0 );
2105 }
2106
2109return _node;
2110 }
2112XMLElement* ToElement() {
2113return ( _node ? _node->ToElement() : 0 );
2114 }
2117return ( _node ? _node->ToText() : 0 );
2118 }
2120XMLUnknown* ToUnknown() {
2121return ( _node ? _node->ToUnknown() : 0 );
2122 }
2124XMLDeclaration* ToDeclaration() {
2125return ( _node ? _node->ToDeclaration() : 0 );
2126 }
2127
2128private:
2129XMLNode* _node;
2130};
2131
2132
2137class TINYXML2_LIB XMLConstHandle
2138{
2139public:
2140explicit XMLConstHandle( const XMLNode* node ) : _node( node ) {
2141 }
2142explicit XMLConstHandle( const XMLNode& node ) : _node( &node ) {
2143 }
2144XMLConstHandle( const XMLConstHandle& ref ) : _node( ref._node ) {
2145 }
2146
2147XMLConstHandle& operator=( const XMLConstHandle& ref ) {
2148 _node = ref._node;
2149return *this;
2150 }
2151
2152const XMLConstHandle FirstChild() const {
2153return XMLConstHandle( _node ? _node->FirstChild() : 0 );
2154 }
2155const XMLConstHandle FirstChildElement( const char* name = 0 ) const {
2156return XMLConstHandle( _node ? _node->FirstChildElement( name ) : 0 );
2157 }
2158const XMLConstHandle LastChild() const {
2159return XMLConstHandle( _node ? _node->LastChild() : 0 );
2160 }
2161const XMLConstHandle LastChildElement( const char* name = 0 ) const {
2162return XMLConstHandle( _node ? _node->LastChildElement( name ) : 0 );
2163 }
2164const XMLConstHandle PreviousSibling() const {
2165return XMLConstHandle( _node ? _node->PreviousSibling() : 0 );
2166 }
2167const XMLConstHandle PreviousSiblingElement( const char* name = 0 ) const {
2168return XMLConstHandle( _node ? _node->PreviousSiblingElement( name ) : 0 );
2169 }
2170const XMLConstHandle NextSibling() const {
2171return XMLConstHandle( _node ? _node->NextSibling() : 0 );
2172 }
2173const XMLConstHandle NextSiblingElement( const char* name = 0 ) const {
2174return XMLConstHandle( _node ? _node->NextSiblingElement( name ) : 0 );
2175 }
2176
2177
2178const XMLNode* ToNode() const {
2179return _node;
2180 }
2181const XMLElement* ToElement() const {
2182return ( _node ? _node->ToElement() : 0 );
2183 }
2184const XMLText* ToText() const {
2185return ( _node ? _node->ToText() : 0 );
2186 }
2187const XMLUnknown* ToUnknown() const {
2188return ( _node ? _node->ToUnknown() : 0 );
2189 }
2190const XMLDeclaration* ToDeclaration() const {
2191return ( _node ? _node->ToDeclaration() : 0 );
2192 }
2193
2194private:
2195const XMLNode* _node;
2196};
2197
2198
2241class TINYXML2_LIB XMLPrinter : public XMLVisitor
2242{
2243public:
2250XMLPrinter( FILE* file=0, bool compact = false, int depth = 0 );
2251virtual ~XMLPrinter() {}
2252
2254void PushHeader( bool writeBOM, bool writeDeclaration );
2258void OpenElement( const char* name, bool compactMode=false );
2260void PushAttribute( const char* name, const char* value );
2261void PushAttribute( const char* name, int value );
2262void PushAttribute( const char* name, unsigned value );
2263void PushAttribute( const char* name, int64_t value );
2264void PushAttribute( const char* name, uint64_t value );
2265void PushAttribute( const char* name, bool value );
2266void PushAttribute( const char* name, double value );
2268virtual void CloseElement( bool compactMode=false );
2269
2271void PushText( const char* text, bool cdata=false );
2273void PushText( int value );
2275void PushText( unsigned value );
2277void PushText( int64_t value );
2279void PushText( uint64_t value );
2281void PushText( bool value );
2283void PushText( float value );
2285void PushText( double value );
2286
2288void PushComment( const char* comment );
2289
2290void PushDeclaration( const char* value );
2291void PushUnknown( const char* value );
2292
2293virtual bool VisitEnter( const XMLDocument& /*doc*/ ) override;
2294virtual bool VisitExit( const XMLDocument& /*doc*/ ) override {
2295return true;
2296 }
2297
2298virtual bool VisitEnter( const XMLElement& element, const XMLAttribute* attribute ) override;
2299virtual bool VisitExit( const XMLElement& element ) override;
2300
2301virtual bool Visit( const XMLText& text ) override;
2302virtual bool Visit( const XMLComment& comment ) override;
2303virtual bool Visit( const XMLDeclaration& declaration ) override;
2304virtual bool Visit( const XMLUnknown& unknown ) override;
2305
2310const char* CStr() const {
2311return _buffer.Mem();
2312 }
2319return _buffer.Size();
2320 }
2325void ClearBuffer( bool resetToFirstElement = true ) {
2326 _buffer.Clear();
2327 _buffer.Push(0);
2328 _firstElement = resetToFirstElement;
2329 }
2330
2331protected:
2332virtual bool CompactMode( const XMLElement& ) { return _compactMode; }
2333
2337virtual void PrintSpace( int depth );
2338virtual void Print( const char* format, ... );
2339virtual void Write( const char* data, size_t size );
2340virtual void Putc( char ch );
2341
2342inline void Write(const char* data) { Write(data, strlen(data)); }
2343
2344void SealElementIfJustOpened();
2345bool _elementJustOpened;
2346 DynArray< const char*, 10 > _stack;
2347
2348private:
2353void PrepareForNewNode( bool compactMode );
2354void PrintString( const char*, bool restrictedEntitySet ); // prints out, after detecting entities.
2355
2356bool _firstElement;
2357 FILE* _fp;
2358int _depth;
2359int _textDepth;
2360bool _processEntities;
2361bool _compactMode;
2362
2363enum {
2364 ENTITY_RANGE = 64,
2365 BUF_SIZE = 200
2366 };
2367bool _entityFlag[ENTITY_RANGE];
2368bool _restrictedEntityFlag[ENTITY_RANGE];
2369
2370 DynArray< char, 20 > _buffer;
2371
2372// Prohibit cloning, intentionally not implemented
2373 XMLPrinter( const XMLPrinter& );
2374 XMLPrinter& operator=( const XMLPrinter& );
2375};
2376
2377
2378} // tinyxml2
2379
2380#if defined(_MSC_VER)
2381# pragma warning(pop)
2382#endif
2383
2384#endif // TINYXML2_INCLUDED
Definition tinyxml2.h:1144
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:1154
tinyxml2::XMLAttribute::QueryFloatValue
XMLError QueryFloatValue(float *value) const
See QueryIntValue.
tinyxml2::XMLAttribute::UnsignedValue
unsigned UnsignedValue() const
Query as an unsigned integer. See IntValue()
Definition tinyxml2.h:1184
tinyxml2::XMLAttribute::SetAttribute
void SetAttribute(uint64_t value)
Set the attribute to value.
tinyxml2::XMLAttribute::FloatValue
float FloatValue() const
Query as a float. See IntValue()
Definition tinyxml2.h:1202
tinyxml2::XMLAttribute::QueryDoubleValue
XMLError QueryDoubleValue(double *value) const
See QueryIntValue.
tinyxml2::XMLAttribute::SetAttribute
void SetAttribute(const char *value)
Set the attribute to a string value.
tinyxml2::XMLAttribute::QueryUnsignedValue
XMLError QueryUnsignedValue(unsigned int *value) const
See QueryIntValue.
tinyxml2::XMLAttribute::DoubleValue
double DoubleValue() const
Query as a double. See IntValue()
Definition tinyxml2.h:1196
tinyxml2::XMLAttribute::QueryInt64Value
XMLError QueryInt64Value(int64_t *value) const
See QueryIntValue.
const char * Name() const
The name of the attribute.
tinyxml2::XMLAttribute::QueryBoolValue
XMLError QueryBoolValue(bool *value) const
See QueryIntValue.
tinyxml2::XMLAttribute::QueryIntValue
XMLError QueryIntValue(int *value) const
tinyxml2::XMLAttribute::SetAttribute
void SetAttribute(int64_t value)
Set the attribute to value.
tinyxml2::XMLAttribute::BoolValue
bool BoolValue() const
Query as a boolean. See IntValue()
Definition tinyxml2.h:1190
tinyxml2::XMLAttribute::SetAttribute
void SetAttribute(double value)
Set the attribute to value.
const XMLAttribute * Next() const
The next attribute in the list.
Definition tinyxml2.h:1157
const char * Value() const
The value of the attribute.
tinyxml2::XMLAttribute::SetAttribute
void SetAttribute(bool value)
Set the attribute to value.
tinyxml2::XMLAttribute::SetAttribute
void SetAttribute(int value)
Set the attribute to value.
tinyxml2::XMLAttribute::IntValue
int IntValue() const
Definition tinyxml2.h:1165
tinyxml2::XMLAttribute::SetAttribute
void SetAttribute(unsigned value)
Set the attribute to value.
tinyxml2::XMLAttribute::SetAttribute
void SetAttribute(float value)
Set the attribute to value.
tinyxml2::XMLAttribute::QueryUnsigned64Value
XMLError QueryUnsigned64Value(uint64_t *value) const
See QueryIntValue.
Definition tinyxml2.h:1035
virtual bool Accept(XMLVisitor *visitor) const override
tinyxml2::XMLComment::ShallowClone
virtual XMLNode * ShallowClone(XMLDocument *document) const override
tinyxml2::XMLComment::ShallowEqual
virtual bool ShallowEqual(const XMLNode *compare) const override
tinyxml2::XMLComment::ToComment
virtual XMLComment * ToComment() override
Safely cast to a Comment, or null.
Definition tinyxml2.h:1038
Definition tinyxml2.h:2138
Definition tinyxml2.h:1074
tinyxml2::XMLDeclaration::ShallowClone
virtual XMLNode * ShallowClone(XMLDocument *document) const override
tinyxml2::XMLDeclaration::ShallowEqual
virtual bool ShallowEqual(const XMLNode *compare) const override
tinyxml2::XMLDeclaration::ToDeclaration
virtual XMLDeclaration * ToDeclaration() override
Safely cast to a Declaration, or null.
Definition tinyxml2.h:1077
tinyxml2::XMLDeclaration::Accept
virtual bool Accept(XMLVisitor *visitor) const override
Definition tinyxml2.h:1721
tinyxml2::XMLDocument::ShallowClone
virtual XMLNode * ShallowClone(XMLDocument *) const override
Definition tinyxml2.h:1927
tinyxml2::XMLDocument::RootElement
XMLElement * RootElement()
Definition tinyxml2.h:1814
void SetBOM(bool useBOM)
Definition tinyxml2.h:1807
tinyxml2::XMLDocument::PrintError
void PrintError() const
A (trivial) utility function that prints the ErrorStr() to stdout.
tinyxml2::XMLDocument::ToDocument
virtual XMLDocument * ToDocument() override
Safely cast to a Document, or null.
Definition tinyxml2.h:1735
tinyxml2::XMLDocument::LoadFile
XMLError LoadFile(const char *filename)
bool HasBOM() const
Definition tinyxml2.h:1802
bool Error() const
Return true if there was an error parsing the document.
Definition tinyxml2.h:1885
tinyxml2::XMLDocument::NewComment
XMLComment * NewComment(const char *comment)
tinyxml2::XMLDocument::NewElement
XMLElement * NewElement(const char *name)
tinyxml2::XMLDocument::ClearError
void ClearError()
Clears the error flags.
tinyxml2::XMLDocument::NewUnknown
XMLUnknown * NewUnknown(const char *text)
tinyxml2::XMLDocument::ErrorLineNum
int ErrorLineNum() const
Return the line where the error occurred, or zero if unknown.
Definition tinyxml2.h:1904
tinyxml2::XMLDocument::XMLDocument
XMLDocument(bool processEntities=true, Whitespace whitespaceMode=PRESERVE_WHITESPACE)
constructor
tinyxml2::XMLDocument::LoadFile
XMLError LoadFile(FILE *)
void Clear()
Clear the document, resetting it to the initial state.
tinyxml2::XMLDocument::SaveFile
XMLError SaveFile(const char *filename, bool compact=false)
virtual bool Accept(XMLVisitor *visitor) const override
void Print(XMLPrinter *streamer=0) const
tinyxml2::XMLDocument::SaveFile
XMLError SaveFile(FILE *fp, bool compact=false)
tinyxml2::XMLDocument::DeleteNode
void DeleteNode(XMLNode *node)
tinyxml2::XMLDocument::ShallowEqual
virtual bool ShallowEqual(const XMLNode *) const override
Definition tinyxml2.h:1930
tinyxml2::XMLDocument::NewText
XMLText * NewText(const char *text)
tinyxml2::XMLDocument::NewDeclaration
XMLDeclaration * NewDeclaration(const char *text=0)
tinyxml2::XMLDocument::ErrorStr
const char * ErrorStr() const
XMLError Parse(const char *xml, size_t nBytes=static_cast< size_t >(-1))
tinyxml2::XMLDocument::DeepCopy
void DeepCopy(XMLDocument *target) const
tinyxml2::XMLDocument::ErrorID
XMLError ErrorID() const
Return the errorID.
Definition tinyxml2.h:1889
Definition tinyxml2.h:1268
const char * GetText() const
tinyxml2::XMLElement::DoubleAttribute
double DoubleAttribute(const char *name, double defaultValue=0) const
See IntAttribute()
tinyxml2::XMLElement::SetAttribute
void SetAttribute(const char *name, const char *value)
Sets the named attribute to value.
Definition tinyxml2.h:1468
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:1373
tinyxml2::XMLElement::QueryBoolAttribute
XMLError QueryBoolAttribute(const char *name, bool *value) const
See QueryIntAttribute()
Definition tinyxml2.h:1382
tinyxml2::XMLElement::QueryUnsignedText
XMLError QueryUnsignedText(unsigned *uval) const
See QueryIntText()
tinyxml2::XMLElement::FindAttribute
const XMLAttribute * FindAttribute(const char *name) const
Query a specific attribute in the list.
void SetText(const char *inText)
tinyxml2::XMLElement::Unsigned64Attribute
uint64_t Unsigned64Attribute(const char *name, uint64_t defaultValue=0) const
See IntAttribute()
tinyxml2::XMLElement::SetAttribute
void SetAttribute(const char *name, double value)
Sets the named attribute to value.
Definition tinyxml2.h:1501
tinyxml2::XMLElement::QueryUnsignedAttribute
XMLError QueryUnsignedAttribute(const char *name, unsigned int *value) const
See QueryIntAttribute()
Definition tinyxml2.h:1355
tinyxml2::XMLElement::QueryBoolText
XMLError QueryBoolText(bool *bval) const
See QueryIntText()
tinyxml2::XMLElement::FloatText
float FloatText(float defaultValue=0) const
See QueryIntText()
tinyxml2::XMLElement::Attribute
const char * Attribute(const char *name, const char *value=0) const
tinyxml2::XMLElement::UnsignedText
unsigned UnsignedText(unsigned defaultValue=0) const
See QueryIntText()
tinyxml2::XMLElement::FirstAttribute
const XMLAttribute * FirstAttribute() const
Return the first attribute in the list.
Definition tinyxml2.h:1517
void SetText(float value)
Convenience method for setting text inside an element. See SetText() for important limitations.
tinyxml2::XMLElement::BoolAttribute
bool BoolAttribute(const char *name, bool defaultValue=false) const
See IntAttribute()
tinyxml2::XMLElement::SetAttribute
void SetAttribute(const char *name, float value)
Sets the named attribute to value.
Definition tinyxml2.h:1506
tinyxml2::XMLElement::QueryAttribute
XMLError QueryAttribute(const char *name, int *value) const
Definition tinyxml2.h:1435
tinyxml2::XMLElement::QueryDoubleAttribute
XMLError QueryDoubleAttribute(const char *name, double *value) const
See QueryIntAttribute()
Definition tinyxml2.h:1390
tinyxml2::XMLElement::Int64Attribute
int64_t Int64Attribute(const char *name, int64_t defaultValue=0) const
See IntAttribute()
void SetText(double value)
Convenience method for setting text inside an element. See SetText() for important limitations.
tinyxml2::XMLElement::QueryDoubleText
XMLError QueryDoubleText(double *dval) const
See QueryIntText()
tinyxml2::XMLElement::BoolText
bool BoolText(bool defaultValue=false) const
See QueryIntText()
tinyxml2::XMLElement::ShallowClone
virtual XMLNode * ShallowClone(XMLDocument *document) const override
void SetText(uint64_t value)
Convenience method for setting text inside an element. See SetText() for important limitations.
void SetText(int64_t value)
Convenience method for setting text inside an element. See SetText() for important limitations.
void SetText(unsigned value)
Convenience method for setting text inside an element. See SetText() for important limitations.
tinyxml2::XMLElement::QueryInt64Attribute
XMLError QueryInt64Attribute(const char *name, int64_t *value) const
See QueryIntAttribute()
Definition tinyxml2.h:1364
tinyxml2::XMLElement::InsertNewDeclaration
XMLDeclaration * InsertNewDeclaration(const char *text)
See InsertNewChildElement()
tinyxml2::XMLElement::DoubleText
double DoubleText(double defaultValue=0) const
See QueryIntText()
tinyxml2::XMLElement::ToElement
virtual XMLElement * ToElement() override
Safely cast to an Element, or null.
Definition tinyxml2.h:1280
tinyxml2::XMLElement::QueryIntAttribute
XMLError QueryIntAttribute(const char *name, int *value) const
Definition tinyxml2.h:1346
tinyxml2::XMLElement::QueryIntText
XMLError QueryIntText(int *ival) const
tinyxml2::XMLElement::IntAttribute
int IntAttribute(const char *name, int defaultValue=0) const
void SetName(const char *str, bool staticMem=false)
Set the name of the element.
Definition tinyxml2.h:1276
tinyxml2::XMLElement::SetAttribute
void SetAttribute(const char *name, bool value)
Sets the named attribute to value.
Definition tinyxml2.h:1496
tinyxml2::XMLElement::Int64Text
int64_t Int64Text(int64_t defaultValue=0) const
See QueryIntText()
tinyxml2::XMLElement::ShallowEqual
virtual bool ShallowEqual(const XMLNode *compare) const override
tinyxml2::XMLElement::SetAttribute
void SetAttribute(const char *name, int value)
Sets the named attribute to value.
Definition tinyxml2.h:1473
tinyxml2::XMLElement::InsertNewComment
XMLComment * InsertNewComment(const char *comment)
See InsertNewChildElement()
tinyxml2::XMLElement::SetAttribute
void SetAttribute(const char *name, int64_t value)
Sets the named attribute to value.
Definition tinyxml2.h:1484
tinyxml2::XMLElement::FloatAttribute
float FloatAttribute(const char *name, float defaultValue=0) const
See IntAttribute()
const char * Name() const
Get the name of an element (which is the Value() of the node.)
Definition tinyxml2.h:1272
tinyxml2::XMLElement::InsertNewChildElement
XMLElement * InsertNewChildElement(const char *name)
tinyxml2::XMLElement::QueryUnsigned64Text
XMLError QueryUnsigned64Text(uint64_t *uval) const
See QueryIntText()
tinyxml2::XMLElement::InsertNewText
XMLText * InsertNewText(const char *text)
See InsertNewChildElement()
virtual bool Accept(XMLVisitor *visitor) const override
tinyxml2::XMLElement::QueryFloatAttribute
XMLError QueryFloatAttribute(const char *name, float *value) const
See QueryIntAttribute()
Definition tinyxml2.h:1398
tinyxml2::XMLElement::SetAttribute
void SetAttribute(const char *name, uint64_t value)
Sets the named attribute to value.
Definition tinyxml2.h:1490
tinyxml2::XMLElement::QueryStringAttribute
XMLError QueryStringAttribute(const char *name, const char **value) const
See QueryIntAttribute()
Definition tinyxml2.h:1407
tinyxml2::XMLElement::SetAttribute
void SetAttribute(const char *name, unsigned value)
Sets the named attribute to value.
Definition tinyxml2.h:1478
void SetText(bool value)
Convenience method for setting text inside an element. See SetText() for important limitations.
void SetText(int value)
Convenience method for setting text inside an element. See SetText() for important limitations.
tinyxml2::XMLElement::DeleteAttribute
void DeleteAttribute(const char *name)
tinyxml2::XMLElement::Unsigned64Text
uint64_t Unsigned64Text(uint64_t defaultValue=0) const
See QueryIntText()
tinyxml2::XMLElement::QueryFloatText
XMLError QueryFloatText(float *fval) const
See QueryIntText()
tinyxml2::XMLElement::InsertNewUnknown
XMLUnknown * InsertNewUnknown(const char *text)
See InsertNewChildElement()
tinyxml2::XMLElement::UnsignedAttribute
unsigned UnsignedAttribute(const char *name, unsigned defaultValue=0) const
See IntAttribute()
Definition tinyxml2.h:2057
tinyxml2::XMLHandle::PreviousSibling
XMLHandle PreviousSibling()
Get the previous sibling of this handle.
Definition tinyxml2.h:2091
tinyxml2::XMLHandle::LastChildElement
XMLHandle LastChildElement(const char *name=0)
Get the last child element of this handle.
Definition tinyxml2.h:2087
tinyxml2::XMLHandle::FirstChild
XMLHandle FirstChild()
Get the first child of this handle.
Definition tinyxml2.h:2075
XMLNode * ToNode()
Safe cast to XMLNode. This can return null.
Definition tinyxml2.h:2108
tinyxml2::XMLHandle::FirstChildElement
XMLHandle FirstChildElement(const char *name=0)
Get the first child element of this handle.
Definition tinyxml2.h:2079
tinyxml2::XMLHandle::PreviousSiblingElement
XMLHandle PreviousSiblingElement(const char *name=0)
Get the previous sibling element of this handle.
Definition tinyxml2.h:2095
tinyxml2::XMLHandle::ToDeclaration
XMLDeclaration * ToDeclaration()
Safe cast to XMLDeclaration. This can return null.
Definition tinyxml2.h:2124
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:2060
tinyxml2::XMLHandle::LastChild
XMLHandle LastChild()
Get the last child of this handle.
Definition tinyxml2.h:2083
tinyxml2::XMLHandle::operator=
XMLHandle & operator=(const XMLHandle &ref)
Assignment.
Definition tinyxml2.h:2069
tinyxml2::XMLHandle::XMLHandle
XMLHandle(XMLNode &node)
Create a handle from a node.
Definition tinyxml2.h:2063
tinyxml2::XMLHandle::NextSibling
XMLHandle NextSibling()
Get the next sibling of this handle.
Definition tinyxml2.h:2099
tinyxml2::XMLHandle::ToElement
XMLElement * ToElement()
Safe cast to XMLElement. This can return null.
Definition tinyxml2.h:2112
XMLText * ToText()
Safe cast to XMLText. This can return null.
Definition tinyxml2.h:2116
tinyxml2::XMLHandle::ToUnknown
XMLUnknown * ToUnknown()
Safe cast to XMLUnknown. This can return null.
Definition tinyxml2.h:2120
tinyxml2::XMLHandle::NextSiblingElement
XMLHandle NextSiblingElement(const char *name=0)
Get the next sibling element of this handle.
Definition tinyxml2.h:2103
tinyxml2::XMLHandle::XMLHandle
XMLHandle(const XMLHandle &ref)
Copy constructor.
Definition tinyxml2.h:2066
Definition tinyxml2.h:672
tinyxml2::XMLNode::SetUserData
void SetUserData(void *userData)
Definition tinyxml2.h:942
tinyxml2::XMLNode::DeleteChildren
void DeleteChildren()
const char * Value() const
void SetValue(const char *val, bool staticMem=false)
virtual XMLText * ToText()
Safely cast to Text, or null.
Definition tinyxml2.h:693
tinyxml2::XMLNode::ToDeclaration
virtual XMLDeclaration * ToDeclaration()
Safely cast to a Declaration, or null.
Definition tinyxml2.h:705
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::XMLNode::GetUserData
void * GetUserData() const
Definition tinyxml2.h:949
tinyxml2::XMLNode::FirstChildElement
const XMLElement * FirstChildElement(const char *name=0) const
tinyxml2::XMLNode::DeleteChild
void DeleteChild(XMLNode *node)
XMLNode * DeepClone(XMLDocument *target) const
tinyxml2::XMLNode::GetDocument
XMLDocument * GetDocument()
Get the XMLDocument that owns this XMLNode.
Definition tinyxml2.h:683
const XMLNode * Parent() const
Get the parent of this node on the DOM.
Definition tinyxml2.h:758
virtual XMLComment * ToComment()
Safely cast to a Comment, or null.
Definition tinyxml2.h:697
tinyxml2::XMLNode::LastChildElement
const XMLElement * LastChildElement(const char *name=0) const
virtual XMLDocument * ToDocument()
Safely cast to a Document, or null.
Definition tinyxml2.h:701
const XMLNode * LastChild() const
Get the last child node, or null if none exists.
Definition tinyxml2.h:790
tinyxml2::XMLNode::GetDocument
const XMLDocument * GetDocument() const
Get the XMLDocument that owns this XMLNode.
Definition tinyxml2.h:678
tinyxml2::XMLNode::ShallowEqual
virtual bool ShallowEqual(const XMLNode *compare) const =0
virtual bool Accept(XMLVisitor *visitor) const =0
tinyxml2::XMLNode::ShallowClone
virtual XMLNode * ShallowClone(XMLDocument *document) const =0
tinyxml2::XMLNode::InsertAfterChild
XMLNode * InsertAfterChild(XMLNode *afterThis, XMLNode *addThis)
tinyxml2::XMLNode::PreviousSibling
const XMLNode * PreviousSibling() const
Get the previous (left) sibling node of this node.
Definition tinyxml2.h:808
virtual XMLElement * ToElement()
Safely cast to an Element, or null.
Definition tinyxml2.h:689
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.
int GetLineNum() const
Gets the line number the node is in, if the document was parsed from a file.
Definition tinyxml2.h:755
virtual XMLUnknown * ToUnknown()
Safely cast to an Unknown, or null.
Definition tinyxml2.h:709
const XMLNode * FirstChild() const
Get the first child node, or null if none exists.
Definition tinyxml2.h:772
bool NoChildren() const
Returns true if this node has no children.
Definition tinyxml2.h:767
tinyxml2::XMLNode::InsertFirstChild
XMLNode * InsertFirstChild(XMLNode *addThis)
tinyxml2::XMLNode::InsertEndChild
XMLNode * InsertEndChild(XMLNode *addThis)
tinyxml2::XMLNode::NextSibling
const XMLNode * NextSibling() const
Get the next (right) sibling node of this node.
Definition tinyxml2.h:824
Definition tinyxml2.h:2242
tinyxml2::XMLPrinter::PrintSpace
virtual void PrintSpace(int depth)
tinyxml2::XMLPrinter::PushHeader
void PushHeader(bool writeBOM, bool writeDeclaration)
tinyxml2::XMLPrinter::PushText
void PushText(const char *text, bool cdata=false)
Add a text node.
tinyxml2::XMLPrinter::PushText
void PushText(float value)
Add a text node from a float.
tinyxml2::XMLPrinter::OpenElement
void OpenElement(const char *name, bool compactMode=false)
tinyxml2::XMLPrinter::VisitExit
virtual bool VisitExit(const XMLDocument &) override
Visit a document.
Definition tinyxml2.h:2294
virtual bool Visit(const XMLUnknown &unknown) override
Visit an unknown node.
tinyxml2::XMLPrinter::CStrSize
int CStrSize() const
Definition tinyxml2.h:2318
tinyxml2::XMLPrinter::PushText
void PushText(int value)
Add a text node from an integer.
tinyxml2::XMLPrinter::PushText
void PushText(bool value)
Add a text node from a bool.
tinyxml2::XMLPrinter::VisitEnter
virtual bool VisitEnter(const XMLElement &element, const XMLAttribute *attribute) override
Visit an element.
tinyxml2::XMLPrinter::PushText
void PushText(uint64_t value)
Add a text node from an unsigned 64bit integer.
virtual bool Visit(const XMLDeclaration &declaration) override
Visit a declaration.
tinyxml2::XMLPrinter::PushText
void PushText(unsigned value)
Add a text node from an unsigned.
tinyxml2::XMLPrinter::ClearBuffer
void ClearBuffer(bool resetToFirstElement=true)
Definition tinyxml2.h:2325
tinyxml2::XMLPrinter::VisitEnter
virtual bool VisitEnter(const XMLDocument &) override
Visit a document.
virtual bool Visit(const XMLComment &comment) override
Visit a comment node.
tinyxml2::XMLPrinter::PushText
void PushText(int64_t value)
Add a text node from a signed 64bit integer.
tinyxml2::XMLPrinter::VisitExit
virtual bool VisitExit(const XMLElement &element) override
Visit an element.
tinyxml2::XMLPrinter::PushAttribute
void PushAttribute(const char *name, const char *value)
If streaming, add an attribute to an open element.
tinyxml2::XMLPrinter::XMLPrinter
XMLPrinter(FILE *file=0, bool compact=false, int depth=0)
tinyxml2::XMLPrinter::PushText
void PushText(double value)
Add a text node from a double.
const char * CStr() const
Definition tinyxml2.h:2310
tinyxml2::XMLPrinter::CloseElement
virtual void CloseElement(bool compactMode=false)
If streaming, close the Element.
virtual bool Visit(const XMLText &text) override
Visit a text node.
tinyxml2::XMLPrinter::PushComment
void PushComment(const char *comment)
Add a comment.
Definition tinyxml2.h:995
tinyxml2::XMLText::ShallowEqual
virtual bool ShallowEqual(const XMLNode *compare) const override
virtual XMLText * ToText() override
Safely cast to Text, or null.
Definition tinyxml2.h:1000
tinyxml2::XMLText::ShallowClone
virtual XMLNode * ShallowClone(XMLDocument *document) const override
virtual bool Accept(XMLVisitor *visitor) const override
bool CData() const
Returns true if this is a CDATA text element.
Definition tinyxml2.h:1012
void SetCData(bool isCData)
Declare whether this should be CDATA or standard text.
Definition tinyxml2.h:1008
Definition tinyxml2.h:1109
tinyxml2::XMLUnknown::ShallowEqual
virtual bool ShallowEqual(const XMLNode *compare) const override
tinyxml2::XMLUnknown::ShallowClone
virtual XMLNode * ShallowClone(XMLDocument *document) const override
tinyxml2::XMLUnknown::ToUnknown
virtual XMLUnknown * ToUnknown() override
Safely cast to an Unknown, or null.
Definition tinyxml2.h:1112
virtual bool Accept(XMLVisitor *visitor) const override
Definition tinyxml2.h:479
virtual bool Visit(const XMLUnknown &)
Visit an unknown node.
Definition tinyxml2.h:514
tinyxml2::XMLVisitor::VisitExit
virtual bool VisitExit(const XMLDocument &)
Visit a document.
Definition tinyxml2.h:488
tinyxml2::XMLVisitor::VisitExit
virtual bool VisitExit(const XMLElement &)
Visit an element.
Definition tinyxml2.h:497
tinyxml2::XMLVisitor::VisitEnter
virtual bool VisitEnter(const XMLDocument &)
Visit a document.
Definition tinyxml2.h:484
virtual bool Visit(const XMLComment &)
Visit a comment node.
Definition tinyxml2.h:510
virtual bool Visit(const XMLDeclaration &)
Visit a declaration.
Definition tinyxml2.h:502
virtual bool Visit(const XMLText &)
Visit a text node.
Definition tinyxml2.h:506
tinyxml2::XMLVisitor::VisitEnter
virtual bool VisitEnter(const XMLElement &, const XMLAttribute *)
Visit an element.
Definition tinyxml2.h:493
Generated on Sat Dec 30 2023 18:02:35 for TinyXML-2 by 1.10.0