40 Commits
2.0.2 ... 2.2.0

Author SHA1 Message Date
Lee Thomason
5321a0e21f setting the version to 2.2.0 2014-09-14 12:47:24 -07:00
Lee Thomason
c755667aa0 add an error message 2014-09-14 12:39:42 -07:00
Lee Thomason
331596e83c clean up the scope and names of the error code. 2014-09-11 14:56:43 -07:00
numatrumpet
cd8550c29c Without using preprocessor 2014-09-08 16:59:39 +09:00
numatrumpet
9f52ad5289 Makefile is recovered to original version 2014-09-08 16:41:33 +09:00
numatrumpet
003368429f ErrorNames is not implemented by vector<string> but *char[] 2014-09-08 16:36:28 +09:00
numatrumpet
8f5d3f8e80 make works correctly when using clang++ 2014-09-06 23:09:14 +09:00
numatrumpet
bb5ffac22d Using C++11, XMLUtil::ToErrorName(XMLError) returns the name of error type 2014-09-06 22:56:46 +09:00
Lee Thomason
fb732f97d4 Merge pull request #205 from Dmitry-Me/moveDefinitionsToLoopHeaders
Move loop variable definition into loop headers
2014-09-04 12:59:25 -07:00
Dmitry-Me
3659fe1d33 Move loop variable definition into loop headers 2014-09-04 11:33:49 +04:00
Lee Thomason
cf6d886903 Merge pull request #204 from Dmitry-Me/convertMacrosIntoFunctions
Convert DELETE_X macros into functions
2014-09-03 21:53:54 -07:00
Dmitry-Me
e3225b1c64 Convert DELETE_X macros into functions 2014-09-03 11:03:11 +04:00
Lee Thomason
30152836da Merge pull request #202 from Dmitry-Me/removeRepeatedVirtualCalls
Remove repeated virtual calls
2014-08-28 04:53:51 -07:00
Lee Thomason
83a6d8c373 Merge remote-tracking branch 'origin/master' 2014-08-27 14:45:53 -07:00
Lee Thomason
d526944e3c removed unused _accumulator 2014-08-27 14:45:35 -07:00
Dmitry-Me
b6b4e82626 Remove repeated virtual calls 2014-08-27 17:17:47 +04:00
Lee Thomason
59b9aaea43 Merge pull request #200 from Dmitry-Me/removeObsoleteComment
Remove obsolete comment
2014-08-25 13:46:37 -07:00
Dmitry-Me
ec19a0e513 Remove obsolete comment 2014-08-25 11:05:55 +04:00
Lee Thomason
b6ea923f0f Merge branch 'Dmitry-Me-makeCodeMoreDefensive' 2014-08-23 16:16:38 -07:00
Dmitry-Me
63f3de1a3c Make code more defensive
* initialize out-parameter for cases the callee fails to
* add assert for length being within range
* replace post-assert with pre-assert

