27 #if defined(ANDROID_NDK) || defined(__QNXNTO__)
75 if (
this == other ) {
110 size_t len = strlen( str );
111 _start =
new char[ len+1 ];
112 memcpy(
_start, str, len+1 );
123 char endChar = *endTag;
124 size_t length = strlen( endTag );
128 if ( *p == endChar && strncmp( p, endTag, length ) == 0 ) {
129 Set( start, p, strFlags );
147 char*
const start = p;
204 if ( *(p+1) ==
LF ) {
212 else if ( (
_flags & NEEDS_NEWLINE_NORMALIZATION) && *p ==
LF ) {
213 if ( *(p+1) ==
CR ) {
227 if ( *(p+1) ==
'#' ) {
228 const int buflen = 10;
229 char buf[buflen] = { 0 };
234 memcpy( q, buf, len );
240 const Entity& entity = entities[i];
242 && *( p + entity.
length + 1 ) ==
';' ) {
250 if ( i == NUM_ENTITIES ) {
286 const unsigned char* pu =
reinterpret_cast<const unsigned char*
>(p);
301 const unsigned long BYTE_MASK = 0xBF;
302 const unsigned long BYTE_MARK = 0x80;
303 const unsigned long FIRST_BYTE_MARK[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };
308 else if ( input < 0x800 ) {
311 else if ( input < 0x10000 ) {
314 else if ( input < 0x200000 ) {
328 *output = (char)((input | BYTE_MARK) & BYTE_MASK);
332 *output = (char)((input | BYTE_MARK) & BYTE_MASK);
336 *output = (char)((input | BYTE_MARK) & BYTE_MASK);
340 *output = (char)(input | FIRST_BYTE_MARK[*length]);
352 if ( *(p+1) ==
'#' && *(p+2) ) {
353 unsigned long ucs = 0;
357 static const char SEMICOLON =
';';
359 if ( *(p+2) ==
'x' ) {
366 q = strchr( q, SEMICOLON );
376 while ( *q !=
'x' ) {
377 if ( *q >=
'0' && *q <=
'9' ) {
378 ucs += mult * (*q -
'0');
380 else if ( *q >=
'a' && *q <=
'f' ) {
381 ucs += mult * (*q -
'a' + 10);
383 else if ( *q >=
'A' && *q <=
'F' ) {
384 ucs += mult * (*q -
'A' + 10 );
401 q = strchr( q, SEMICOLON );
411 while ( *q !=
'#' ) {
412 if ( *q >=
'0' && *q <=
'9' ) {
413 ucs += mult * (*q -
'0');
425 return p + delta + 1;
483 if (
ToInt( str, &ival )) {
484 *value = (ival==0) ?
false :
true;
518 char*
const start = p;
526 static const char* xmlHeader = {
"<?" };
527 static const char* commentHeader = {
"<!--" };
528 static const char* dtdHeader = {
"<!" };
529 static const char* cdataHeader = {
"<![CDATA[" };
530 static const char* elementHeader = {
"<" };
532 static const int xmlHeaderLen = 2;
533 static const int commentHeaderLen = 4;
534 static const int dtdHeaderLen = 2;
535 static const int cdataHeaderLen = 9;
536 static const int elementHeaderLen = 1;
551 p += commentHeaderLen;
559 text->SetCData(
true );
571 p += elementHeaderLen;
590 if ( !node->Accept( visitor ) ) {
604 _firstChild( 0 ), _lastChild( 0 ),
605 _prev( 0 ), _next( 0 ),
659 if ( child->
_prev ) {
662 if ( child->
_next ) {
749 if ( afterThis->
_parent !=
this ) {
754 if ( afterThis->
_next == 0 ) {
759 addThis->
_prev = afterThis;
762 afterThis->
_next = addThis;
847 if ( p == 0 || node == 0 ) {
875 bool mismatch =
false;
876 if ( endTag.
Empty() ) {
924 const char* start = p;
925 if ( this->
CData() ) {
971 return visitor->
Visit( *
this );
990 const char* start = p;
1020 return visitor->
Visit( *
this );
1040 const char* start = p;
1071 return visitor->
Visit( *
this );
1089 const char* start = p;
1120 return visitor->
Visit( *
this );
1151 if ( *p !=
'\"' && *p !=
'\'' ) {
1155 char endTag[2] = { *p, 0 };
1432 last = attrib, attrib = attrib->
_next ) {
1442 last->
_next = attrib;
1448 attrib->_memPool->SetTracked();
1475 const char* start = p;
1491 attrib->_memPool->SetTracked();
1494 if ( !p ||
Attribute( attrib->Name() ) ) {
1504 if ( prevAttribute ) {
1505 prevAttribute->
_next = attrib;
1510 prevAttribute = attrib;
1513 else if ( *p ==
'/' && *(p+1) ==
'>' ) {
1518 else if ( *p ==
'>' ) {
1532 if ( attribute == 0 ) {
1537 pool->
Free( attribute );
1617 if ( !node->Accept( visitor ) ) {
1632 "XML_WRONG_ATTRIBUTE_TYPE",
1633 "XML_ERROR_FILE_NOT_FOUND",
1634 "XML_ERROR_FILE_COULD_NOT_BE_OPENED",
1635 "XML_ERROR_FILE_READ_ERROR",
1636 "XML_ERROR_ELEMENT_MISMATCH",
1637 "XML_ERROR_PARSING_ELEMENT",
1638 "XML_ERROR_PARSING_ATTRIBUTE",
1639 "XML_ERROR_IDENTIFYING_TAG",
1640 "XML_ERROR_PARSING_TEXT",
1641 "XML_ERROR_PARSING_CDATA",
1642 "XML_ERROR_PARSING_COMMENT",
1643 "XML_ERROR_PARSING_DECLARATION",
1644 "XML_ERROR_PARSING_UNKNOWN",
1645 "XML_ERROR_EMPTY_DOCUMENT",
1646 "XML_ERROR_MISMATCHED_ELEMENT",
1647 "XML_ERROR_PARSING",
1648 "XML_CAN_NOT_CONVERT_TEXT",
1656 _processEntities( processEntities ),
1658 _whitespace( whitespace ),
1678 const bool hadError =
Error();
1710 ele->SetName( name );
1720 comment->SetValue( str );
1730 text->SetValue( str );
1740 dec->SetValue( str ? str :
"xml version=\"1.0\" encoding=\"UTF-8\"" );
1750 unk->SetValue( str );
1754 static FILE*
callfopen(
const char* filepath,
const char* mode )
1758 #if defined(_MSC_VER) && (_MSC_VER >= 1400 ) && (!defined WINCE)
1760 errno_t err = fopen_s( &fp, filepath, mode );
1765 FILE* fp = fopen( filepath, mode );
1806 fseek( fp, 0, SEEK_SET );
1807 if ( fgetc( fp ) == EOF && ferror( fp ) != 0 ) {
1812 fseek( fp, 0, SEEK_END );
1813 const long filelength = ftell( fp );
1814 fseek( fp, 0, SEEK_SET );
1815 if ( filelength == -1L ) {
1820 const size_t size = filelength;
1828 if ( read != size ) {
1865 if ( len == 0 || !p || !*p ) {
1869 if ( len == (
size_t)(-1) ) {
1895 streamer = &stdStreamer;
1918 static const int LEN = 20;
1919 char buf1[LEN] = { 0 };
1920 char buf2[LEN] = { 0 };
1929 printf(
"XMLDocument error id=%d '%s' str1=%s str2=%s\n",
1949 _elementJustOpened( false ),
1950 _firstElement( true ),
1954 _processEntities( true ),
1955 _compactMode( compact )
1962 const char entityValue = entities[i].
value;
1963 TIXMLASSERT( 0 <= entityValue && entityValue < ENTITY_RANGE );
1976 va_start( va, format );
1979 vfprintf(
_fp, format, va );
1982 #if defined(_MSC_VER) && (_MSC_VER >= 1400 )
1987 char* str =
new char[len]();
1988 len = _vsnprintf(str, len, format, va);
1992 int len = _vscprintf( format, va );
1995 int len = vsnprintf( 0, 0, format, va );
1999 va_start( va, format );
2002 #if defined(_MSC_VER) && (_MSC_VER >= 1400 )
2004 _vsnprintf( p, len+1, format, va );
2006 vsnprintf_s( p, len+1, _TRUNCATE, format, va );
2009 vsnprintf( p, len+1, format, va );
2018 for(
int i=0; i<depth; ++i ) {
2037 if ( flag[(
unsigned char)(*q)] ) {
2043 if ( entities[i].value == *q ) {
2044 Print(
"&%s;", entities[i].pattern );
2082 if ( !compactMode ) {
2086 Print(
"<%s", name );
2096 Print(
" %s=\"", name );
2147 Print(
"</%s>", name );
2153 if (
_depth == 0 && !compactMode) {
2176 Print(
"<![CDATA[" );
2177 Print(
"%s", text );
2233 Print(
"<!--%s-->", comment );
2245 Print(
"<?%s?>", value );
2257 Print(
"<!%s>", value );
2276 while ( attribute ) {
2278 attribute = attribute->
Next();
virtual XMLElement * ToElement()
Safely cast to an Element, or null.
XMLText * NewText(const char *text)
virtual bool Visit(const XMLText &text)
Visit a text node.
void SetError(XMLError error, const char *str1, const char *str2)
void CollapseWhitespace()
bool Error() const
Return true if there was an error parsing the document.
static const char LINE_FEED
void SetText(const char *inText)
void SealElementIfJustOpened()
static void ToStr(int v, char *buffer, int bufferSize)
XMLAttribute * FindOrCreateAttribute(const char *name)
XMLError QueryIntValue(int *value) const
static const char * GetCharacterRef(const char *p, char *value, int *length)
static const unsigned char TIXML_UTF_LEAD_0
XMLError LoadFile(const char *filename)
void PushComment(const char *comment)
Add a comment.
char * ParseDeep(char *p, StrPair *endTag)
XMLError QueryFloatValue(float *value) const
See QueryIntValue.
static const Entity entities[NUM_ENTITIES]
virtual bool Accept(XMLVisitor *visitor) const
XMLAttribute * _rootAttribute
MemPoolT< sizeof(XMLAttribute) > _attributePool
static const char * SkipWhiteSpace(const char *p)
static bool ToFloat(const char *str, float *value)
virtual XMLComment * ToComment()
Safely cast to a Comment, or null.
char * ParseDeep(char *, StrPair *endTag)
XMLError QueryBoolText(bool *bval) const
See QueryIntText()
void PushHeader(bool writeBOM, bool writeDeclaration)
bool CData() const
Returns true if this is a CDATA text element.
void Set(char *start, char *end, int flags)
void Unlink(XMLNode *child)
void PushDeclaration(const char *value)
virtual void Free(void *)=0
void PrintError() const
If there is an error, print it to stdout.
static bool IsNameChar(unsigned char ch)
static bool IsWhiteSpace(char p)
static const char * ReadBOM(const char *p, bool *hasBOM)
void TransferTo(StrPair *other)
char * ParseDeep(char *p, bool processEntities)
const XMLAttribute * FindAttribute(const char *name) const
Query a specific attribute in the list.
static const char DOUBLE_QUOTE
const XMLNode * FirstChild() const
Get the first child node, or null if none exists.
static const char * _errorNames[XML_ERROR_COUNT]
static bool ToBool(const char *str, bool *value)
virtual bool VisitExit(const XMLDocument &)
Visit a document.
char * ParseName(char *in)
const char * Value() const
The value of the attribute.
void SetAttribute(const char *value)
Set the attribute to a string value.
void Print(const char *format,...)
virtual bool ShallowEqual(const XMLNode *compare) const
XMLPrinter(FILE *file=0, bool compact=false, int depth=0)
void Clear()
Clear the document, resetting it to the initial state.
void SetAttribute(const char *name, const char *value)
Sets the named attribute to value.
virtual char * ParseDeep(char *, StrPair *)
XMLError QueryDoubleText(double *dval) const
See QueryIntText()
XMLElement * NewElement(const char *name)
virtual XMLNode * ShallowClone(XMLDocument *document) const
XMLError QueryDoubleValue(double *value) const
See QueryIntValue.
bool ProcessEntities() const
DynArray< char, 20 > _buffer
static const unsigned char TIXML_UTF_LEAD_2
char * ParseDeep(char *, StrPair *endTag)
static bool ToInt(const char *str, int *value)
void SetName(const char *name)
XMLError SaveFile(const char *filename, bool compact=false)
static bool ToUnsigned(const char *str, unsigned *value)
const XMLNode * Parent() const
Get the parent of this node on the DOM.
void PushText(const char *text, bool cdata=false)
Add a text node.
const XMLAttribute * Next() const
The next attribute in the list.
const XMLElement * LastChildElement(const char *value=0) const
static const char CARRIAGE_RETURN
XMLComment * NewComment(const char *comment)
const XMLElement * FirstChildElement(const char *value=0) const
virtual void CloseElement(bool compactMode=false)
If streaming, close the Element.
void DeleteNode(XMLNode *node)
virtual void SetTracked()=0
const char * Attribute(const char *name, const char *value=0) const
virtual bool VisitEnter(const XMLDocument &)
Visit a document.
static bool ToDouble(const char *str, double *value)
MemPoolT< sizeof(XMLComment) > _commentPool
const char * Name() const
The name of the attribute.
const char * GetText() const
XMLError QueryIntText(int *ival) const
static const char SINGLE_QUOTE
virtual bool VisitExit(const XMLDocument &)
Visit a document.
virtual ~XMLDeclaration()
void OpenElement(const char *name, bool compactMode=false)
void SetStr(const char *str, int flags=0)
virtual XMLNode * ShallowClone(XMLDocument *document) const
void SetCData(bool isCData)
Declare whether this should be CDATA or standard text.
virtual bool Accept(XMLVisitor *visitor) const
XMLDeclaration(XMLDocument *doc)
XMLNode * InsertFirstChild(XMLNode *addThis)
const XMLDocument * GetDocument() const
Get the XMLDocument that owns this XMLNode.
XMLElement(XMLDocument *doc)
char * ParseAttributes(char *p)
XMLDocument(bool processEntities=true, Whitespace=PRESERVE_WHITESPACE)
constructor
virtual XMLUnknown * ToUnknown()
Safely cast to an Unknown, or null.
char * Identify(char *p, XMLNode **node)
static bool StringEqual(const char *p, const char *q, int nChar=INT_MAX)
virtual bool ShallowEqual(const XMLNode *compare) const
virtual XMLNode * ShallowClone(XMLDocument *document) const
void InsertChildPreamble(XMLNode *insertThis) const
const char * Value() const
static void DeleteNode(XMLNode *node)
XMLError QueryFloatText(float *fval) const
See QueryIntText()
void SetValue(const char *val, bool staticMem=false)
XMLError QueryUnsignedText(unsigned *uval) const
See QueryIntText()
static const int NUM_ENTITIES
void PushUnknown(const char *value)
virtual bool Accept(XMLVisitor *visitor) const
void PushAttribute(const char *name, const char *value)
If streaming, add an attribute to an open element.
const XMLElement * NextSiblingElement(const char *value=0) const
Get the next (right) sibling element of this node, with an optionally supplied name.
DynArray< const char *, 10 > _stack
static void ConvertUTF32ToUTF8(unsigned long input, char *output, int *length)
void DeleteAttribute(const char *name)
void PrintString(const char *, bool restrictedEntitySet)
XMLUnknown(XMLDocument *doc)
XMLError QueryUnsignedValue(unsigned int *value) const
See QueryIntValue.
static bool IsNameStartChar(unsigned char ch)
void DeleteChild(XMLNode *node)
virtual XMLText * ToText()
Safely cast to Text, or null.
virtual XMLNode * ShallowClone(XMLDocument *document) const
virtual bool Accept(XMLVisitor *visitor) const
virtual void PrintSpace(int depth)
XMLUnknown * NewUnknown(const char *text)
virtual bool CompactMode(const XMLElement &)
MemPoolT< sizeof(XMLText) > _textPool
char * ParseDeep(char *, StrPair *endTag)
XMLDeclaration * NewDeclaration(const char *text=0)
bool NoChildren() const
Returns true if this node has no children.
MemPoolT< sizeof(XMLElement) > _elementPool
const XMLAttribute * FirstAttribute() const
Return the first attribute in the list.
virtual bool ShallowEqual(const XMLNode *compare) const
virtual bool Visit(const XMLDeclaration &)
Visit a declaration.
bool _restrictedEntityFlag[ENTITY_RANGE]
virtual bool VisitEnter(const XMLDocument &)
Visit a document.
void Print(XMLPrinter *streamer=0) const
char * ParseText(char *in, const char *endTag, int strFlags)
XMLError QueryBoolValue(bool *value) const
See QueryIntValue.
const XMLElement * PreviousSiblingElement(const char *value=0) const
Get the previous (left) sibling element of this node, with an optionally supplied name...
Whitespace WhitespaceMode() const
XMLNode * InsertAfterChild(XMLNode *afterThis, XMLNode *addThis)
virtual XMLDeclaration * ToDeclaration()
Safely cast to a Declaration, or null.
static const unsigned char TIXML_UTF_LEAD_1
virtual XMLElement * ToElement()
Safely cast to an Element, or null.
const char * ErrorName() const
virtual bool Accept(XMLVisitor *visitor) const
static FILE * callfopen(const char *filepath, const char *mode)
XMLNode * InsertEndChild(XMLNode *addThis)
const XMLNode * NextSibling() const
Get the next (right) sibling node of this node.
bool _entityFlag[ENTITY_RANGE]
int mult(const std::string &)
const char * Name() const
Get the name of an element (which is the Value() of the node.)
virtual bool ShallowEqual(const XMLNode *compare) const
void SetInternedStr(const char *str)