23#ifndef TINYXML2_INCLUDED
24#define TINYXML2_INCLUDED
26#if defined(ANDROID_NDK) || defined(__BORLANDC__) || defined(__QNXNTO__)
55#if defined(_DEBUG ) || defined(__DEBUG__)
56# ifndef TINYXML2_DEBUG
57# define TINYXML2_DEBUG
62# pragma warning(disable: 4267)
66# pragma warning(disable: 4251)
70# ifdef TINYXML2_EXPORT
71# define TINYXML2_LIB __declspec(dllexport)
72# elif defined(TINYXML2_IMPORT)
73# define TINYXML2_LIB __declspec(dllimport)
78# define TINYXML2_LIB __attribute__((visibility("default")))
84#if defined(TINYXML2_DEBUG)
87# define TIXMLASSERT(x )
88# elif defined(ANDROID_NDK)
89# include <android/log.h>
90# define TIXMLASSERT(x ) if(!(x)) { __android_log_assert("assert", "grinliz", "ASSERT in '%s' at %d.", __FILE__, __LINE__ ); }
93# define TIXMLASSERT assert
96# define TIXMLASSERT(x ) {}
107#define TINYXML2_MAJOR_VERSION 6
108#define TINYXML2_MINOR_VERSION 1
109#define TINYXML2_PATCHVERSION 0
132 NEEDS_ENTITY_PROCESSING = 0x01,
133 NEEDS_NEWLINE_NORMALIZATION = 0x02,
134 NEEDS_WHITESPACE_COLLAPSING = 0x04,
136 TEXT_ELEMENT = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION,
137 TEXT_ELEMENT_LEAVE_ENTITIES = NEEDS_NEWLINE_NORMALIZATION,
139 ATTRIBUTE_VALUE = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION,
140 ATTRIBUTE_VALUE_LEAVE_ENTITIES = NEEDS_NEWLINE_NORMALIZATION,
141 COMMENT = NEEDS_NEWLINE_NORMALIZATION
144 StrPair() : _flags(0 ), _start(
nullptr ), _end(
nullptr ) {}
147 void Set(
char* start,
char* end,
int flags ) {
153 _flags = flags | NEEDS_FLUSH;
156 const char* GetStr();
159 return _start == _end;
162 void SetInternedStr(
const char* str ) {
164 _start =
const_cast<char*
>(str);
167 void SetStr(
const char* str,
int flags=0 );
169 char* ParseText(
char* in,
const char* endTag,
int strFlags,
int* curLineNumPtr );
170 char* ParseName(
char* in );
172 void TransferTo(
StrPair* other );
176 void CollapseWhitespace();
188 void operator= (
StrPair& other );
197template <
class T,
int INITIAL_SIZE>
203 _allocated(INITIAL_SIZE ),
219 TIXMLASSERT(_size < INT_MAX );
220 EnsureCapacity(_size+1 );
225 T* PushArr(
int count ) {
226 TIXMLASSERT(count >= 0 );
227 TIXMLASSERT(_size <= INT_MAX - count );
228 EnsureCapacity(_size+count );
229 T* ret = &_mem[_size];
235 TIXMLASSERT(_size > 0 );
240 void PopArr(
int count ) {
241 TIXMLASSERT(_size >= count );
249 T& operator[](
int i) {
250 TIXMLASSERT(i>= 0 && i < _size );
254 const T& operator[](
int i)
const {
255 TIXMLASSERT(i>= 0 && i < _size );
259 const T& PeekTop()
const {
260 TIXMLASSERT(_size > 0 );
261 return _mem[ _size - 1];
265 TIXMLASSERT(_size >= 0 );
269 int Capacity()
const {
270 TIXMLASSERT(_allocated >= INITIAL_SIZE );
274 void SwapRemove(
int i) {
275 TIXMLASSERT(i >= 0 && i < _size);
276 TIXMLASSERT(_size > 0);
277 _mem[i] = _mem[_size - 1];
281 const T* Mem()
const {
295 void EnsureCapacity(
int cap ) {
296 TIXMLASSERT(cap > 0 );
297 if(cap > _allocated ) {
298 TIXMLASSERT(cap <= INT_MAX / 2 );
299 int newAllocated = cap * 2;
300 T* newMem =
new T[
static_cast<size_t>(newAllocated)];
301 TIXMLASSERT(newAllocated >= _size );
302 memcpy(newMem, _mem,
sizeof(T)*
static_cast<size_t>(_size) );
307 _allocated = newAllocated;
312 T _pool[INITIAL_SIZE];
328 virtual int ItemSize()
const = 0;
329 virtual void* Alloc() = 0;
330 virtual void Free(
void*) = 0;
331 virtual void SetTracked() = 0;
332 virtual void Clear() = 0;
339template<
int ITEM_SIZE >
343 MemPoolT() : _blockPtrs(), _root(0), _currentAllocs(0), _nAllocs(0), _maxAllocs(0), _nUntracked(0) {}
350 while(!_blockPtrs.Empty()) {
351 Block* lastBlock = _blockPtrs.Pop();
361 virtual int ItemSize()
const {
364 int CurrentAllocs()
const {
365 return _currentAllocs;
368 virtual void* Alloc() {
372 _blockPtrs.Push(block );
374 Item* blockItems = block->items;
375 for(
int i = 0; i < ITEMS_PER_BLOCK - 1; ++i ) {
376 blockItems[i].next = &(blockItems[i + 1]);
378 blockItems[ITEMS_PER_BLOCK - 1].next = 0;
381 Item*
const result = _root;
382 TIXMLASSERT(result != 0 );
386 if(_currentAllocs > _maxAllocs ) {
387 _maxAllocs = _currentAllocs;
394 virtual void Free(
void* mem ) {
399 Item* item =
static_cast<Item*
>(mem );
401 memset(item, 0xfe,
sizeof(*item ));
406 void Trace(
const char* name ) {
407 printf(
"Mempool %s watermark=%d [%dk] current=%d size=%d nAlloc=%d blocks=%d\n",
408 name, _maxAllocs, _maxAllocs * ITEM_SIZE / 1024, _currentAllocs,
409 ITEM_SIZE, _nAllocs, _blockPtrs.Size());
416 int Untracked()
const {
431 enum { ITEMS_PER_BLOCK = (4 * 1024) / ITEM_SIZE };
439 char itemData[ITEM_SIZE];
442 Item items[ITEMS_PER_BLOCK];
519 XML_WRONG_ATTRIBUTE_TYPE,
520 XML_ERROR_FILE_NOT_FOUND,
521 XML_ERROR_FILE_COULD_NOT_BE_OPENED,
522 XML_ERROR_FILE_READ_ERROR,
523 UNUSED_XML_ERROR_ELEMENT_MISMATCH,
524 XML_ERROR_PARSING_ELEMENT,
525 XML_ERROR_PARSING_ATTRIBUTE,
526 UNUSED_XML_ERROR_IDENTIFYING_TAG,
527 XML_ERROR_PARSING_TEXT,
528 XML_ERROR_PARSING_CDATA,
529 XML_ERROR_PARSING_COMMENT,
530 XML_ERROR_PARSING_DECLARATION,
531 XML_ERROR_PARSING_UNKNOWN,
532 XML_ERROR_EMPTY_DOCUMENT,
533 XML_ERROR_MISMATCHED_ELEMENT,
535 XML_CAN_NOT_CONVERT_TEXT,
548 static const char* SkipWhiteSpace(
const char* p,
int* curLineNumPtr ) {
551 while(IsWhiteSpace(*p)) {
552 if(curLineNumPtr && *p ==
'\n') {
560 static char* SkipWhiteSpace(
char* p,
int* curLineNumPtr ) {
561 return const_cast<char*
>(SkipWhiteSpace(
const_cast<const char*
>(p), curLineNumPtr ));
566 static bool IsWhiteSpace(
char p ) {
567 return !IsUTF8Continuation(p) && isspace(
static_cast<unsigned char>(p));
570 inline static bool IsNameStartChar(
unsigned char ch ) {
578 return ch ==
':' || ch ==
'_';
581 inline static bool IsNameChar(
unsigned char ch ) {
582 return IsNameStartChar(ch )
588 inline static bool StringEqual(
const char* p,
const char* q,
int nChar=INT_MAX ) {
594 TIXMLASSERT(nChar >= 0 );
595 return strncmp(p, q,
static_cast<size_t>(nChar) ) == 0;
598 inline static bool IsUTF8Continuation(
char p ) {
599 return(p & 0x80 ) != 0;
602 static const char* ReadBOM(
const char* p,
bool* hasBOM );
605 static const char* GetCharacterRef(
const char* p,
char* value,
int* length );
606 static void ConvertUTF32ToUTF8(
unsigned long input,
char* output,
int* length );
609 static void ToStr(
int v,
char* buffer,
int bufferSize );
610 static void ToStr(
unsigned v,
char* buffer,
int bufferSize );
611 static void ToStr(
bool v,
char* buffer,
int bufferSize );
612 static void ToStr(
float v,
char* buffer,
int bufferSize );
613 static void ToStr(
double v,
char* buffer,
int bufferSize );
614 static void ToStr(int64_t v,
char* buffer,
int bufferSize);
617 static bool ToInt(
const char* str,
int* value );
618 static bool ToUnsigned(
const char* str,
unsigned* value );
619 static bool ToBool(
const char* str,
bool* value );
620 static bool ToFloat(
const char* str,
float* value );
621 static bool ToDouble(
const char* str,
double* value );
622 static bool ToInt64(
const char* str, int64_t* value);
629 static void SetBoolSerialization(
const char* writeTrue,
const char* writeFalse);
632 static const char* writeBoolTrue;
633 static const char* writeBoolFalse;
670 TIXMLASSERT(_document );
675 TIXMLASSERT(_document );
707 virtual const XMLText* ToText()
const {
710 virtual const XMLComment* ToComment()
const {
713 virtual const XMLDocument* ToDocument()
const {
716 virtual const XMLDeclaration* ToDeclaration()
const {
719 virtual const XMLUnknown* ToUnknown()
const {
732 const char* Value()
const;
737 void SetValue(
const char* val,
bool staticMem=
false );
768 const XMLElement* FirstChildElement(
const char* name =
nullptr )
const;
770 XMLElement* FirstChildElement(
const char* name =
nullptr ) {
771 return const_cast<XMLElement*
>(
const_cast<const XMLNode*
>(
this)->FirstChildElement(name ));
786 const XMLElement* LastChildElement(
const char* name =
nullptr )
const;
788 XMLElement* LastChildElement(
const char* name =
nullptr ) {
789 return const_cast<XMLElement*
>(
const_cast<const XMLNode*
>(
this)->LastChildElement(name));
802 const XMLElement* PreviousSiblingElement(
const char* name =
nullptr )
const;
804 XMLElement* PreviousSiblingElement(
const char* name =
nullptr ) {
805 return const_cast<XMLElement*
>(
const_cast<const XMLNode*
>(
this)->PreviousSiblingElement(name ));
818 const XMLElement* NextSiblingElement(
const char* name =
nullptr )
const;
820 XMLElement* NextSiblingElement(
const char* name =
nullptr ) {
821 return const_cast<XMLElement*
>(
const_cast<const XMLNode*
>(
this)->NextSiblingElement(name ));
831 XMLNode* InsertEndChild(XMLNode* addThis );
833 XMLNode* LinkEndChild(XMLNode* addThis ) {
834 return InsertEndChild(addThis );
843 XMLNode* InsertFirstChild(XMLNode* addThis );
852 XMLNode* InsertAfterChild(XMLNode* afterThis, XMLNode* addThis );
857 void DeleteChildren();
862 void DeleteChild(XMLNode* node );
873 virtual XMLNode* ShallowClone(XMLDocument* document )
const = 0;
888 XMLNode* DeepClone(XMLDocument* target )
const;
896 virtual bool ShallowEqual(
const XMLNode* compare )
const = 0;
920 virtual bool Accept(XMLVisitor* visitor )
const = 0;
927 void SetUserData(
void* userData) { _userData = userData; }
934 void* GetUserData()
const {
return _userData; }
937 XMLNode(XMLDocument*);
940 virtual char* ParseDeep(
char* p, StrPair* parentEndTag,
int* curLineNumPtr);
942 XMLDocument* _document;
944 mutable StrPair _value;
947 XMLNode* _firstChild;
957 void Unlink(XMLNode* child );
958 static void DeleteNode(XMLNode* node );
959 void InsertChildPreamble(XMLNode* insertThis )
const;
960 const XMLElement* ToElementWithName(
const char* name )
const;
962 XMLNode(
const XMLNode&);
963 XMLNode& operator= (
const XMLNode&);
983 virtual bool Accept(
XMLVisitor* visitor )
const;
988 virtual const XMLText* ToText()
const {
1002 virtual bool ShallowEqual(
const XMLNode* compare )
const;
1006 virtual ~XMLText() {}
1008 char* ParseDeep(
char* p, StrPair* parentEndTag,
int* curLineNumPtr );
1013 XMLText(
const XMLText&);
1014 XMLText& operator= (
const XMLText&);
1026 virtual const XMLComment* ToComment()
const {
1030 virtual bool Accept(XMLVisitor* visitor )
const;
1032 virtual XMLNode* ShallowClone(XMLDocument* document )
const;
1033 virtual bool ShallowEqual(
const XMLNode* compare )
const;
1036 XMLComment(XMLDocument* doc );
1037 virtual ~XMLComment();
1039 char* ParseDeep(
char* p, StrPair* parentEndTag,
int* curLineNumPtr);
1042 XMLComment(
const XMLComment&);
1043 XMLComment& operator= (
const XMLComment&);
1069 virtual bool Accept(XMLVisitor* visitor )
const;
1071 virtual XMLNode* ShallowClone(XMLDocument* document )
const;
1072 virtual bool ShallowEqual(
const XMLNode* compare )
const;
1075 XMLDeclaration(XMLDocument* doc );
1076 virtual ~XMLDeclaration();
1078 char* ParseDeep(
char* p, StrPair* parentEndTag,
int* curLineNumPtr );
1081 XMLDeclaration(
const XMLDeclaration&);
1082 XMLDeclaration& operator= (
const XMLDeclaration&);
1100 virtual const XMLUnknown* ToUnknown()
const {
1104 virtual bool Accept(XMLVisitor* visitor )
const;
1106 virtual XMLNode* ShallowClone(XMLDocument* document )
const;
1107 virtual bool ShallowEqual(
const XMLNode* compare )
const;
1110 XMLUnknown(XMLDocument* doc );
1111 virtual ~XMLUnknown();
1113 char* ParseDeep(
char* p, StrPair* parentEndTag,
int* curLineNumPtr );
1116 XMLUnknown(
const XMLUnknown&);
1117 XMLUnknown& operator= (
const XMLUnknown&);
1133 const char* Name()
const;
1136 const char* Value()
const;
1150 int IntValue()
const {
1156 int64_t Int64Value()
const {
1158 QueryInt64Value(&i);
1165 QueryUnsignedValue(&i );
1171 QueryBoolValue(&b );
1177 QueryDoubleValue(&d );
1183 QueryFloatValue(&f );
1191 XMLError QueryIntValue(
int* value )
const;
1193 XMLError QueryUnsignedValue(
unsigned int* value )
const;
1195 XMLError QueryInt64Value(int64_t* value)
const;
1197 XMLError QueryBoolValue(
bool* value )
const;
1199 XMLError QueryDoubleValue(
double* value )
const;
1201 XMLError QueryFloatValue(
float* value )
const;
1204 void SetAttribute(
const char* value );
1206 void SetAttribute(
int value );
1208 void SetAttribute(
unsigned value );
1210 void SetAttribute(int64_t value);
1212 void SetAttribute(
bool value );
1214 void SetAttribute(
double value );
1216 void SetAttribute(
float value );
1219 enum { BUF_SIZE = 200 };
1221 XMLAttribute() : _name(), _value(),_parseLineNum(0 ), _next(nullptr ), _memPool(nullptr ) {}
1222 virtual ~XMLAttribute() {}
1224 XMLAttribute(
const XMLAttribute&);
1225 void operator= (
const XMLAttribute&);
1226 void SetName(
const char* name );
1228 char* ParseDeep(
char* p,
bool processEntities,
int* curLineNumPtr );
1230 mutable StrPair _name;
1231 mutable StrPair _value;
1233 XMLAttribute* _next;
1251 void SetName(
const char* str,
bool staticMem=
false ) {
1252 SetValue(str, staticMem );
1258 virtual const XMLElement* ToElement()
const {
1261 virtual bool Accept(XMLVisitor* visitor )
const;
1286 const char* Attribute(
const char* name,
const char* value=
nullptr )
const;
1294 int IntAttribute(
const char* name,
int defaultValue = 0)
const;
1296 unsigned UnsignedAttribute(
const char* name,
unsigned defaultValue = 0)
const;
1298 int64_t Int64Attribute(
const char* name, int64_t defaultValue = 0)
const;
1300 bool BoolAttribute(
const char* name,
bool defaultValue =
false)
const;
1302 double DoubleAttribute(
const char* name,
double defaultValue = 0)
const;
1304 float FloatAttribute(
const char* name,
float defaultValue = 0)
const;
1319 XMLError QueryIntAttribute(
const char* name,
int* value )
const {
1320 const XMLAttribute* a = FindAttribute(name );
1322 return XML_NO_ATTRIBUTE;
1324 return a->QueryIntValue(value );
1331 return XML_NO_ATTRIBUTE;
1340 return XML_NO_ATTRIBUTE;
1349 return XML_NO_ATTRIBUTE;
1357 return XML_NO_ATTRIBUTE;
1365 return XML_NO_ATTRIBUTE;
1374 return XML_NO_ATTRIBUTE;
1376 *value = a->
Value();
1399 int QueryAttribute(
const char* name,
int* value )
const {
1400 return QueryIntAttribute(name, value );
1403 int QueryAttribute(
const char* name,
unsigned int* value )
const {
1404 return QueryUnsignedAttribute(name, value );
1407 int QueryAttribute(
const char* name, int64_t* value)
const {
1408 return QueryInt64Attribute(name, value);
1411 int QueryAttribute(
const char* name,
bool* value )
const {
1412 return QueryBoolAttribute(name, value );
1415 int QueryAttribute(
const char* name,
double* value )
const {
1416 return QueryDoubleAttribute(name, value );
1419 int QueryAttribute(
const char* name,
float* value )
const {
1420 return QueryFloatAttribute(name, value );
1464 void DeleteAttribute(
const char* name );
1468 return _rootAttribute;
1471 const XMLAttribute* FindAttribute(
const char* name )
const;
1501 const char* GetText()
const;
1537 void SetText(
const char* inText );
1539 void SetText(
int value );
1541 void SetText(
unsigned value );
1543 void SetText(int64_t value);
1545 void SetText(
bool value );
1547 void SetText(
double value );
1549 void SetText(
float value );
1577 XMLError QueryIntText(
int* ival )
const;
1579 XMLError QueryUnsignedText(
unsigned* uval )
const;
1581 XMLError QueryInt64Text(int64_t* uval)
const;
1583 XMLError QueryBoolText(
bool* bval )
const;
1585 XMLError QueryDoubleText(
double* dval )
const;
1587 XMLError QueryFloatText(
float* fval )
const;
1589 int IntText(
int defaultValue = 0)
const;
1592 unsigned UnsignedText(
unsigned defaultValue = 0)
const;
1594 int64_t Int64Text(int64_t defaultValue = 0)
const;
1596 bool BoolText(
bool defaultValue =
false)
const;
1598 double DoubleText(
double defaultValue = 0)
const;
1600 float FloatText(
float defaultValue = 0)
const;
1603 enum ElementClosingType {
1608 ElementClosingType ClosingType()
const {
1609 return _closingType;
1611 virtual XMLNode* ShallowClone(XMLDocument* document )
const;
1612 virtual bool ShallowEqual(
const XMLNode* compare )
const;
1615 char* ParseDeep(
char* p, StrPair* parentEndTag,
int* curLineNumPtr );
1618 XMLElement(XMLDocument* doc );
1619 virtual ~XMLElement();
1620 XMLElement(
const XMLElement&);
1621 void operator= (
const XMLElement&);
1623 XMLAttribute* FindAttribute(
const char* name ) {
1624 return const_cast<XMLAttribute*
>(
const_cast<const XMLElement*
>(
this)->FindAttribute(name ));
1626 XMLAttribute* FindOrCreateAttribute(
const char* name );
1628 char* ParseAttributes(
char* p,
int* curLineNumPtr );
1629 static void DeleteAttribute(XMLAttribute* attribute );
1630 XMLAttribute* CreateAttribute();
1632 enum { BUF_SIZE = 200 };
1633 ElementClosingType _closingType;
1637 XMLAttribute* _rootAttribute;
1642 PRESERVE_WHITESPACE,
1664 XMLDocument(
bool processEntities =
true, Whitespace whitespaceMode = PRESERVE_WHITESPACE );
1668 TIXMLASSERT(
this == _document );
1672 TIXMLASSERT(
this == _document );
1686 XMLError Parse(
const char* xml,
int nBytes=
static_cast<int>(-1));
1693 XMLError LoadFile(
const char* filename );
1706 XMLError LoadFile(FILE*);
1713 XMLError SaveFile(
const char* filename,
bool compact =
false );
1722 XMLError SaveFile(FILE* fp,
bool compact =
false );
1724 bool ProcessEntities()
const {
1725 return _processEntities;
1727 Whitespace WhitespaceMode()
const {
1728 return _whitespaceMode;
1734 bool HasBOM()
const {
1740 void SetBOM(
bool useBOM ) {
1747 XMLElement* RootElement() {
1748 return FirstChildElement();
1750 const XMLElement* RootElement()
const {
1751 return FirstChildElement();
1768 void Print(XMLPrinter* streamer=
nullptr )
const;
1769 virtual bool Accept(XMLVisitor* visitor )
const;
1776 XMLElement* NewElement(
const char* name );
1782 XMLComment* NewComment(
const char* comment );
1788 XMLText* NewText(
const char* text );
1800 XMLDeclaration* NewDeclaration(
const char* text=
nullptr );
1806 XMLUnknown* NewUnknown(
const char* text );
1812 void DeleteNode(XMLNode* node );
1815 SetError(XML_SUCCESS, 0,
nullptr);
1820 return _errorID != XML_SUCCESS;
1826 const char* ErrorName()
const;
1827 static const char* ErrorIDToName(XMLError errorID);
1832 const char* ErrorStr()
const;
1835 void PrintError()
const;
1840 return _errorLineNum;
1855 char* Identify(
char* p,
XMLNode** node );
1863 virtual bool ShallowEqual(
const XMLNode*)
const {
1868 XMLDocument(
const XMLDocument&);
1869 void operator= (
const XMLDocument&);
1872 bool _processEntities;
1874 Whitespace _whitespaceMode;
1875 mutable StrPair _errorStr;
1878 int _parseCurLineNum;
1885 DynArray<XMLNode*, 10> _unlinked;
1887 MemPoolT<
sizeof(XMLElement) > _elementPool;
1888 MemPoolT<
sizeof(XMLAttribute) > _attributePool;
1889 MemPoolT<
sizeof(XMLText) > _textPool;
1890 MemPoolT<
sizeof(XMLComment) > _commentPool;
1892 static const char* _errorNames[XML_ERROR_COUNT];
1896 void SetError(XMLError error,
int lineNum,
const char* format, ...);
1898 template<
class NodeType,
int PoolElementSize>
1899 NodeType* CreateUnlinkedNode(MemPoolT<PoolElementSize>& pool );
1902template<
class NodeType,
int PoolElementSize>
1903inline NodeType* XMLDocument::CreateUnlinkedNode(MemPoolT<PoolElementSize>& pool )
1905 TIXMLASSERT(
sizeof(NodeType ) == PoolElementSize );
1906 TIXMLASSERT(
sizeof(NodeType ) == pool.ItemSize());
1907 NodeType* returnNode =
new(pool.Alloc()) NodeType(
this );
1908 TIXMLASSERT(returnNode );
1909 returnNode->_memPool = &pool;
1911 _unlinked.Push(returnNode);
1990 return XMLHandle(_node ? _node->FirstChild() :
nullptr );
1994 return XMLHandle(_node ? _node->FirstChildElement(name ) :
nullptr );
1998 return XMLHandle(_node ? _node->LastChild() :
nullptr );
2002 return XMLHandle(_node ? _node->LastChildElement(name ) :
nullptr );
2006 return XMLHandle(_node ? _node->PreviousSibling() :
nullptr );
2010 return XMLHandle(_node ? _node->PreviousSiblingElement(name ) :
nullptr );
2014 return XMLHandle(_node ? _node->NextSibling() :
nullptr );
2018 return XMLHandle(_node ? _node->NextSiblingElement(name ) :
nullptr );
2027 return(_node ? _node->ToElement() :
nullptr );
2031 return(_node ? _node->ToText() :
nullptr );
2035 return(_node ? _node->ToUnknown() :
nullptr );
2039 return(_node ? _node->ToDeclaration() :
nullptr );
2067 const XMLConstHandle FirstChildElement(
const char* name =
nullptr )
const {
2068 return XMLConstHandle(_node ? _node->FirstChildElement(name ) :
nullptr );
2073 const XMLConstHandle LastChildElement(
const char* name =
nullptr )
const {
2074 return XMLConstHandle(_node ? _node->LastChildElement(name ) :
nullptr );
2077 return XMLConstHandle(_node ? _node->PreviousSibling() :
nullptr );
2079 const XMLConstHandle PreviousSiblingElement(
const char* name =
nullptr )
const {
2080 return XMLConstHandle(_node ? _node->PreviousSiblingElement(name ) :
nullptr );
2085 const XMLConstHandle NextSiblingElement(
const char* name =
nullptr )
const {
2086 return XMLConstHandle(_node ? _node->NextSiblingElement(name ) :
nullptr );
2090 const XMLNode* ToNode()
const {
2094 return(_node ? _node->ToElement() :
nullptr );
2096 const XMLText* ToText()
const {
2097 return(_node ? _node->ToText() :
nullptr );
2100 return(_node ? _node->ToUnknown() :
nullptr );
2103 return(_node ? _node->ToDeclaration() :
nullptr );
2162 XMLPrinter(FILE* file=
nullptr,
bool compact =
false,
int depth = 0 );
2166 void PushHeader(
bool writeBOM,
bool writeDeclaration );
2170 void OpenElement(
const char* name,
bool compactMode=
false );
2172 void PushAttribute(
const char* name,
const char* value );
2173 void PushAttribute(
const char* name,
int value );
2174 void PushAttribute(
const char* name,
unsigned value );
2175 void PushAttribute(
const char* name, int64_t value);
2176 void PushAttribute(
const char* name,
bool value );
2177 void PushAttribute(
const char* name,
double value );
2179 virtual void CloseElement(
bool compactMode=
false );
2182 void PushText(
const char* text,
bool cdata=
false );
2184 void PushText(
int value );
2186 void PushText(
unsigned value );
2188 void PushText(int64_t value);
2190 void PushText(
bool value );
2192 void PushText(
float value );
2194 void PushText(
double value );
2197 void PushComment(
const char* comment );
2199 void PushDeclaration(
const char* value );
2200 void PushUnknown(
const char* value );
2208 virtual bool VisitExit(
const XMLElement& element );
2210 virtual bool Visit(
const XMLText& text );
2211 virtual bool Visit(
const XMLComment& comment );
2213 virtual bool Visit(
const XMLUnknown& unknown );
2219 const char* CStr()
const {
2220 return _buffer.Mem();
2227 int CStrSize()
const {
2228 return _buffer.Size();
2234 void ClearBuffer() {
2237 _firstElement =
true;
2241 virtual bool CompactMode(
const XMLElement&) {
return _compactMode; }
2246 virtual void PrintSpace(
int depth );
2247 void Print(
const char* format, ...);
2248 void Write(
const char* data,
int size );
2249 inline void Write(
const char* data ) { Write(data,
static_cast<int>(strlen(data))); }
2250 void Putc(
char ch );
2252 void SealElementIfJustOpened();
2253 bool _elementJustOpened;
2254 DynArray< const char*, 10 > _stack;
2257 void PrintString(
const char*,
bool restrictedEntitySet );
2263 bool _processEntities;
2270 bool _entityFlag[ENTITY_RANGE];
2271 bool _restrictedEntityFlag[ENTITY_RANGE];
2273 DynArray< char, 20 > _buffer;
2276 XMLPrinter(
const XMLPrinter&);
2277 XMLPrinter& operator= (
const XMLPrinter&);
2283#if defined(_MSC_VER)
2284# pragma warning(pop)
const XMLAttribute * Next() const
The next attribute in the list.
double DoubleValue() const
Query as a double. See IntValue()
XMLError QueryUnsignedValue(unsigned int *value) const
See QueryIntValue.
XMLError QueryBoolValue(bool *value) const
See QueryIntValue.
XMLError QueryFloatValue(float *value) const
See QueryIntValue.
float FloatValue() const
Query as a float. See IntValue()
unsigned UnsignedValue() const
Query as an unsigned integer. See IntValue()
void SetAttribute(const char *value)
Set the attribute to a string value.
XMLError QueryDoubleValue(double *value) const
See QueryIntValue.
bool BoolValue() const
Query as a boolean. See IntValue()
const char * Value() const
The value of the attribute.
int GetLineNum() const
Gets the line number the attribute is in, if the document was parsed from a file.
XMLError QueryInt64Value(int64_t *value) const
See QueryIntValue.
virtual XMLDeclaration * ToDeclaration()
Safely cast to a Declaration, or null.
virtual XMLDocument * ToDocument()
Safely cast to a Document, or null.
XMLError ErrorID() const
Return the errorID.
bool Error() const
Return true if there was an error parsing the document.
int ErrorLineNum() const
Return the line where the error occured, or zero if unknown.
XMLError QueryDoubleAttribute(const char *name, double *value) const
See QueryIntAttribute()
void SetAttribute(const char *name, const char *value)
Sets the named attribute to value.
void SetAttribute(const char *name, bool value)
Sets the named attribute to value.
void SetAttribute(const char *name, int64_t value)
Sets the named attribute to value.
const XMLAttribute * FirstAttribute() const
Return the first attribute in the list.
const char * Name() const
Get the name of an element(which is the Value() of the node.)
void SetAttribute(const char *name, double value)
Sets the named attribute to value.
void SetAttribute(const char *name, float value)
Sets the named attribute to value.
XMLError QueryBoolAttribute(const char *name, bool *value) const
See QueryIntAttribute()
void SetName(const char *str, bool staticMem=false)
Set the name of the element.
XMLError QueryInt64Attribute(const char *name, int64_t *value) const
See QueryIntAttribute()
virtual XMLElement * ToElement()
Safely cast to an Element, or null.
XMLError QueryStringAttribute(const char *name, const char **value) const
See QueryIntAttribute()
void SetAttribute(const char *name, int value)
Sets the named attribute to value.
void SetAttribute(const char *name, unsigned value)
Sets the named attribute to value.
XMLError QueryUnsignedAttribute(const char *name, unsigned int *value) const
See QueryIntAttribute()
XMLError QueryFloatAttribute(const char *name, float *value) const
See QueryIntAttribute()
XMLHandle NextSibling()
Get the next sibling of this handle.
XMLUnknown * ToUnknown()
Safe cast to XMLUnknown. This can return null.
XMLHandle PreviousSibling()
Get the previous sibling of this handle.
XMLNode * ToNode()
Safe cast to XMLNode. This can return null.
XMLHandle PreviousSiblingElement(const char *name=nullptr)
Get the previous sibling element of this handle.
XMLElement * ToElement()
Safe cast to XMLElement. This can return null.
XMLHandle LastChild()
Get the last child of this handle.
XMLHandle(XMLNode *node)
Create a handle from any node(at any depth of the tree.) This can be a null pointer.
XMLHandle(const XMLHandle &ref)
Copy constructor.
XMLDeclaration * ToDeclaration()
Safe cast to XMLDeclaration. This can return null.
XMLText * ToText()
Safe cast to XMLText. This can return null.
XMLHandle FirstChildElement(const char *name=nullptr)
Get the first child element of this handle.
XMLHandle NextSiblingElement(const char *name=nullptr)
Get the next sibling element of this handle.
XMLHandle(XMLNode &node)
Create a handle from a node.
XMLHandle FirstChild()
Get the first child of this handle.
XMLHandle LastChildElement(const char *name=nullptr)
Get the last child element of this handle.
virtual XMLDeclaration * ToDeclaration()
Safely cast to a Declaration, or null.
bool NoChildren() const
Returns true if this node has no children.
virtual XMLDocument * ToDocument()
Safely cast to a Document, or null.
virtual XMLText * ToText()
Safely cast to Text, or null.
virtual XMLUnknown * ToUnknown()
Safely cast to an Unknown, or null.
const XMLNode * NextSibling() const
Get the next(right) sibling node of this node.
XMLDocument * GetDocument()
Get the XMLDocument that owns this XMLNode.
const XMLDocument * GetDocument() const
Get the XMLDocument that owns this XMLNode.
const XMLNode * LastChild() const
Get the last child node, or null if none exists.
const XMLNode * Parent() const
Get the parent of this node on the DOM.
const XMLNode * PreviousSibling() const
Get the previous(left) sibling node of this node.
int GetLineNum() const
Gets the line number the node is in, if the document was parsed from a file.
const XMLNode * FirstChild() const
Get the first child node, or null if none exists.
virtual XMLElement * ToElement()
Safely cast to an Element, or null.
virtual XMLComment * ToComment()
Safely cast to a Comment, or null.
virtual bool VisitExit(const XMLDocument &)
Visit a document.
virtual XMLText * ToText()
Safely cast to Text, or null.
bool CData() const
Returns true if this is a CDATA text element.
void SetCData(bool isCData)
Declare whether this should be CDATA or standard text.
virtual XMLUnknown * ToUnknown()
Safely cast to an Unknown, or null.
virtual bool Visit(const XMLUnknown &)
Visit an unknown node.
virtual bool VisitEnter(const XMLDocument &)
Visit a document.
virtual bool Visit(const XMLDeclaration &)
Visit a declaration.
virtual bool VisitExit(const XMLDocument &)
Visit a document.
virtual bool VisitExit(const XMLElement &)
Visit an element.
virtual bool VisitEnter(const XMLElement &, const XMLAttribute *)
Visit an element.
virtual bool Visit(const XMLComment &)
Visit a comment node.
virtual bool Visit(const XMLText &)
Visit a text node.