Also replace the loop with an equivalent memcpy() call
2014-08-21 12:33:19 +04:00
Lee Thomason
dc50a31758 Merge pull request #197 from Dmitry-Me/dontAdjustStartWhenNeedsDelete
Assert when trying to adjust _start in "needs delete" mode.
2014-08-20 10:03:43 -07:00
Dmitry-Me
67a5bb0ac1 Assert when trying to adjust _start in "needs delete" mode. 2014-08-20 10:01:53 +04:00
Lee Thomason
0b26702ac9 Merge pull request #196 from Dmitry-Me/wrapFopenCalls
Wrap fopen()/fopen_s() calls to avoid duplication
2014-08-19 11:18:52 -07:00
Dmitry-Me
01578db56b Wrap fopen()/fopen_s() calls to avoid duplication 2014-08-19 10:18:48 +04:00
Lee Thomason
2af5679b26 Merge pull request #194 from Dmitry-Me/fixCStyleCast
Replace C-style cast with static_cast
2014-08-17 14:55:39 -07:00
Dmitry-Me
5657176b61 Replace C-style cast with static_cast 2014-08-15 11:03:47 +04:00
Lee Thomason
73c822c201 Merge pull request #193 from Dmitry-Me/shouldCheckFtellForError
Check ftell() result for error code before using it.
2014-08-14 16:46:13 -07:00
Dmitry-Me
acb9c9c260 Check ftell() result for error code before using it. 2014-08-04 09:49:25 +04:00
Lee Thomason
fca00d0ebc Merge pull request #191 from Dmitry-Me/dontIgnoreFgetcReturnValue
fgetc() is not required to clear the error indicator on success
2014-08-03 11:17:04 -07:00
Dmitry-Me
08e7f7be59 fgetc() is not required to clear the error indicator on success 2014-07-31 15:19:14 +04:00
Lee Thomason
84bd9624c6 Merge pull request #190 from pffang/master
WinCE Compatibility Fix
2014-07-12 11:22:30 -07:00
pffang
91d34a0989 WinCE Compatibility Fix 2014-07-10 10:02:35 +08:00
Lee Thomason
cf33e37d25 Merge pull request #187 from amai2012/master
Fix compiler warning: extra ';' after member function definition
2014-05-20 13:56:47 -07:00
Alexander Mai
d740b64044 Fix compiler warning: extra ';' after member function definition 2014-05-20 22:04:42 +02:00
Lee Thomason
500fb6aa21 Merge pull request #181 from eserdem/master
Fixed _CRT_SECURE_NO_WARNINGS macro redefinition warning
2014-04-17 10:07:50 -07:00
Serhat Eser Erdem
ca5d684a2b Fixed _CRT_SECURE_NO_WARNINGS macro redefinition warning 2014-04-17 14:06:15 +02:00
Lee Thomason
6ee53e7d49 setting the version to 2.1.0 2014-04-06 14:43:37 -07:00
Lee Thomason
256adb6371 missing default parameter for compact mode in XMLPrinter 2014-04-06 14:41:46 -07:00
Lee Thomason
98112fcdba minor doxygen file fix 2014-03-16 20:44:35 -07:00
Lee Thomason
433f1272d4 update readme 2014-03-16 20:22:12 -07:00
7 changed files with 1609 additions and 1071 deletions

View File

@@ -10,7 +10,7 @@ include(GNUInstallDirs)
################################
# set lib version here
set(GENERIC_LIB_VERSION "2.0.2")
set(GENERIC_LIB_VERSION "2.2.0")
set(GENERIC_LIB_SOVERSION "2")

2360
dox Executable file → Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -269,6 +269,14 @@ an XCode project, a Code::Blocks project, and a cmake CMakeLists.txt included to
The top of tinyxml.h even has a simple g++ command line if you are are *nix and don't want
to use a build system.
Versioning
----------
TinyXML-2 uses semantic versioning. http://semver.org/ Releases are now tagged in github.
Note that the major version will (probably) change fairly rapidly. API changes are fairly
common.
Documentation
-------------

View File

@@ -116,4 +116,8 @@ print( "Release note:" )
print( '1. Build. g++ -Wall -DDEBUG tinyxml2.cpp xmltest.cpp -o gccxmltest.exe' )
print( '2. Commit. git commit -am"setting the version to ' + versionStr + '"' )
print( '3. Tag. git tag ' + versionStr )
print( ' OR git tag -a ' + versionStr + ' -m <tag message>' )
print( ' OR git tag -a ' + versionStr + ' -m [tag message]' )
print( 'Remember to "git push" both code and tag. For the tag:' )
print( 'git push origin [tagname]')

View File

