24 #ifndef TINYXML2_INCLUDED
25 #define TINYXML2_INCLUDED
27 #if defined(ANDROID_NDK) || defined(__BORLANDC__) || defined(__QNXNTO__)
56 #if defined( _DEBUG ) || defined (__DEBUG__)
57 # ifndef TINYXML2_DEBUG
58 # define TINYXML2_DEBUG
63 # pragma warning(push)
64 # pragma warning(disable: 4251)
68 # ifdef TINYXML2_EXPORT
69 # define TINYXML2_LIB __declspec(dllexport)
70 # elif defined(TINYXML2_IMPORT)
71 # define TINYXML2_LIB __declspec(dllimport)
76 # define TINYXML2_LIB __attribute__((visibility("default")))
82 #if defined(TINYXML2_DEBUG)
83 # if defined(_MSC_VER)
84 # // "(void)0," is for suppressing C4127 warning in "assert(false)", "assert(true)" and the like
85 # define TIXMLASSERT( x ) if ( !((void)0,(x))) { __debugbreak(); }
86 # elif defined (ANDROID_NDK)
87 # include <android/log.h>
88 # define TIXMLASSERT( x ) if ( !(x)) { __android_log_assert( "assert", "grinliz", "ASSERT in '%s' at %d.", __FILE__, __LINE__ ); }
91 # define TIXMLASSERT assert
94 # define TIXMLASSERT( x ) {}
101 static const int TIXML2_MAJOR_VERSION = 7;
102 static const int TIXML2_MINOR_VERSION = 1;
103 static const int TIXML2_PATCH_VERSION = 0;
105 #define TINYXML2_MAJOR_VERSION 7
106 #define TINYXML2_MINOR_VERSION 1
107 #define TINYXML2_PATCH_VERSION 0
114 static const int TINYXML2_MAX_ELEMENT_DEPTH = 100;
123 class XMLDeclaration;
139 NEEDS_ENTITY_PROCESSING = 0x01,
140 NEEDS_NEWLINE_NORMALIZATION = 0x02,
141 NEEDS_WHITESPACE_COLLAPSING = 0x04,
143 TEXT_ELEMENT = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION,
144 TEXT_ELEMENT_LEAVE_ENTITIES = NEEDS_NEWLINE_NORMALIZATION,
146 ATTRIBUTE_VALUE = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION,
147 ATTRIBUTE_VALUE_LEAVE_ENTITIES = NEEDS_NEWLINE_NORMALIZATION,
148 COMMENT = NEEDS_NEWLINE_NORMALIZATION
151 StrPair() : _flags( 0 ), _start( 0 ), _end( 0 ) {}
154 void Set(
char* start,
char* end,
int flags ) {
155 TIXMLASSERT( start );
160 _flags = flags | NEEDS_FLUSH;
163 const char* GetStr();
166 return _start == _end;
169 void SetInternedStr(
const char* str ) {
171 _start =
const_cast<char*
>(str);
174 void SetStr(
const char* str,
int flags=0 );
176 char* ParseText(
char* in,
const char* endTag,
int strFlags,
int* curLineNumPtr );
177 char* ParseName(
char* in );
179 void TransferTo(
StrPair* other );
183 void CollapseWhitespace();
195 void operator=(
const StrPair& other );
204 template <
class T,
int INITIAL_SIZE>
210 _allocated( INITIAL_SIZE ),
216 if ( _mem != _pool ) {
226 TIXMLASSERT( _size < INT_MAX );
227 EnsureCapacity( _size+1 );
232 T* PushArr(
int count ) {
233 TIXMLASSERT( count >= 0 );
234 TIXMLASSERT( _size <= INT_MAX - count );
235 EnsureCapacity( _size+count );
236 T* ret = &_mem[_size];
242 TIXMLASSERT( _size > 0 );
247 void PopArr(
int count ) {
248 TIXMLASSERT( _size >= count );
256 T& operator[](
int i) {
257 TIXMLASSERT( i>= 0 && i < _size );
261 const T& operator[](
int i)
const {
262 TIXMLASSERT( i>= 0 && i < _size );
266 const T& PeekTop()
const {
267 TIXMLASSERT( _size > 0 );
268 return _mem[ _size - 1];
272 TIXMLASSERT( _size >= 0 );
276 int Capacity()
const {
277 TIXMLASSERT( _allocated >= INITIAL_SIZE );
281 void SwapRemove(
int i) {
282 TIXMLASSERT(i >= 0 && i < _size);
283 TIXMLASSERT(_size > 0);
284 _mem[i] = _mem[_size - 1];
288 const T* Mem()
const {
302 void EnsureCapacity(
int cap ) {
303 TIXMLASSERT( cap > 0 );
304 if ( cap > _allocated ) {
305 TIXMLASSERT( cap <= INT_MAX / 2 );
306 const int newAllocated = cap * 2;
307 T* newMem =
new T[newAllocated];
308 TIXMLASSERT( newAllocated >= _size );
309 memcpy( newMem, _mem,
sizeof(T)*_size );
310 if ( _mem != _pool ) {
314 _allocated = newAllocated;
319 T _pool[INITIAL_SIZE];
335 virtual int ItemSize()
const = 0;
336 virtual void* Alloc() = 0;
337 virtual void Free(
void* ) = 0;
338 virtual void SetTracked() = 0;
345 template<
int ITEM_SIZE >
349 MemPoolT() : _blockPtrs(), _root(0), _currentAllocs(0), _nAllocs(0), _maxAllocs(0), _nUntracked(0) {}
356 while( !_blockPtrs.Empty()) {
357 Block* lastBlock = _blockPtrs.Pop();
367 virtual int ItemSize()
const {
370 int CurrentAllocs()
const {
371 return _currentAllocs;
374 virtual void* Alloc() {
377 Block* block =
new Block();
378 _blockPtrs.Push( block );
380 Item* blockItems = block->items;
381 for(
int i = 0; i < ITEMS_PER_BLOCK - 1; ++i ) {
382 blockItems[i].next = &(blockItems[i + 1]);
384 blockItems[ITEMS_PER_BLOCK - 1].next = 0;
387 Item*
const result = _root;
388 TIXMLASSERT( result != 0 );
392 if ( _currentAllocs > _maxAllocs ) {
393 _maxAllocs = _currentAllocs;
400 virtual void Free(
void* mem ) {
405 Item* item =
static_cast<Item*
>( mem );
406 #ifdef TINYXML2_DEBUG
407 memset( item, 0xfe,
sizeof( *item ) );
412 void Trace(
const char* name ) {
413 printf(
"Mempool %s watermark=%d [%dk] current=%d size=%d nAlloc=%d blocks=%d\n",
414 name, _maxAllocs, _maxAllocs * ITEM_SIZE / 1024, _currentAllocs,
415 ITEM_SIZE, _nAllocs, _blockPtrs.Size() );
422 int Untracked()
const {
437 enum { ITEMS_PER_BLOCK = (4 * 1024) / ITEM_SIZE };
445 char itemData[ITEM_SIZE];
448 Item items[ITEMS_PER_BLOCK];
525 XML_WRONG_ATTRIBUTE_TYPE,
526 XML_ERROR_FILE_NOT_FOUND,
527 XML_ERROR_FILE_COULD_NOT_BE_OPENED,
528 XML_ERROR_FILE_READ_ERROR,
529 XML_ERROR_PARSING_ELEMENT,
530 XML_ERROR_PARSING_ATTRIBUTE,
531 XML_ERROR_PARSING_TEXT,
532 XML_ERROR_PARSING_CDATA,
533 XML_ERROR_PARSING_COMMENT,
534 XML_ERROR_PARSING_DECLARATION,
535 XML_ERROR_PARSING_UNKNOWN,
536 XML_ERROR_EMPTY_DOCUMENT,
537 XML_ERROR_MISMATCHED_ELEMENT,
539 XML_CAN_NOT_CONVERT_TEXT,
541 XML_ELEMENT_DEPTH_EXCEEDED,
553 static const char* SkipWhiteSpace(
const char* p,
int* curLineNumPtr ) {
556 while( IsWhiteSpace(*p) ) {
557 if (curLineNumPtr && *p ==
'\n') {
565 static char* SkipWhiteSpace(
char* p,
int* curLineNumPtr ) {
566 return const_cast<char*
>( SkipWhiteSpace( const_cast<const char*>(p), curLineNumPtr ) );
571 static bool IsWhiteSpace(
char p ) {
572 return !IsUTF8Continuation(p) && isspace( static_cast<unsigned char>(p) );
575 inline static bool IsNameStartChar(
unsigned char ch ) {
580 if ( isalpha( ch ) ) {
583 return ch ==
':' || ch ==
'_';
586 inline static bool IsNameChar(
unsigned char ch ) {
587 return IsNameStartChar( ch )
593 inline static bool StringEqual(
const char* p,
const char* q,
int nChar=INT_MAX ) {
599 TIXMLASSERT( nChar >= 0 );
600 return strncmp( p, q, nChar ) == 0;
603 inline static bool IsUTF8Continuation(
char p ) {
604 return ( p & 0x80 ) != 0;
607 static const char* ReadBOM(
const char* p,
bool* hasBOM );
610 static const char* GetCharacterRef(
const char* p,
char* value,
int* length );
611 static void ConvertUTF32ToUTF8(
unsigned long input,
char* output,
int* length );
614 static void ToStr(
int v,
char* buffer,
int bufferSize );
615 static void ToStr(
unsigned v,
char* buffer,
int bufferSize );
616 static void ToStr(
bool v,
char* buffer,
int bufferSize );
617 static void ToStr(
float v,
char* buffer,
int bufferSize );
618 static void ToStr(
double v,
char* buffer,
int bufferSize );
619 static void ToStr(int64_t v,
char* buffer,
int bufferSize);
620 static void ToStr(uint64_t v,
char* buffer,
int bufferSize);
623 static bool ToInt(
const char* str,
int* value );
624 static bool ToUnsigned(
const char* str,
unsigned* value );
625 static bool ToBool(
const char* str,
bool* value );
626 static bool ToFloat(
const char* str,
float* value );
627 static bool ToDouble(
const char* str,
double* value );
628 static bool ToInt64(
const char* str, int64_t* value);
629 static bool ToUnsigned64(
const char* str, uint64_t* value);
635 static void SetBoolSerialization(
const char* writeTrue,
const char* writeFalse);
638 static const char* writeBoolTrue;
639 static const char* writeBoolFalse;
676 TIXMLASSERT( _document );
681 TIXMLASSERT( _document );
713 virtual const XMLText* ToText()
const {
716 virtual const XMLComment* ToComment()
const {
719 virtual const XMLDocument* ToDocument()
const {
722 virtual const XMLDeclaration* ToDeclaration()
const {
725 virtual const XMLUnknown* ToUnknown()
const {
738 const char* Value()
const;
743 void SetValue(
const char* val,
bool staticMem=
false );
774 const XMLElement* FirstChildElement(
const char* name = 0 )
const;
776 XMLElement* FirstChildElement(
const char* name = 0 ) {
777 return const_cast<XMLElement*
>(
const_cast<const XMLNode*
>(
this)->FirstChildElement( name ));
792 const XMLElement* LastChildElement(
const char* name = 0 )
const;
794 XMLElement* LastChildElement(
const char* name = 0 ) {
795 return const_cast<XMLElement*
>(
const_cast<const XMLNode*
>(
this)->LastChildElement(name) );
808 const XMLElement* PreviousSiblingElement(
const char* name = 0 )
const ;
810 XMLElement* PreviousSiblingElement(
const char* name = 0 ) {
811 return const_cast<XMLElement*
>(
const_cast<const XMLNode*
>(
this)->PreviousSiblingElement( name ) );
824 const XMLElement* NextSiblingElement(
const char* name = 0 )
const;
826 XMLElement* NextSiblingElement(
const char* name = 0 ) {
827 return const_cast<XMLElement*
>(
const_cast<const XMLNode*
>(
this)->NextSiblingElement( name ) );
837 XMLNode* InsertEndChild( XMLNode* addThis );
839 XMLNode* LinkEndChild( XMLNode* addThis ) {
840 return InsertEndChild( addThis );
849 XMLNode* InsertFirstChild( XMLNode* addThis );
858 XMLNode* InsertAfterChild( XMLNode* afterThis, XMLNode* addThis );
863 void DeleteChildren();
868 void DeleteChild( XMLNode* node );
879 virtual XMLNode* ShallowClone( XMLDocument* document )
const = 0;
894 XMLNode* DeepClone( XMLDocument* target )
const;
902 virtual bool ShallowEqual(
const XMLNode* compare )
const = 0;
926 virtual bool Accept( XMLVisitor* visitor )
const = 0;
946 virtual char* ParseDeep(
char* p,
StrPair* parentEndTag,
int* curLineNumPtr);
964 static void DeleteNode(
XMLNode* node );
965 void InsertChildPreamble(
XMLNode* insertThis )
const;
966 const XMLElement* ToElementWithName(
const char* name )
const;
989 virtual bool Accept(
XMLVisitor* visitor )
const;
994 virtual const XMLText* ToText()
const {
1008 virtual bool ShallowEqual(
const XMLNode* compare )
const;
1012 virtual ~XMLText() {}
1014 char* ParseDeep(
char* p, StrPair* parentEndTag,
int* curLineNumPtr );
1019 XMLText(
const XMLText& );
1020 XMLText& operator=(
const XMLText& );
1032 virtual const XMLComment* ToComment()
const {
1036 virtual bool Accept( XMLVisitor* visitor )
const;
1038 virtual XMLNode* ShallowClone( XMLDocument* document )
const;
1039 virtual bool ShallowEqual(
const XMLNode* compare )
const;
1042 explicit XMLComment( XMLDocument* doc );
1043 virtual ~XMLComment();
1045 char* ParseDeep(
char* p, StrPair* parentEndTag,
int* curLineNumPtr);
1048 XMLComment(
const XMLComment& );
1049 XMLComment& operator=(
const XMLComment& );
1075 virtual bool Accept( XMLVisitor* visitor )
const;
1077 virtual XMLNode* ShallowClone( XMLDocument* document )
const;
1078 virtual bool ShallowEqual(
const XMLNode* compare )
const;
1081 explicit XMLDeclaration( XMLDocument* doc );
1082 virtual ~XMLDeclaration();
1084 char* ParseDeep(
char* p, StrPair* parentEndTag,
int* curLineNumPtr );
1087 XMLDeclaration(
const XMLDeclaration& );
1088 XMLDeclaration& operator=(
const XMLDeclaration& );
1106 virtual const XMLUnknown* ToUnknown()
const {
1110 virtual bool Accept( XMLVisitor* visitor )
const;
1112 virtual XMLNode* ShallowClone( XMLDocument* document )
const;
1113 virtual bool ShallowEqual(
const XMLNode* compare )
const;
1116 explicit XMLUnknown( XMLDocument* doc );
1117 virtual ~XMLUnknown();
1119 char* ParseDeep(
char* p, StrPair* parentEndTag,
int* curLineNumPtr );
1122 XMLUnknown(
const XMLUnknown& );
1123 XMLUnknown& operator=(
const XMLUnknown& );
1139 const char* Name()
const;
1142 const char* Value()
const;
1162 int64_t Int64Value()
const {
1164 QueryInt64Value(&i);
1168 uint64_t Unsigned64Value()
const {
1170 QueryUnsigned64Value(&i);
1177 QueryUnsignedValue( &i );
1183 QueryBoolValue( &b );
1189 QueryDoubleValue( &d );
1195 QueryFloatValue( &f );
1203 XMLError QueryIntValue(
int* value )
const;
1205 XMLError QueryUnsignedValue(
unsigned int* value )
const;
1207 XMLError QueryInt64Value(int64_t* value)
const;
1209 XMLError QueryUnsigned64Value(uint64_t* value)
const;
1211 XMLError QueryBoolValue(
bool* value )
const;
1213 XMLError QueryDoubleValue(
double* value )
const;
1215 XMLError QueryFloatValue(
float* value )
const;
1218 void SetAttribute(
const char* value );
1220 void SetAttribute(
int value );
1222 void SetAttribute(
unsigned value );
1224 void SetAttribute(int64_t value);
1226 void SetAttribute(uint64_t value);
1228 void SetAttribute(
bool value );
1230 void SetAttribute(
double value );
1232 void SetAttribute(
float value );
1235 enum { BUF_SIZE = 200 };
1237 XMLAttribute() : _name(), _value(),_parseLineNum( 0 ), _next( 0 ), _memPool( 0 ) {}
1238 virtual ~XMLAttribute() {}
1240 XMLAttribute(
const XMLAttribute& );
1241 void operator=(
const XMLAttribute& );
1242 void SetName(
const char* name );
1244 char* ParseDeep(
char* p,
bool processEntities,
int* curLineNumPtr );
1246 mutable StrPair _name;
1247 mutable StrPair _value;
1249 XMLAttribute* _next;
1267 void SetName(
const char* str,
bool staticMem=
false ) {
1268 SetValue( str, staticMem );
1274 virtual const XMLElement* ToElement()
const {
1277 virtual bool Accept( XMLVisitor* visitor )
const;
1302 const char* Attribute(
const char* name,
const char* value=0 )
const;
1310 int IntAttribute(
const char* name,
int defaultValue = 0)
const;
1312 unsigned UnsignedAttribute(
const char* name,
unsigned defaultValue = 0)
const;
1314 int64_t Int64Attribute(
const char* name, int64_t defaultValue = 0)
const;
1316 uint64_t Unsigned64Attribute(
const char* name, uint64_t defaultValue = 0)
const;
1318 bool BoolAttribute(
const char* name,
bool defaultValue =
false)
const;
1320 double DoubleAttribute(
const char* name,
double defaultValue = 0)
const;
1322 float FloatAttribute(
const char* name,
float defaultValue = 0)
const;
1340 return XML_NO_ATTRIBUTE;
1349 return XML_NO_ATTRIBUTE;
1358 return XML_NO_ATTRIBUTE;
1367 return XML_NO_ATTRIBUTE;
1376 return XML_NO_ATTRIBUTE;
1384 return XML_NO_ATTRIBUTE;
1392 return XML_NO_ATTRIBUTE;
1401 return XML_NO_ATTRIBUTE;
1403 *value = a->
Value();
1427 return QueryIntAttribute( name, value );
1430 XMLError QueryAttribute(
const char* name,
unsigned int* value )
const {
1431 return QueryUnsignedAttribute( name, value );
1434 XMLError QueryAttribute(
const char* name, int64_t* value)
const {
1435 return QueryInt64Attribute(name, value);
1438 XMLError QueryAttribute(
const char* name, uint64_t* value)
const {
1439 return QueryUnsigned64Attribute(name, value);
1442 XMLError QueryAttribute(
const char* name,
bool* value )
const {
1443 return QueryBoolAttribute( name, value );
1446 XMLError QueryAttribute(
const char* name,
double* value )
const {
1447 return QueryDoubleAttribute( name, value );
1450 XMLError QueryAttribute(
const char* name,
float* value )
const {
1451 return QueryFloatAttribute( name, value );
1501 void DeleteAttribute(
const char* name );
1505 return _rootAttribute;
1508 const XMLAttribute* FindAttribute(
const char* name )
const;
1538 const char* GetText()
const;
1574 void SetText(
const char* inText );
1576 void SetText(
int value );
1578 void SetText(
unsigned value );
1580 void SetText(int64_t value);
1582 void SetText(uint64_t value);
1584 void SetText(
bool value );
1586 void SetText(
double value );
1588 void SetText(
float value );
1616 XMLError QueryIntText(
int* ival )
const;
1618 XMLError QueryUnsignedText(
unsigned* uval )
const;
1620 XMLError QueryInt64Text(int64_t* uval)
const;
1622 XMLError QueryUnsigned64Text(uint64_t* uval)
const;
1624 XMLError QueryBoolText(
bool* bval )
const;
1626 XMLError QueryDoubleText(
double* dval )
const;
1628 XMLError QueryFloatText(
float* fval )
const;
1630 int IntText(
int defaultValue = 0)
const;
1633 unsigned UnsignedText(
unsigned defaultValue = 0)
const;
1635 int64_t Int64Text(int64_t defaultValue = 0)
const;
1637 uint64_t Unsigned64Text(uint64_t defaultValue = 0)
const;
1639 bool BoolText(
bool defaultValue =
false)
const;
1641 double DoubleText(
double defaultValue = 0)
const;
1643 float FloatText(
float defaultValue = 0)
const;
1646 enum ElementClosingType {
1651 ElementClosingType ClosingType()
const {
1652 return _closingType;
1654 virtual XMLNode* ShallowClone( XMLDocument* document )
const;
1655 virtual bool ShallowEqual(
const XMLNode* compare )
const;
1658 char* ParseDeep(
char* p, StrPair* parentEndTag,
int* curLineNumPtr );
1661 XMLElement( XMLDocument* doc );
1662 virtual ~XMLElement();
1663 XMLElement(
const XMLElement& );
1664 void operator=(
const XMLElement& );
1666 XMLAttribute* FindOrCreateAttribute(
const char* name );
1667 char* ParseAttributes(
char* p,
int* curLineNumPtr );
1668 static void DeleteAttribute( XMLAttribute* attribute );
1669 XMLAttribute* CreateAttribute();
1671 enum { BUF_SIZE = 200 };
1672 ElementClosingType _closingType;
1676 XMLAttribute* _rootAttribute;
1681 PRESERVE_WHITESPACE,
1703 XMLDocument(
bool processEntities =
true, Whitespace whitespaceMode = PRESERVE_WHITESPACE );
1707 TIXMLASSERT(
this == _document );
1711 TIXMLASSERT(
this == _document );
1725 XMLError Parse(
const char* xml,
size_t nBytes=static_cast<size_t>(-1) );
1732 XMLError LoadFile(
const char* filename );
1745 XMLError LoadFile( FILE* );
1752 XMLError SaveFile(
const char* filename,
bool compact =
false );
1761 XMLError SaveFile( FILE* fp,
bool compact =
false );
1763 bool ProcessEntities()
const {
1764 return _processEntities;
1766 Whitespace WhitespaceMode()
const {
1767 return _whitespaceMode;
1786 return FirstChildElement();
1789 return FirstChildElement();
1806 void Print( XMLPrinter* streamer=0 )
const;
1807 virtual bool Accept( XMLVisitor* visitor )
const;
1814 XMLElement* NewElement(
const char* name );
1820 XMLComment* NewComment(
const char* comment );
1826 XMLText* NewText(
const char* text );
1838 XMLDeclaration* NewDeclaration(
const char* text=0 );
1844 XMLUnknown* NewUnknown(
const char* text );
1850 void DeleteNode( XMLNode* node );
1853 SetError(XML_SUCCESS, 0, 0);
1858 return _errorID != XML_SUCCESS;
1864 const char* ErrorName()
const;
1865 static const char* ErrorIDToName(XMLError errorID);
1870 const char* ErrorStr()
const;
1873 void PrintError()
const;
1878 return _errorLineNum;
1894 char* Identify(
char* p,
XMLNode** node );
1911 bool _processEntities;
1913 Whitespace _whitespaceMode;
1917 int _parseCurLineNum;
1932 static const char* _errorNames[XML_ERROR_COUNT];
1936 void SetError( XMLError error,
int lineNum,
const char* format, ... );
1941 class DepthTracker {
1944 this->_document = document;
1945 document->PushDepth();
1948 _document->PopDepth();
1951 XMLDocument * _document;
1956 template<
class NodeType,
int PoolElementSize>
1957 NodeType* CreateUnlinkedNode( MemPoolT<PoolElementSize>& pool );
1960 template<
class NodeType,
int PoolElementSize>
1961 inline NodeType* XMLDocument::CreateUnlinkedNode( MemPoolT<PoolElementSize>& pool )
1963 TIXMLASSERT(
sizeof( NodeType ) == PoolElementSize );
1964 TIXMLASSERT(
sizeof( NodeType ) == pool.ItemSize() );
1965 NodeType* returnNode =
new (pool.Alloc()) NodeType(
this );
1966 TIXMLASSERT( returnNode );
1967 returnNode->_memPool = &pool;
1969 _unlinked.Push(returnNode);
2048 return XMLHandle( _node ? _node->FirstChild() : 0 );
2052 return XMLHandle( _node ? _node->FirstChildElement( name ) : 0 );
2056 return XMLHandle( _node ? _node->LastChild() : 0 );
2060 return XMLHandle( _node ? _node->LastChildElement( name ) : 0 );
2064 return XMLHandle( _node ? _node->PreviousSibling() : 0 );
2068 return XMLHandle( _node ? _node->PreviousSiblingElement( name ) : 0 );
2072 return XMLHandle( _node ? _node->NextSibling() : 0 );
2076 return XMLHandle( _node ? _node->NextSiblingElement( name ) : 0 );
2085 return ( _node ? _node->ToElement() : 0 );
2089 return ( _node ? _node->ToText() : 0 );
2093 return ( _node ? _node->ToUnknown() : 0 );
2097 return ( _node ? _node->ToDeclaration() : 0 );
2127 const XMLConstHandle FirstChildElement(
const char* name = 0 )
const {
2128 return XMLConstHandle( _node ? _node->FirstChildElement( name ) : 0 );
2133 const XMLConstHandle LastChildElement(
const char* name = 0 )
const {
2134 return XMLConstHandle( _node ? _node->LastChildElement( name ) : 0 );
2139 const XMLConstHandle PreviousSiblingElement(
const char* name = 0 )
const {
2140 return XMLConstHandle( _node ? _node->PreviousSiblingElement( name ) : 0 );
2145 const XMLConstHandle NextSiblingElement(
const char* name = 0 )
const {
2146 return XMLConstHandle( _node ? _node->NextSiblingElement( name ) : 0 );
2150 const XMLNode* ToNode()
const {
2154 return ( _node ? _node->ToElement() : 0 );
2156 const XMLText* ToText()
const {
2157 return ( _node ? _node->ToText() : 0 );
2160 return ( _node ? _node->ToUnknown() : 0 );
2163 return ( _node ? _node->ToDeclaration() : 0 );
2222 XMLPrinter( FILE* file=0,
bool compact =
false,
int depth = 0 );
2226 void PushHeader(
bool writeBOM,
bool writeDeclaration );
2230 void OpenElement(
const char* name,
bool compactMode=
false );
2232 void PushAttribute(
const char* name,
const char* value );
2233 void PushAttribute(
const char* name,
int value );
2234 void PushAttribute(
const char* name,
unsigned value );
2235 void PushAttribute(
const char* name, int64_t value );
2236 void PushAttribute(
const char* name, uint64_t value );
2237 void PushAttribute(
const char* name,
bool value );
2238 void PushAttribute(
const char* name,
double value );
2240 virtual void CloseElement(
bool compactMode=
false );
2243 void PushText(
const char* text,
bool cdata=
false );
2245 void PushText(
int value );
2247 void PushText(
unsigned value );
2249 void PushText( int64_t value );
2251 void PushText( uint64_t value );
2253 void PushText(
bool value );
2255 void PushText(
float value );
2257 void PushText(
double value );
2260 void PushComment(
const char* comment );
2262 void PushDeclaration(
const char* value );
2263 void PushUnknown(
const char* value );
2271 virtual bool VisitExit(
const XMLElement& element );
2273 virtual bool Visit(
const XMLText& text );
2274 virtual bool Visit(
const XMLComment& comment );
2276 virtual bool Visit(
const XMLUnknown& unknown );
2283 return _buffer.Mem();
2291 return _buffer.Size();
2300 _firstElement = resetToFirstElement;
2304 virtual bool CompactMode(
const XMLElement& ) {
return _compactMode; }
2309 virtual void PrintSpace(
int depth );
2310 void Print(
const char* format, ... );
2311 void Write(
const char* data,
size_t size );
2312 inline void Write(
const char* data ) { Write( data, strlen( data ) ); }
2313 void Putc(
char ch );
2315 void SealElementIfJustOpened();
2316 bool _elementJustOpened;
2317 DynArray< const char*, 10 > _stack;
2320 void PrintString(
const char*,
bool restrictedEntitySet );
2326 bool _processEntities;
2333 bool _entityFlag[ENTITY_RANGE];
2334 bool _restrictedEntityFlag[ENTITY_RANGE];
2339 XMLPrinter(
const XMLPrinter& );
2340 XMLPrinter& operator=(
const XMLPrinter& );
2346 #if defined(_MSC_VER)
2347 # pragma warning(pop)
2350 #endif // TINYXML2_INCLUDED
virtual XMLElement * ToElement()
Safely cast to an Element, or null.
Definition: tinyxml2.h:1271
Definition: tinyxml2.h:550
bool BoolValue() const
Query as a boolean. See IntValue()
Definition: tinyxml2.h:1181
void SetAttribute(const char *name, int64_t value)
Sets the named attribute to value.
Definition: tinyxml2.h:1471
bool Error() const
Return true if there was an error parsing the document.
Definition: tinyxml2.h:1857
XMLError QueryIntValue(int *value) const
Definition: tinyxml2.cpp:1412
XMLError QueryUnsignedAttribute(const char *name, unsigned int *value) const
See QueryIntAttribute()
Definition: tinyxml2.h:1346
virtual XMLDocument * ToDocument()
Safely cast to a Document, or null.
Definition: tinyxml2.h:698
XMLHandle(XMLNode *node)
Create a handle from any node (at any depth of the tree.) This can be a null pointer.
Definition: tinyxml2.h:2032
XMLError QueryFloatValue(float *value) const
See QueryIntValue.
Definition: tinyxml2.cpp:1457
Definition: tinyxml2.h:346
Definition: tinyxml2.h:2213
void SetAttribute(const char *name, unsigned value)
Sets the named attribute to value.
Definition: tinyxml2.h:1465
virtual XMLComment * ToComment()
Safely cast to a Comment, or null.
Definition: tinyxml2.h:694
int GetLineNum() const
Gets the line number the node is in, if the document was parsed from a file.
Definition: tinyxml2.h:746
XMLError QueryInt64Value(int64_t *value) const
See QueryIntValue.
Definition: tinyxml2.cpp:1430
virtual bool VisitEnter(const XMLElement &, const XMLAttribute *)
Visit an element.
Definition: tinyxml2.h:495
bool CData() const
Returns true if this is a CDATA text element.
Definition: tinyxml2.h:1003
Definition: tinyxml2.h:2109
virtual XMLUnknown * ToUnknown()
Safely cast to an Unknown, or null.
Definition: tinyxml2.h:1103
virtual bool Visit(const XMLText &)
Visit a text node.
Definition: tinyxml2.h:508
const XMLNode * FirstChild() const
Get the first child node, or null if none exists.
Definition: tinyxml2.h:763
virtual bool ShallowEqual(const XMLNode *) const
Definition: tinyxml2.h:1902
Definition: tinyxml2.h:1258
double DoubleValue() const
Query as a double. See IntValue()
Definition: tinyxml2.h:1187
virtual bool VisitExit(const XMLDocument &)
Visit a document.
Definition: tinyxml2.h:490
const char * Value() const
The value of the attribute.
Definition: tinyxml2.cpp:1373
void SetAttribute(const char *value)
Set the attribute to a string value.
Definition: tinyxml2.cpp:1475
Definition: tinyxml2.cpp:119
XMLError QueryFloatAttribute(const char *name, float *value) const
See QueryIntAttribute()
Definition: tinyxml2.h:1389
Definition: tinyxml2.h:205
virtual XMLText * ToText()
Safely cast to Text, or null.
Definition: tinyxml2.h:991
virtual bool Visit(const XMLComment &)
Visit a comment node.
Definition: tinyxml2.h:512
XMLHandle LastChild()
Get the last child of this handle.
Definition: tinyxml2.h:2055
virtual XMLNode * ShallowClone(XMLDocument *) const
Definition: tinyxml2.h:1899
void SetAttribute(const char *name, const char *value)
Sets the named attribute to value.
Definition: tinyxml2.h:1455
Definition: tinyxml2.h:1691
XMLHandle FirstChildElement(const char *name=0)
Get the first child element of this handle.
Definition: tinyxml2.h:2051
XMLHandle & operator=(const XMLHandle &ref)
Assignment.
Definition: tinyxml2.h:2041
void SetBOM(bool useBOM)
Definition: tinyxml2.h:1778
XMLError QueryDoubleValue(double *value) const
See QueryIntValue.
Definition: tinyxml2.cpp:1466
XMLError QueryInt64Attribute(const char *name, int64_t *value) const
See QueryIntAttribute()
Definition: tinyxml2.h:1355
XMLError ErrorID() const
Return the errorID.
Definition: tinyxml2.h:1861
XMLElement * RootElement()
Definition: tinyxml2.h:1785
XMLHandle NextSiblingElement(const char *name=0)
Get the next sibling element of this handle.
Definition: tinyxml2.h:2075
Definition: tinyxml2.h:1099
Definition: tinyxml2.h:2028
const XMLNode * Parent() const
Get the parent of this node on the DOM.
Definition: tinyxml2.h:749
const XMLAttribute * Next() const
The next attribute in the list.
Definition: tinyxml2.h:1148
XMLError QueryDoubleAttribute(const char *name, double *value) const
See QueryIntAttribute()
Definition: tinyxml2.h:1381
void SetName(const char *str, bool staticMem=false)
Set the name of the element.
Definition: tinyxml2.h:1267
Definition: tinyxml2.h:668
void SetAttribute(const char *name, double value)
Sets the named attribute to value.
Definition: tinyxml2.h:1488
int IntValue() const
Definition: tinyxml2.h:1156
Definition: tinyxml2.h:135
void ClearBuffer(bool resetToFirstElement=true)
Definition: tinyxml2.h:2297
XMLError QueryUnsigned64Attribute(const char *name, uint64_t *value) const
See QueryIntAttribute()
Definition: tinyxml2.h:1364
void * GetUserData() const
Definition: tinyxml2.h:940
Definition: tinyxml2.h:1134
XMLHandle LastChildElement(const char *name=0)
Get the last child element of this handle.
Definition: tinyxml2.h:2059
virtual bool VisitExit(const XMLDocument &)
Visit a document.
Definition: tinyxml2.h:2266
XMLHandle(XMLNode &node)
Create a handle from a node.
Definition: tinyxml2.h:2035
void SetCData(bool isCData)
Declare whether this should be CDATA or standard text.
Definition: tinyxml2.h:999
XMLDocument * GetDocument()
Get the XMLDocument that owns this XMLNode.
Definition: tinyxml2.h:680
const XMLDocument * GetDocument() const
Get the XMLDocument that owns this XMLNode.
Definition: tinyxml2.h:675
Definition: tinyxml2.h:329
virtual XMLDeclaration * ToDeclaration()
Safely cast to a Declaration, or null.
Definition: tinyxml2.h:1068
virtual XMLUnknown * ToUnknown()
Safely cast to an Unknown, or null.
Definition: tinyxml2.h:706
int ErrorLineNum() const
Return the line where the error occurred, or zero if unknown.
Definition: tinyxml2.h:1876
virtual bool VisitExit(const XMLElement &)
Visit an element.
Definition: tinyxml2.h:499
virtual bool Visit(const XMLUnknown &)
Visit an unknown node.
Definition: tinyxml2.h:516
Definition: tinyxml2.h:985
const XMLNode * PreviousSibling() const
Get the previous (left) sibling node of this node.
Definition: tinyxml2.h:799
Definition: tinyxml2.h:1064
void SetAttribute(const char *name, bool value)
Sets the named attribute to value.
Definition: tinyxml2.h:1483
void SetAttribute(const char *name, float value)
Sets the named attribute to value.
Definition: tinyxml2.h:1493
XMLError QueryStringAttribute(const char *name, const char **value) const
See QueryIntAttribute()
Definition: tinyxml2.h:1398
XMLError QueryIntAttribute(const char *name, int *value) const
Definition: tinyxml2.h:1337
XMLNode * ToNode()
Safe cast to XMLNode. This can return null.
Definition: tinyxml2.h:2080
Definition: tinyxml2.h:480
void SetUserData(void *userData)
Definition: tinyxml2.h:933
XMLHandle NextSibling()
Get the next sibling of this handle.
Definition: tinyxml2.h:2071
unsigned UnsignedValue() const
Query as an unsigned integer. See IntValue()
Definition: tinyxml2.h:1175
XMLError QueryUnsignedValue(unsigned int *value) const
See QueryIntValue.
Definition: tinyxml2.cpp:1421
virtual XMLText * ToText()
Safely cast to Text, or null.
Definition: tinyxml2.h:690
int GetLineNum() const
Gets the line number the attribute is in, if the document was parsed from a file. ...
Definition: tinyxml2.h:1145
void SetAttribute(const char *name, int value)
Sets the named attribute to value.
Definition: tinyxml2.h:1460
XMLError QueryBoolAttribute(const char *name, bool *value) const
See QueryIntAttribute()
Definition: tinyxml2.h:1373
bool HasBOM() const
Definition: tinyxml2.h:1773
XMLText * ToText()
Safe cast to XMLText. This can return null.
Definition: tinyxml2.h:2088
XMLError QueryUnsigned64Value(uint64_t *value) const
See QueryIntValue.
Definition: tinyxml2.cpp:1439
void SetAttribute(const char *name, uint64_t value)
Sets the named attribute to value.
Definition: tinyxml2.h:1477
const XMLNode * LastChild() const
Get the last child node, or null if none exists.
Definition: tinyxml2.h:781
XMLHandle PreviousSibling()
Get the previous sibling of this handle.
Definition: tinyxml2.h:2063
XMLDeclaration * ToDeclaration()
Safe cast to XMLDeclaration. This can return null.
Definition: tinyxml2.h:2096
bool NoChildren() const
Returns true if this node has no children.
Definition: tinyxml2.h:758
int CStrSize() const
Definition: tinyxml2.h:2290
const XMLAttribute * FirstAttribute() const
Return the first attribute in the list.
Definition: tinyxml2.h:1504
XMLUnknown * ToUnknown()
Safe cast to XMLUnknown. This can return null.
Definition: tinyxml2.h:2092
XMLError QueryAttribute(const char *name, int *value) const
Definition: tinyxml2.h:1426
XMLHandle FirstChild()
Get the first child of this handle.
Definition: tinyxml2.h:2047
XMLElement * ToElement()
Safe cast to XMLElement. This can return null.
Definition: tinyxml2.h:2084
XMLHandle PreviousSiblingElement(const char *name=0)
Get the previous sibling element of this handle.
Definition: tinyxml2.h:2067
virtual bool Visit(const XMLDeclaration &)
Visit a declaration.
Definition: tinyxml2.h:504
virtual bool VisitEnter(const XMLDocument &)
Visit a document.
Definition: tinyxml2.h:486
XMLError QueryBoolValue(bool *value) const
See QueryIntValue.
Definition: tinyxml2.cpp:1448
virtual XMLDocument * ToDocument()
Safely cast to a Document, or null.
Definition: tinyxml2.h:1706
float FloatValue() const
Query as a float. See IntValue()
Definition: tinyxml2.h:1193
virtual XMLDeclaration * ToDeclaration()
Safely cast to a Declaration, or null.
Definition: tinyxml2.h:702
virtual XMLElement * ToElement()
Safely cast to an Element, or null.
Definition: tinyxml2.h:686
const XMLNode * NextSibling() const
Get the next (right) sibling node of this node.
Definition: tinyxml2.h:815
XMLHandle(const XMLHandle &ref)
Copy constructor.
Definition: tinyxml2.h:2038
const char * CStr() const
Definition: tinyxml2.h:2282
const char * Name() const
Get the name of an element (which is the Value() of the node.)
Definition: tinyxml2.h:1263