49 #define DELETE_NODE( node ) { \
51 MemPool* pool = node->_memPool; \
56 #define DELETE_ATTRIBUTE( attrib ) { \
58 MemPool* pool = attrib->_memPool; \
59 attrib->~XMLAttribute(); \
60 pool->Free( attrib ); \
103 size_t len =
strlen( str );
104 _start =
new char[ len+1 ];
116 char endChar = *endTag;
117 size_t length =
strlen( endTag );
121 if ( *p == endChar &&
strncmp( p, endTag, length ) == 0 ) {
122 Set( start, p, strFlags );
135 if ( !start || !(*start) ) {
143 || (*p ==
'-' && p>start )
144 || (*p ==
'.' && p>start ) )) {
198 if ( *(p+1) ==
LF ) {
206 else if ( (
_flags & NEEDS_NEWLINE_NORMALIZATION) && *p ==
LF ) {
207 if ( *(p+1) ==
CR ) {
221 if ( *(p+1) ==
'#' ) {
222 char buf[10] = { 0 };
225 for(
int i=0; i<len; ++i ) {
234 && *(p+
entities[i].length+1) ==
';' ) {
242 if ( i == NUM_ENTITIES ) {
275 const unsigned char* pu =
reinterpret_cast<const unsigned char*
>(p);
289 const unsigned long BYTE_MASK = 0xBF;
290 const unsigned long BYTE_MARK = 0x80;
291 const unsigned long FIRST_BYTE_MARK[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };
296 else if ( input < 0x800 ) {
299 else if ( input < 0x10000 ) {
302 else if ( input < 0x200000 ) {
316 *output = (char)((input | BYTE_MARK) & BYTE_MASK);
320 *output = (char)((input | BYTE_MARK) & BYTE_MASK);
324 *output = (char)((input | BYTE_MARK) & BYTE_MASK);
328 *output = (char)(input | FIRST_BYTE_MARK[*length]);
340 if ( *(p+1) ==
'#' && *(p+2) ) {
341 unsigned long ucs = 0;
345 if ( *(p+2) ==
'x' ) {
361 while ( *q !=
'x' ) {
362 if ( *q >=
'0' && *q <=
'9' ) {
363 ucs += mult * (*q -
'0');
365 else if ( *q >=
'a' && *q <=
'f' ) {
366 ucs += mult * (*q -
'a' + 10);
368 else if ( *q >=
'A' && *q <=
'F' ) {
369 ucs += mult * (*q -
'A' + 10 );
394 while ( *q !=
'#' ) {
395 if ( *q >=
'0' && *q <=
'9' ) {
396 ucs += mult * (*q -
'0');
407 return p + delta + 1;
462 if (
ToInt( str, &ival )) {
463 *value = (ival==0) ?
false :
true;
511 static const char* xmlHeader = {
"<?" };
512 static const char* commentHeader = {
"<!--" };
513 static const char* dtdHeader = {
"<!" };
514 static const char* cdataHeader = {
"<![CDATA[" };
515 static const char* elementHeader = {
"<" };
517 static const int xmlHeaderLen = 2;
518 static const int commentHeaderLen = 4;
519 static const int dtdHeaderLen = 2;
520 static const int cdataHeaderLen = 9;
521 static const int elementHeaderLen = 1;
523 #if defined(_MSC_VER)
524 #pragma warning ( push )
525 #pragma warning ( disable : 4127 )
529 #if defined(_MSC_VER)
530 #pragma warning (pop)
540 p += commentHeaderLen;
557 p += elementHeaderLen;
574 if ( !node->Accept( visitor ) ) {
588 _firstChild( 0 ), _lastChild( 0 ),
589 _prev( 0 ), _next( 0 )
636 if ( child->
_prev ) {
639 if ( child->
_next ) {
705 if ( afterThis->
_parent !=
this ) {
709 if ( afterThis->
_next == 0 ) {
713 addThis->
_prev = afterThis;
716 afterThis->
_next = addThis;
756 if ( element->ToElement()
768 if ( element->ToElement()
800 if ( p == 0 || node == 0 ) {
837 else if ( !endTag.
Empty() ) {
858 const char* start = p;
859 if ( this->
CData() ) {
903 return visitor->
Visit( *
this );
922 const char* start = p;
949 return visitor->
Visit( *
this );
969 const char* start = p;
997 return visitor->
Visit( *
this );
1015 const char* start = p;
1043 return visitor->
Visit( *
this );
1057 if ( !p || *p !=
'=' ) {
1063 if ( *p !=
'\"' && *p !=
'\'' ) {
1067 char endTag[2] = { *p, 0 };
1306 last = attrib, attrib = attrib->
_next ) {
1315 last->
_next = attrib;
1321 attrib->_memPool->SetTracked();
1348 const char* start = p;
1354 if ( !p || !(*p) ) {
1376 if ( prevAttribute ) {
1377 prevAttribute->
_next = attrib;
1382 prevAttribute = attrib;
1385 else if ( *p ==
'/' && *(p+1) ==
'>' ) {
1390 else if ( *p ==
'>' ) {
1481 if ( !node->Accept( visitor ) ) {
1494 _processEntities( processEntities ),
1496 _whitespace( whitespace ),
1511 textPool.Trace(
"text" );
1512 elementPool.Trace(
"element" );
1513 commentPool.Trace(
"comment" );
1514 attributePool.Trace(
"attribute" );
1518 if (
Error() ==
false ) {
1570 dec->
SetValue( str ? str :
"xml version=\"1.0\" encoding=\"UTF-8\"" );
1590 #if defined(_MSC_VER) && (_MSC_VER >= 1400 )
1591 errno_t err = fopen_s(&fp, filename,
"rb" );
1594 fp = fopen( filename,
"rb" );
1611 fseek( fp, 0, SEEK_END );
1612 size_t size = ftell( fp );
1613 fseek( fp, 0, SEEK_SET );
1621 if ( read != size ) {
1644 #if defined(_MSC_VER) && (_MSC_VER >= 1400 )
1645 errno_t err = fopen_s(&fp, filename,
"w" );
1648 fp = fopen( filename,
"w" );
1677 if ( len == (
size_t)(-1) ) {
1700 streamer = &stdStreamer;
1717 static const int LEN = 20;
1718 char buf1[LEN] = { 0 };
1719 char buf2[LEN] = { 0 };
1728 printf(
"XMLDocument error id=%d str1=%s str2=%s\n",
1735 _elementJustOpened( false ),
1736 _firstElement( true ),
1741 _compactMode( compact )
1749 if (
entities[i].value < ENTITY_RANGE ) {
1763 va_start( va, format );
1766 vfprintf(
_fp, format, va );
1775 len = vsnprintf_s( _accumulator.Mem(), _accumulator.Capacity(), _TRUNCATE, format, va );
1778 _accumulator.PushArr( expand );
1782 memcpy( p, _accumulator.Mem(), len+1 );
1784 int len = vsnprintf( 0, 0, format, va );
1787 va_start( va, format );
1789 vsnprintf( p, len+1, format, va );
1798 for(
int i=0; i<depth; ++i ) {
1817 if ( flag[(
unsigned)(*q)] ) {
1866 Print(
"<%s", name );
1876 Print(
" %s=\"", name );
1927 Print(
"</%s>", name );
1955 Print(
"<![CDATA[" );
1956 Print(
"%s", text );
2014 Print(
"<!--%s-->", comment );
2028 Print(
"<?%s?>", value );
2042 Print(
"<!%s>", value );
2059 while ( attribute ) {
2061 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 OpenElement(const char *name)
void CollapseWhitespace()
bool Error() const
Return true if there was an error parsing the document.
static const char LINE_FEED
static void ToStr(int v, char *buffer, int bufferSize)
XMLAttribute * FindOrCreateAttribute(const char *name)
XMLError QueryIntValue(int *value) const
XMLError Parse(const char *xml, size_t nBytes=(size_t)(-1))
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 QueryIntAttribute.
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)
__BEGIN_NAMESPACE_STD void * memcpy(void *__restrict __dest, const void *__restrict __src, size_t __n) __THROW __nonnull((1
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)
void PrintError() const
If there is an error, print it to stdout.
static bool IsWhiteSpace(char p)
static const char * ReadBOM(const char *p, bool *hasBOM)
char * ParseDeep(char *p, bool processEntities)
const XMLAttribute * FindAttribute(const char *name) const
Query a specific attribute in the list.
__END_NAMESPACE_STD char char __BEGIN_NAMESPACE_STD size_t strlen(const char *__s) __THROW __attribute_pure__ __nonnull((1))
static const char DOUBLE_QUOTE
const XMLNode * FirstChild() const
Get the first child node, or null if none exists.
const char * Name() const
The name of the attribute.
static bool ToBool(const char *str, bool *value)
virtual bool VisitExit(const XMLDocument &)
Visit a document.
char * ParseName(char *in)
void SetAttribute(const char *value)
Set the attribute to a string value.
#define DELETE_NODE(node)
void Print(const char *format,...)
virtual bool ShallowEqual(const XMLNode *compare) const
const char * Value() const
The value of the attribute.
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 QueryIntAttribute.
bool ProcessEntities() const
DynArray< char, 20 > _buffer
#define DELETE_ATTRIBUTE(attrib)
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)
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
void SetName(const char *str, bool staticMem=false)
Set the name of the element.
XMLComment * NewComment(const char *comment)
const XMLElement * FirstChildElement(const char *value=0) const
XMLPrinter(FILE *file=0, bool compact=false)
const char * Value() const
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
__BEGIN_NAMESPACE_STD char * strchr(const char *__s, int __c) __THROW __attribute_pure__ __nonnull((1))
const char * GetText() const
XMLError QueryIntText(int *ival) const
__END_NAMESPACE_STD __BEGIN_NAMESPACE_STD char char char char int int strncmp(const char *__s1, const char *__s2, size_t __n) __THROW __attribute_pure__ __nonnull((1
static const char SINGLE_QUOTE
virtual bool VisitExit(const XMLDocument &)
Visit a document.
virtual ~XMLDeclaration()
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)
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
XMLError QueryFloatText(float *fval) const
See QueryIntText()
void SetValue(const char *val, bool staticMem=false)
void CloseElement()
If streaming, close the Element.
XMLError QueryUnsignedText(unsigned *uval) const
See QueryIntText()
static const int NUM_ENTITIES
void PushUnknown(const char *value)
static int IsAlphaNum(unsigned char anyByte)
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 opitionally 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 QueryIntAttribute.
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
void PrintSpace(int depth)
XMLUnknown * NewUnknown(const char *text)
MemPoolT< sizeof(XMLText) > _textPool
char * ParseDeep(char *, StrPair *endTag)
XMLDeclaration * NewDeclaration(const char *text=0)
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)
char * ParseText(char *in, const char *endTag, int strFlags)
XMLError QueryBoolValue(bool *value) const
See QueryIntAttribute.
const XMLElement * PreviousSiblingElement(const char *value=0) const
Get the previous (left) sibling element of this node, with an opitionally 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.
virtual bool Accept(XMLVisitor *visitor) const
XMLNode * InsertEndChild(XMLNode *addThis)
const XMLNode * NextSibling() const
Get the next (right) sibling node of this node.
bool _entityFlag[ENTITY_RANGE]
static int IsAlpha(unsigned char anyByte)
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)