@@ -45,22 +45,6 @@ static const unsigned char TIXML_UTF_LEAD_0 = 0xefU;
static const unsigned char TIXML_UTF_LEAD_1 = 0xbbU;
static const unsigned char TIXML_UTF_LEAD_2 = 0xbfU;
#define DELETE_NODE( node ) { \
if ( node ) { \
MemPool* pool = node->_memPool; \
node->~XMLNode(); \
pool->Free( node ); \
} \
}
#define DELETE_ATTRIBUTE( attrib ) { \
if ( attrib ) { \
MemPool* pool = attrib->_memPool; \
attrib->~XMLAttribute(); \
pool->Free( attrib ); \
} \
}
namespace tinyxml2
{
@@ -112,7 +96,7 @@ char* StrPair::ParseText( char* p, const char* endTag, int strFlags )
{
TIXMLASSERT( endTag && *endTag );
char* start = p; // fixme: hides a member
char* start = p;
char endChar = *endTag;
size_t length = strlen( endTag );
@@ -150,6 +134,8 @@ char* StrPair::ParseName( char* p )
void StrPair::CollapseWhitespace()
{
// Adjusting _start would cause undefined behavior on delete[]
TIXMLASSERT( ( _flags & NEEDS_DELETE ) == 0 );
// Trim leading space.
_start = XMLUtil::SkipWhiteSpace( _start );
@@ -214,13 +200,14 @@ const char* StrPair::GetStr()
// &#20013; or &#x4e2d;
if ( *(p+1) == '#' ) {
char buf[10] = { 0 };
int len;
const int buflen = 10;
char buf[buflen] = { 0 };
int len = 0;
p = const_cast<char*>( XMLUtil::GetCharacterRef( p, buf, &len ) );
for( int i=0; i<len; ++i ) {
*q++ = buf[i];
}
TIXMLASSERT( q <= p );
TIXMLASSERT( 0 <= len && len <= buflen );
TIXMLASSERT( q + len <= p );
memcpy( q, buf, len );
q += len;
}
else {
int i=0;
@@ -615,7 +602,7 @@ void XMLNode::DeleteChildren()
XMLNode* node = _firstChild;
Unlink( node );
DELETE_NODE( node );
DeleteNode( node );
}
_firstChild = _lastChild = 0;
}
@@ -643,7 +630,7 @@ void XMLNode::Unlink( XMLNode* child )
void XMLNode::DeleteChild( XMLNode* node )
{
TIXMLASSERT( node->_parent == this );
DELETE_NODE( node );
DeleteNode( node );
}
@@ -770,10 +757,11 @@ const XMLElement* XMLNode::LastChildElement( const char* value ) const
const XMLElement* XMLNode::NextSiblingElement( const char* value ) const
{
for( XMLNode* element=this->_next; element; element = element->_next ) {
if ( element->ToElement()
&& (!value || XMLUtil::StringEqual( value, element->Value() ))) {
return element->ToElement();
for( XMLNode* node=this->_next; node; node = node->_next ) {
const XMLElement* element = node->ToElement();
if ( element
&& (!value || XMLUtil::StringEqual( value, node->Value() ))) {
return element;
}
}
return 0;
@@ -782,10 +770,11 @@ const XMLElement* XMLNode::NextSiblingElement( const char* value ) const
const XMLElement* XMLNode::PreviousSiblingElement( const char* value ) const
{
for( XMLNode* element=_prev; element; element = element->_prev ) {
if ( element->ToElement()
&& (!value || XMLUtil::StringEqual( value, element->Value() ))) {
return element->ToElement();
for( XMLNode* node=_prev; node; node = node->_prev ) {
const XMLElement* element = node->ToElement();
if ( element
&& (!value || XMLUtil::StringEqual( value, node->Value() ))) {
return element;
}
}
return 0;
@@ -822,7 +811,7 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEnd )
StrPair endTag;
p = node->ParseDeep( p, &endTag );
if ( !p ) {
DELETE_NODE( node );
DeleteNode( node );
node = 0;
if ( !_document->Error() ) {
_document->SetError( XML_ERROR_PARSING, 0, 0 );
@@ -830,19 +819,19 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEnd )
break;
}
XMLElement* ele = node->ToElement();
// We read the end tag. Return it to the parent.
if ( node->ToElement() && node->ToElement()->ClosingType() == XMLElement::CLOSING ) {
if ( ele && ele->ClosingType() == XMLElement::CLOSING ) {
if ( parentEnd ) {
*parentEnd = static_cast<XMLElement*>(node)->_value;
}
node->_memPool->SetTracked(); // created and then immediately deleted.
DELETE_NODE( node );
DeleteNode( node );
return p;
}
// Handle an end tag returned to this level.
// And handle a bunch of annoying errors.
XMLElement* ele = node->ToElement();
if ( ele ) {
if ( endTag.Empty() && ele->ClosingType() == XMLElement::OPEN ) {
_document->SetError( XML_ERROR_MISMATCHED_ELEMENT, node->Value(), 0 );
@@ -860,7 +849,7 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEnd )
}
}
if ( p == 0 ) {
DELETE_NODE( node );
DeleteNode( node );
node = 0;
}
if ( node ) {
@@ -870,6 +859,16 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEnd )
return 0;
}
void XMLNode::DeleteNode( XMLNode* node )
{
if ( node == 0 ) {
return;
}
MemPool* pool = node->_memPool;
node->~XMLNode();
pool->Free( node );
}
// --------- XMLText ---------- //
char* XMLText::ParseDeep( char* p, StrPair* )
{
@@ -958,7 +957,8 @@ XMLNode* XMLComment::ShallowClone( XMLDocument* doc ) const
bool XMLComment::ShallowEqual( const XMLNode* compare ) const
{
return ( compare->ToComment() && XMLUtil::StringEqual( compare->ToComment()->Value(), Value() ));
const XMLComment* comment = compare->ToComment();
return ( comment && XMLUtil::StringEqual( comment->Value(), Value() ));
}
@@ -1005,7 +1005,8 @@ XMLNode* XMLDeclaration::ShallowClone( XMLDocument* doc ) const
bool XMLDeclaration::ShallowEqual( const XMLNode* compare ) const
{
return ( compare->ToDeclaration() && XMLUtil::StringEqual( compare->ToDeclaration()->Value(), Value() ));
const XMLDeclaration* declaration = compare->ToDeclaration();
return ( declaration && XMLUtil::StringEqual( declaration->Value(), Value() ));
}
@@ -1052,7 +1053,8 @@ XMLNode* XMLUnknown::ShallowClone( XMLDocument* doc ) const
bool XMLUnknown::ShallowEqual( const XMLNode* compare ) const
{
return ( compare->ToUnknown() && XMLUtil::StringEqual( compare->ToUnknown()->Value(), Value() ));
const XMLUnknown* unknown = compare->ToUnknown();
return ( unknown && XMLUtil::StringEqual( unknown->Value(), Value() ));
}
@@ -1208,7 +1210,7 @@ XMLElement::~XMLElement()
{
while( _rootAttribute ) {
XMLAttribute* next = _rootAttribute->_next;
DELETE_ATTRIBUTE( _rootAttribute );
DeleteAttribute( _rootAttribute );
_rootAttribute = next;
}
}
@@ -1216,8 +1218,7 @@ XMLElement::~XMLElement()
XMLAttribute* XMLElement::FindAttribute( const char* name )
{
XMLAttribute* a = 0;
for( a=_rootAttribute; a; a = a->_next ) {
for( XMLAttribute* a = _rootAttribute; a; a = a->_next ) {
if ( XMLUtil::StringEqual( a->Name(), name ) ) {
return a;
}
@@ -1228,8 +1229,7 @@ XMLAttribute* XMLElement::FindAttribute( const char* name )
const XMLAttribute* XMLElement::FindAttribute( const char* name ) const
{
XMLAttribute* a = 0;
for( a=_rootAttribute; a; a = a->_next ) {
for( XMLAttribute* a = _rootAttribute; a; a = a->_next ) {
if ( XMLUtil::StringEqual( a->Name(), name ) ) {
return a;
}
@@ -1415,7 +1415,7 @@ void XMLElement::DeleteAttribute( const char* name )
else {
_rootAttribute = a->_next;
}
DELETE_ATTRIBUTE( a );
DeleteAttribute( a );
break;
}
prev = a;
@@ -1444,7 +1444,7 @@ char* XMLElement::ParseAttributes( char* p )
p = attrib->ParseDeep( p, _document->ProcessEntities() );
if ( !p || Attribute( attrib->Name() ) ) {
DELETE_ATTRIBUTE( attrib );
DeleteAttribute( attrib );
_document->SetError( XML_ERROR_PARSING_ATTRIBUTE, start, p );
return 0;
}
@@ -1479,6 +1479,15 @@ char* XMLElement::ParseAttributes( char* p )
return p;
}
void XMLElement::DeleteAttribute( XMLAttribute* attribute )
{
if ( attribute == 0 ) {
return;
}
MemPool* pool = attribute->_memPool;
attribute->~XMLAttribute();
pool->Free( attribute );
}
//
// <ele></ele>
@@ -1568,6 +1577,32 @@ bool XMLElement::Accept( XMLVisitor* visitor ) const
// --------- XMLDocument ----------- //
// Warning: List must match 'enum XMLError'
const char* XMLDocument::_errorNames[XML_ERROR_COUNT] = {
"XML_SUCCESS",
"XML_NO_ATTRIBUTE",
"XML_WRONG_ATTRIBUTE_TYPE",
"XML_ERROR_FILE_NOT_FOUND",
"XML_ERROR_FILE_COULD_NOT_BE_OPENED",
"XML_ERROR_FILE_READ_ERROR",
"XML_ERROR_ELEMENT_MISMATCH",
"XML_ERROR_PARSING_ELEMENT",
"XML_ERROR_PARSING_ATTRIBUTE",
"XML_ERROR_IDENTIFYING_TAG",
"XML_ERROR_PARSING_TEXT",
"XML_ERROR_PARSING_CDATA",
"XML_ERROR_PARSING_COMMENT",
"XML_ERROR_PARSING_DECLARATION",
"XML_ERROR_PARSING_UNKNOWN",
"XML_ERROR_EMPTY_DOCUMENT",
"XML_ERROR_MISMATCHED_ELEMENT",
"XML_ERROR_PARSING",
"XML_CAN_NOT_CONVERT_TEXT",
"XML_NO_TEXT_NODE"
};
XMLDocument::XMLDocument( bool processEntities, Whitespace whitespace ) :
XMLNode( 0 ),
_writeBOM( false ),
@@ -1662,19 +1697,25 @@ XMLUnknown* XMLDocument::NewUnknown( const char* str )
return unk;
}
static FILE* callfopen( const char* filepath, const char* mode )
{
#if defined(_MSC_VER) && (_MSC_VER >= 1400 ) && (!defined WINCE)
FILE* fp = 0;
errno_t err = fopen_s( &fp, filepath, mode );
if ( err ) {
return 0;
}
#else
FILE* fp = fopen( filepath, mode );
#endif
return fp;
}
XMLError XMLDocument::LoadFile( const char* filename )
{
Clear();
FILE* fp = 0;
#if defined(_MSC_VER) && (_MSC_VER >= 1400 )
errno_t err = fopen_s(&fp, filename, "rb" );
if ( !fp || err) {
#else
fp = fopen( filename, "rb" );
if ( !fp) {
#endif
FILE* fp = callfopen( filename, "rb" );
if ( !fp ) {
SetError( XML_ERROR_FILE_NOT_FOUND, filename, 0 );
return _errorID;
}
@@ -1689,16 +1730,20 @@ XMLError XMLDocument::LoadFile( FILE* fp )
Clear();
fseek( fp, 0, SEEK_SET );
fgetc( fp );
if ( ferror( fp ) != 0 ) {
if ( fgetc( fp ) == EOF && ferror( fp ) != 0 ) {
SetError( XML_ERROR_FILE_READ_ERROR, 0, 0 );
return _errorID;
}
fseek( fp, 0, SEEK_END );
size_t size = ftell( fp );
const long filelength = ftell( fp );
fseek( fp, 0, SEEK_SET );
if ( filelength == -1L ) {
SetError( XML_ERROR_FILE_READ_ERROR, 0, 0 );
return _errorID;
}
const size_t size = filelength;
if ( size == 0 ) {
SetError( XML_ERROR_EMPTY_DOCUMENT, 0, 0 );
return _errorID;
@@ -1728,14 +1773,8 @@ XMLError XMLDocument::LoadFile( FILE* fp )
XMLError XMLDocument::SaveFile( const char* filename, bool compact )
{
FILE* fp = 0;
#if defined(_MSC_VER) && (_MSC_VER >= 1400 )
errno_t err = fopen_s(&fp, filename, "w" );
if ( !fp || err) {
#else
fp = fopen( filename, "w" );
if ( !fp) {
#endif
FILE* fp = callfopen( filename, "w" );
if ( !fp ) {
SetError( XML_ERROR_FILE_COULD_NOT_BE_OPENED, filename, 0 );
return _errorID;
}
@@ -1799,6 +1838,11 @@ void XMLDocument::SetError( XMLError error, const char* str1, const char* str2 )
_errorStr2 = str2;
}
const char* XMLDocument::ErrorName() const
{
TIXMLASSERT(_errorID >= 0 && _errorID < XML_ERROR_COUNT );
return _errorNames[_errorID];
}
void XMLDocument::PrintError() const
{
@@ -1814,8 +1858,8 @@ void XMLDocument::PrintError() const
TIXML_SNPRINTF( buf2, LEN, "%s", _errorStr2 );
}
printf( "XMLDocument error id=%d str1=%s str2=%s\n",
_errorID, buf1, buf2 );
printf( "XMLDocument error id=%d '%s' str1=%s str2=%s\n",
_errorID, ErrorName(), buf1, buf2 );
}
}
@@ -1856,7 +1900,17 @@ void XMLPrinter::Print( const char* format, ... )
}
else {
#if defined(_MSC_VER) && (_MSC_VER >= 1400 )
#if defined(WINCE)
int len = 512;
do {
len = len*2;
char* str = new char[len]();
len = _vsnprintf(str, len, format, va);
delete[] str;
}while (len < 0);
#else
int len = _vscprintf( format, va );
#endif
#else
int len = vsnprintf( 0, 0, format, va );
#endif
@@ -1865,7 +1919,11 @@ void XMLPrinter::Print( const char* format, ... )
va_start( va, format );
char* p = _buffer.PushArr( len ) - 1; // back up over the null terminator.
#if defined(_MSC_VER) && (_MSC_VER >= 1400 )
#if defined(WINCE)
_vsnprintf( p, len+1, format, va );
#else
vsnprintf_s( p, len+1, _TRUNCATE, format, va );
#endif
#else
vsnprintf( p, len+1, format, va );
#endif

View File

@@ -91,7 +91,7 @@ distribution.
#endif
#if defined(_MSC_VER) && (_MSC_VER >= 1400 )
#if defined(_MSC_VER) && (_MSC_VER >= 1400 ) && (!defined WINCE)
// Microsoft visual studio, version 2005 and higher.
/*int _snprintf_s(
char *buffer,
@@ -109,6 +109,9 @@ inline int TIXML_SNPRINTF( char* buffer, size_t size, const char* format, ... )
return result;
}
#define TIXML_SSCANF sscanf_s
#elif defined WINCE
#define TIXML_SNPRINTF _snprintf
#define TIXML_SSCANF sscanf
#else
// GCC version 3 and higher
//#warning( "Using sn* functions." )
@@ -120,8 +123,8 @@ inline int TIXML_SNPRINTF( char* buffer, size_t size, const char* format, ... )
http://semver.org/
*/
static const int TIXML2_MAJOR_VERSION = 2;
static const int TIXML2_MINOR_VERSION = 0;
static const int TIXML2_PATCH_VERSION = 2;
static const int TIXML2_MINOR_VERSION = 2;
static const int TIXML2_PATCH_VERSION = 0;
namespace tinyxml2
{
@@ -367,7 +370,7 @@ public:
return;
}
--_currentAllocs;
Chunk* chunk = (Chunk*)mem;
Chunk* chunk = static_cast<Chunk*>( mem );
#ifdef DEBUG
memset( chunk, 0xfe, sizeof(Chunk) );
#endif
@@ -477,6 +480,33 @@ public:
}
};
// WARNING: must match XMLErrorNames[]
enum XMLError {
XML_SUCCESS = 0,
XML_NO_ERROR = 0,
XML_NO_ATTRIBUTE,
XML_WRONG_ATTRIBUTE_TYPE,
XML_ERROR_FILE_NOT_FOUND,
XML_ERROR_FILE_COULD_NOT_BE_OPENED,
XML_ERROR_FILE_READ_ERROR,
XML_ERROR_ELEMENT_MISMATCH,
XML_ERROR_PARSING_ELEMENT,
XML_ERROR_PARSING_ATTRIBUTE,
XML_ERROR_IDENTIFYING_TAG,
XML_ERROR_PARSING_TEXT,
XML_ERROR_PARSING_CDATA,
XML_ERROR_PARSING_COMMENT,
XML_ERROR_PARSING_DECLARATION,
XML_ERROR_PARSING_UNKNOWN,
XML_ERROR_EMPTY_DOCUMENT,
XML_ERROR_MISMATCHED_ELEMENT,
XML_ERROR_PARSING,
XML_CAN_NOT_CONVERT_TEXT,
XML_NO_TEXT_NODE,
XML_ERROR_COUNT
};
/*
Utility functionality.
@@ -844,6 +874,7 @@ protected:
private:
MemPool* _memPool;
void Unlink( XMLNode* child );
static void DeleteNode( XMLNode* node );
};
@@ -993,33 +1024,6 @@ protected:
};
enum XMLError {
XML_NO_ERROR = 0,
XML_SUCCESS = 0,
XML_NO_ATTRIBUTE,
XML_WRONG_ATTRIBUTE_TYPE,
XML_ERROR_FILE_NOT_FOUND,
XML_ERROR_FILE_COULD_NOT_BE_OPENED,
XML_ERROR_FILE_READ_ERROR,
XML_ERROR_ELEMENT_MISMATCH,
XML_ERROR_PARSING_ELEMENT,
XML_ERROR_PARSING_ATTRIBUTE,
XML_ERROR_IDENTIFYING_TAG,
XML_ERROR_PARSING_TEXT,
XML_ERROR_PARSING_CDATA,
XML_ERROR_PARSING_COMMENT,
XML_ERROR_PARSING_DECLARATION,
XML_ERROR_PARSING_UNKNOWN,
XML_ERROR_EMPTY_DOCUMENT,
XML_ERROR_MISMATCHED_ELEMENT,
XML_ERROR_PARSING,
XML_CAN_NOT_CONVERT_TEXT,
XML_NO_TEXT_NODE
};
/** An attribute is a name-value pair. Elements have an arbitrary
number of attributes, each with a unique name.
@@ -1477,6 +1481,7 @@ private:
XMLAttribute* FindOrCreateAttribute( const char* name );
//void LinkAttribute( XMLAttribute* attrib );
char* ParseAttributes( char* p );
static void DeleteAttribute( XMLAttribute* attribute );
enum { BUF_SIZE = 200 };
int _closingType;
@@ -1658,6 +1663,8 @@ public:
XMLError ErrorID() const {
return _errorID;
}
const char* ErrorName() const;
/// Return a possibly helpful diagnostic location or string.
const char* GetErrorStr1() const {
return _errorStr1;
@@ -1698,6 +1705,8 @@ private:
MemPoolT< sizeof(XMLAttribute) > _attributePool;
MemPoolT< sizeof(XMLText) > _textPool;
MemPoolT< sizeof(XMLComment) > _commentPool;
static const char* _errorNames[XML_ERROR_COUNT];
};
@@ -1816,19 +1825,19 @@ public:
}
/// Safe cast to XMLElement. This can return null.
XMLElement* ToElement() {
return ( ( _node && _node->ToElement() ) ? _node->ToElement() : 0 );
return ( ( _node == 0 ) ? 0 : _node->ToElement() );
}
/// Safe cast to XMLText. This can return null.
XMLText* ToText() {
return ( ( _node && _node->ToText() ) ? _node->ToText() : 0 );
return ( ( _node == 0 ) ? 0 : _node->ToText() );
}
/// Safe cast to XMLUnknown. This can return null.
XMLUnknown* ToUnknown() {
return ( ( _node && _node->ToUnknown() ) ? _node->ToUnknown() : 0 );
return ( ( _node == 0 ) ? 0 : _node->ToUnknown() );
}
/// Safe cast to XMLDeclaration. This can return null.
XMLDeclaration* ToDeclaration() {
return ( ( _node && _node->ToDeclaration() ) ? _node->ToDeclaration() : 0 );
return ( ( _node == 0 ) ? 0 : _node->ToDeclaration() );
}
private:
@@ -1888,16 +1897,16 @@ public:
return _node;
}
const XMLElement* ToElement() const {
return ( ( _node && _node->ToElement() ) ? _node->ToElement() : 0 );
return ( ( _node == 0 ) ? 0 : _node->ToElement() );
}
const XMLText* ToText() const {
return ( ( _node && _node->ToText() ) ? _node->ToText() : 0 );
return ( ( _node == 0 ) ? 0 : _node->ToText() );
}
const XMLUnknown* ToUnknown() const {
return ( ( _node && _node->ToUnknown() ) ? _node->ToUnknown() : 0 );
return ( ( _node == 0 ) ? 0 : _node->ToUnknown() );
}
const XMLDeclaration* ToDeclaration() const {
return ( ( _node && _node->ToDeclaration() ) ? _node->ToDeclaration() : 0 );
return ( ( _node == 0 ) ? 0 : _node->ToDeclaration() );
}
private:
@@ -1964,7 +1973,7 @@ public:
/** If streaming, start writing an element.
The element must be closed with CloseElement()
*/
void OpenElement( const char* name, bool compactMode );
void OpenElement( const char* name, bool compactMode=false );
/// If streaming, add an attribute to an open element.
void PushAttribute( const char* name, const char* value );
void PushAttribute( const char* name, int value );
@@ -1972,7 +1981,7 @@ public:
void PushAttribute( const char* name, bool value );
void PushAttribute( const char* name, double value );
/// If streaming, close the Element.
virtual void CloseElement( bool compactMode );
virtual void CloseElement( bool compactMode=false );
/// Add a text node.
void PushText( const char* text, bool cdata=false );
@@ -2031,7 +2040,7 @@ public:
}
protected:
virtual bool CompactMode( const XMLElement& ) { return _compactMode; };
virtual bool CompactMode( const XMLElement& ) { return _compactMode; }
/** Prints out the space before an element. You may override to change
the space and tabs used. A PrintSpace() override should call Print().
@@ -2061,9 +2070,6 @@ private:
bool _restrictedEntityFlag[ENTITY_RANGE];
DynArray< char, 20 > _buffer;
#ifdef _MSC_VER
DynArray< char, 20 > _accumulator;
#endif
};

View File

@@ -1,5 +1,7 @@
#if defined( _MSC_VER )
#define _CRT_SECURE_NO_WARNINGS // This test file is not intended to be secure.
#if !defined( _CRT_SECURE_NO_WARNINGS )
#define _CRT_SECURE_NO_WARNINGS // This test file is not intended to be secure.
#endif
#endif
#include "tinyxml2.h"
@@ -1220,6 +1222,8 @@ int main( int argc, const char ** argv )
XMLDocument doc;
XMLError error = doc.LoadFile( "resources/empty.xml" );
XMLTest( "Loading an empty file", XML_ERROR_EMPTY_DOCUMENT, error );
XMLTest( "Loading an empty file and ErrorName as string", "XML_ERROR_EMPTY_DOCUMENT", doc.ErrorName() );
doc.PrintError();
}
{