Imported Upstream version 4.0.0 upstream/4.0.0
authorJinWang An <jinwang.an@samsung.com>
Fri, 30 Oct 2020 05:29:39 +0000 (14:29 +0900)
committerJinWang An <jinwang.an@samsung.com>
Fri, 30 Oct 2020 05:29:39 +0000 (14:29 +0900)
15 files changed:
.gitignore
.travis.yml [new file with mode: 0644]
CMakeLists.txt
Makefile
appveyor.yml [new file with mode: 0644]
biicode.conf [new file with mode: 0644]
cmake_uninstall.cmake.in [new file with mode: 0644]
contrib/html5-printer.cpp
dox
readme.md
tinyxml2.cpp
tinyxml2.h
tinyxml2/test.vcxproj
tinyxml2/tinyxml2.vcxproj
xmltest.cpp

index a7655772ab755010463df01e1450d56fa7ecb470..f5b7e9960c3caaef10383dff5b9419d81067a83a 100644 (file)
@@ -10,4 +10,5 @@ tinyxml2/tinyxml2-cbp/obj/
 *.opensdf
 *.user
 *.depend
-*.layout
\ No newline at end of file
+*.layout
+*.o
diff --git a/.travis.yml b/.travis.yml
new file mode 100644 (file)
index 0000000..50e9a6f
--- /dev/null
@@ -0,0 +1,15 @@
+language: cpp
+
+os:
+  - linux
+  - osx
+
+compiler:
+  - g++
+  - clang
+
+before_script: cmake .
+
+script:
+  - make -j3
+  - ./xmltest
index 16f2ccdc3a5a88b5ecc088b4591fcccff1eea69c..98d4c555faa5cfe9c5ba16d3a3ae0a3f6560ba3d 100644 (file)
@@ -1,3 +1,10 @@
+IF(BIICODE)\r
+       ADD_BIICODE_TARGETS()\r
+       if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/resources)\r
+               file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/resources DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})\r
+    ENDIF()\r
+    RETURN()\r
+ENDIF(BIICODE)\r
 cmake_minimum_required(VERSION 2.6 FATAL_ERROR)\r
 cmake_policy(VERSION 2.6)\r
 \r
@@ -10,12 +17,12 @@ include(GNUInstallDirs)
 ################################\r
 # set lib version here\r
 \r
-set(GENERIC_LIB_VERSION "3.0.0")
-set(GENERIC_LIB_SOVERSION "3")
+set(GENERIC_LIB_VERSION "4.0.0")\r
+set(GENERIC_LIB_SOVERSION "4")\r
 \r
 \r
 ################################\r
-# Add common source \r
+# Add common source\r
 \r
 include_directories("${CMAKE_CURRENT_SOURCE_DIR}/.")\r
 \r
@@ -23,19 +30,20 @@ include_directories("${CMAKE_CURRENT_SOURCE_DIR}/.")
 # Add custom target to copy all data\r
 \r
 set(TARGET_DATA_COPY DATA_COPY)\r
-if(${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_BINARY_DIR})\r
-       add_custom_target(\r
-               ${TARGET_DATA_COPY}\r
-               COMMAND ${CMAKE_COMMAND} -E echo "In source build")\r
-else(${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_BINARY_DIR})\r
-       make_directory(${CMAKE_CURRENT_BINARY_DIR}/resources/)\r
-       add_custom_target(\r
-               ${TARGET_DATA_COPY}\r
-               COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/resources/dream.xml ${CMAKE_CURRENT_BINARY_DIR}/resources/\r
-               COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/resources/empty.xml ${CMAKE_CURRENT_BINARY_DIR}/resources/\r
-               COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/resources/utf8test.xml ${CMAKE_CURRENT_BINARY_DIR}/resources/\r
-               COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/resources/utf8testverify.xml ${CMAKE_CURRENT_BINARY_DIR}/resources/)\r
-endif(${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_BINARY_DIR})\r
+set(DATA_COPY_FILES)\r
+if(NOT ${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_BINARY_DIR})\r
+       foreach(data dream.xml empty.xml utf8test.xml utf8testverify.xml)\r
+               set(DATA_COPY_SRC  ${CMAKE_CURRENT_SOURCE_DIR}/resources/${data})\r
+               set(DATA_COPY_DEST ${CMAKE_CURRENT_BINARY_DIR}/resources/${data})\r
+               add_custom_command(\r
+                       OUTPUT ${DATA_COPY_DEST}\r
+                       COMMAND ${CMAKE_COMMAND}\r
+                       ARGS -E copy ${DATA_COPY_SRC} ${DATA_COPY_DEST}\r
+                       DEPENDS ${DATA_COPY_SRC})\r
+               list(APPEND DATA_COPY_FILES ${DATA_COPY_DEST})\r
+       endforeach(data)\r
+endif(NOT ${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_BINARY_DIR})\r
+add_custom_target(${TARGET_DATA_COPY} DEPENDS ${DATA_COPY_FILES})\r
 \r
 ################################\r
 # Add definitions\r
@@ -44,25 +52,65 @@ if(MSVC)
        add_definitions(-D_CRT_SECURE_NO_WARNINGS)\r
 endif(MSVC)\r
 \r
+set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG")\r
+\r
 ################################\r
 # Add targets\r
-option(BUILD_SHARED_LIBS "build shared or static libraries" ON)\r
-add_library(tinyxml2 tinyxml2.cpp tinyxml2.h)\r
+# By Default shared libray is being built\r
+# To build static libs also - Do cmake . -DBUILD_STATIC_LIBS:BOOL=ON\r
+# User can choose not to build shared library by using cmake -BUILD_SHARED_LIBS:BOOL:OFF\r
+# To build only static libs use cmake . -DBUILD_SHARED_LIBS:BOOL=OFF -DBUILD_STATIC_LIBS:BOOL=ON\r
+\r
+option(BUILD_SHARED_LIBS "build as shared library" ON)\r
+option(BUILD_STATIC_LIBS "build as static library" OFF)\r
+\r
+if(BUILD_SHARED_LIBS)\r
+add_library(tinyxml2 SHARED tinyxml2.cpp tinyxml2.h)\r
+\r
 set_target_properties(tinyxml2 PROPERTIES\r
         COMPILE_DEFINITIONS "TINYXML2_EXPORT"\r
        VERSION "${GENERIC_LIB_VERSION}"\r
        SOVERSION "${GENERIC_LIB_SOVERSION}")\r
 \r
-add_executable(xmltest xmltest.cpp)\r
-add_dependencies(xmltest tinyxml2)\r
-add_dependencies(xmltest ${TARGET_DATA_COPY})\r
-target_link_libraries(xmltest tinyxml2)\r
-\r
+if(DEFINED CMAKE_VERSION AND NOT "${CMAKE_VERSION}" VERSION_LESS "2.8.11")\r
+    target_include_directories(tinyxml2 INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/.")\r
+endif()\r
 \r
 install(TARGETS tinyxml2\r
         RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}\r
         LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}\r
         ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})\r
+endif()\r
+\r
+if(BUILD_STATIC_LIBS)\r
+add_library(tinyxml2_static STATIC tinyxml2.cpp tinyxml2.h)\r
+set_target_properties(tinyxml2_static PROPERTIES\r
+        COMPILE_DEFINITONS "TINYXML2_EXPORT"\r
+        VERSION "${GENERIC_LIB_VERSION}"\r
+        SOVERSION "${GENERIC_LIB_SOVERSION}")\r
+set_target_properties( tinyxml2_static PROPERTIES OUTPUT_NAME tinyxml2 )\r
+\r
+if(DEFINED CMAKE_VERSION AND NOT "${CMAKE_VERSION}" VERSION_LESS "2.8.11")\r
+    target_include_directories(tinyxml2_static INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/.")\r
+endif()\r
+\r
+install(TARGETS tinyxml2_static\r
+        RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}\r
+        LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}\r
+        ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})\r
+endif()\r
+\r
+add_executable(xmltest xmltest.cpp)\r
+if(BUILD_SHARED_LIBS)\r
+   add_dependencies(xmltest tinyxml2)\r
+   add_dependencies(xmltest ${TARGET_DATA_COPY})\r
+   target_link_libraries(xmltest tinyxml2)\r
+else(BUILD_STATIC_LIBS)\r
+   add_dependencies(xmltest tinyxml2_static)\r
+   add_dependencies(xmltest ${TARGET_DATA_COPY})\r
+   target_link_libraries(xmltest tinyxml2_static)\r
+endif()\r
+install(TARGETS DESTINATION ${CMAKE_INSTALL_BINDIR})\r
 \r
 install(FILES tinyxml2.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})\r
 \r
@@ -77,3 +125,12 @@ configure_file(tinyxml2.pc.in tinyxml2.pc @ONLY)
 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/tinyxml2.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)\r
 \r
 #add_test(xmltest ${SAMPLE_NAME} COMMAND $<TARGET_FILE:${SAMPLE_NAME}>)\r
+\r
+# uninstall target\r
+configure_file(\r
+    "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"\r
+    "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"\r
+    IMMEDIATE @ONLY)\r
+\r
+add_custom_target(uninstall\r
+    COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)\r
index aab62932e2efaf44fe561add4324b3fe779daf12..eba6fef161db26f4169759fec72b729178195963 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,19 @@
-all: xmltest
-xmltest: xmltest.cpp tinyxml2.cpp tinyxml2.h
+all: xmltest staticlib
+
+rebuild: clean all
+
+xmltest: xmltest.cpp libtinyxml2.a
+
+clean:
+       $(RM) *.o xmltest libtinyxml2.a
+       
 test: clean xmltest
        ./xmltest
-clean:
-       rm -f *.o xmltest
+
+staticlib: libtinyxml2.a
+
+libtinyxml2.a: tinyxml2.o
+       $(AR) $(ARFLAGS)s $@ $^
+       
+tinyxml2.o: tinyxml2.cpp tinyxml2.h
+
diff --git a/appveyor.yml b/appveyor.yml
new file mode 100644 (file)
index 0000000..aac8867
--- /dev/null
@@ -0,0 +1,7 @@
+before_build:
+  - cmake .
+
+build_script:
+  - msbuild tinyxml2.sln /m /p:Configuration=Release /t:ALL_BUILD
+  - copy Release\xmltest.exe .\ && copy Release\tinyxml2.dll .\
+  - xmltest.exe
diff --git a/biicode.conf b/biicode.conf
new file mode 100644 (file)
index 0000000..5dca6b1
--- /dev/null
@@ -0,0 +1,7 @@
+# Biicode configuration file
+
+[paths]
+    /
+
+[dependencies]
+    xmltest.cpp + resources/*.xml
\ No newline at end of file
diff --git a/cmake_uninstall.cmake.in b/cmake_uninstall.cmake.in
new file mode 100644 (file)
index 0000000..2c34c81
--- /dev/null
@@ -0,0 +1,21 @@
+if(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
+  message(FATAL_ERROR "Cannot find install manifest: @CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
+endif(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
+
+file(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files)
+string(REGEX REPLACE "\n" ";" files "${files}")
+foreach(file ${files})
+  message(STATUS "Uninstalling $ENV{DESTDIR}${file}")
+  if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
+    exec_program(
+      "@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\""
+      OUTPUT_VARIABLE rm_out
+      RETURN_VALUE rm_retval
+      )
+    if(NOT "${rm_retval}" STREQUAL 0)
+      message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}")
+    endif(NOT "${rm_retval}" STREQUAL 0)
+  else(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
+    message(STATUS "File $ENV{DESTDIR}${file} does not exist.")
+  endif(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
+endforeach(file)
\ No newline at end of file
index 3205ccd09bd35c8ef5eb0127c543af8920003362..7728b692fdd15c39a5a7162dd931ba4fec524982 100644 (file)
@@ -65,7 +65,7 @@ public:
 protected:
     virtual void CloseElement () {
         if (_elementJustOpened && !isVoidElement (_stack.PeekTop())) {
-            SealElement();
+            SealElementIfJustOpened();
             }
         XMLPrinter::CloseElement();
     }
diff --git a/dox b/dox
index 7c3cd7884fb92feb2e6f2a3c7123eb0eeb30e245..5ae0b213bf410f36baffa09af762ea18be1cb366 100644 (file)
--- a/dox
+++ b/dox
@@ -38,7 +38,7 @@ PROJECT_NAME           = "TinyXML-2"
 # could be handy for archiving the generated documentation or if some version\r
 # control system is used.\r
 \r
-PROJECT_NUMBER = 3.0.0
+PROJECT_NUMBER = 4.0.0\r
 \r
 # Using the PROJECT_BRIEF tag one can provide an optional one line description\r
 # for a project that appears at the top of each page and should give viewer a\r
index 485e00fc8454554869d33ecfbaddcfa514050baa..82c6ce927580da2896e73e61ef867b6ec7de17e6 100644 (file)
--- a/readme.md
+++ b/readme.md
@@ -1,4 +1,4 @@
-TinyXML-2
+TinyXML-2 [![TravisCI Status](https://travis-ci.org/leethomason/tinyxml2.svg?branch=master)](https://travis-ci.org/leethomason/tinyxml2) [![AppVeyor Status](https://ci.appveyor.com/api/projects/status/github/leethomason/tinyxml2?branch=master&svg=true)](https://ci.appveyor.com/project/leethomason/tinyxml2)
 =========
 ![TinyXML-2 Logo](http://www.grinninglizard.com/tinyxml2/TinyXML2_small.png)
 
@@ -177,7 +177,7 @@ will have the Value() of "Far & Away" when queried from the XMLText object,
 and will be written back to the XML stream/file as an ampersand. 
 
 Additionally, any character can be specified by its Unicode code point:
-The syntax "&#xA0;" or "&#160;" are both to the non-breaking space characher. 
+The syntax `&#xA0;` or `&#160;` are both to the non-breaking space character. 
 This is called a 'numeric character reference'. Any numeric character reference
 that isn't one of the special entities above, will be read, but written as a
 regular code point. The output is correct, but the entity syntax isn't preserved.
@@ -264,8 +264,8 @@ There are 2 files in TinyXML-2:
 And additionally a test file:
 * xmltest.cpp
 
-Simply compile and run. There is a visual studio 2010 project included, a simple Makefile, 
-an XCode project, a Code::Blocks project, and a cmake CMakeLists.txt included to help you. 
+Simply compile and run. There is a visual studio 2015 project included, a simple Makefile, 
+an Xcode project, a Code::Blocks project, and a cmake CMakeLists.txt included to help you. 
 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.
 
index 6d8573bde7e8831daccfb04e1b32039bc4bd5593..d5d8ebb9e6fbae1cccd0a5384467c9a417d501c9 100755 (executable)
@@ -24,12 +24,83 @@ distribution.
 #include "tinyxml2.h"\r
 \r
 #include <new>         // yes, this one new style header, is in the Android SDK.\r
-#if defined(ANDROID_NDK) || defined(__QNXNTO__)\r
+#if defined(ANDROID_NDK) || defined(__BORLANDC__) || defined(__QNXNTO__)\r
 #   include <stddef.h>\r
+#   include <stdarg.h>\r
 #else\r
 #   include <cstddef>\r
+#   include <cstdarg>\r
 #endif\r
 \r
+#if defined(_MSC_VER) && (_MSC_VER >= 1400 ) && (!defined WINCE)\r
+       // Microsoft Visual Studio, version 2005 and higher. Not WinCE.\r
+       /*int _snprintf_s(\r
+          char *buffer,\r
+          size_t sizeOfBuffer,\r
+          size_t count,\r
+          const char *format [,\r
+                 argument] ...\r
+       );*/\r
+       static inline int TIXML_SNPRINTF( char* buffer, size_t size, const char* format, ... )\r
+       {\r
+               va_list va;\r
+               va_start( va, format );\r
+               int result = vsnprintf_s( buffer, size, _TRUNCATE, format, va );\r
+               va_end( va );\r
+               return result;\r
+       }\r
+\r
+       static inline int TIXML_VSNPRINTF( char* buffer, size_t size, const char* format, va_list va )\r
+       {\r
+               int result = vsnprintf_s( buffer, size, _TRUNCATE, format, va );\r
+               return result;\r
+       }\r
+\r
+       #define TIXML_VSCPRINTF _vscprintf\r
+       #define TIXML_SSCANF    sscanf_s\r
+#elif defined _MSC_VER\r
+       // Microsoft Visual Studio 2003 and earlier or WinCE\r
+       #define TIXML_SNPRINTF  _snprintf\r
+       #define TIXML_VSNPRINTF _vsnprintf\r
+       #define TIXML_SSCANF    sscanf\r
+       #if (_MSC_VER < 1400 ) && (!defined WINCE)\r
+               // Microsoft Visual Studio 2003 and not WinCE.\r
+               #define TIXML_VSCPRINTF   _vscprintf // VS2003's C runtime has this, but VC6 C runtime or WinCE SDK doesn't have.\r
+       #else\r
+               // Microsoft Visual Studio 2003 and earlier or WinCE.\r
+               static inline int TIXML_VSCPRINTF( const char* format, va_list va )\r
+               {\r
+                       int len = 512;\r
+                       for (;;) {\r
+                               len = len*2;\r
+                               char* str = new char[len]();\r
+                               const int required = _vsnprintf(str, len, format, va);\r
+                               delete[] str;\r
+                               if ( required != -1 ) {\r
+                                       TIXMLASSERT( required >= 0 );\r
+                                       len = required;\r
+                                       break;\r
+                               }\r
+                       }\r
+                       TIXMLASSERT( len >= 0 );\r
+                       return len;\r
+               }\r
+       #endif\r
+#else\r
+       // GCC version 3 and higher\r
+       //#warning( "Using sn* functions." )\r
+       #define TIXML_SNPRINTF  snprintf\r
+       #define TIXML_VSNPRINTF vsnprintf\r
+       static inline int TIXML_VSCPRINTF( const char* format, va_list va )\r
+       {\r
+               int len = vsnprintf( 0, 0, format, va );\r
+               TIXMLASSERT( len >= 0 );\r
+               return len;\r
+       }\r
+       #define TIXML_SSCANF   sscanf\r
+#endif\r
+\r
+\r
 static const char LINE_FEED                            = (char)0x0a;                   // all line endings are normalized to LF\r
 static const char LF = LINE_FEED;\r
 static const char CARRIAGE_RETURN              = (char)0x0d;                   // CR gets filtered out\r
@@ -106,8 +177,10 @@ void StrPair::Reset()
 \r
 void StrPair::SetStr( const char* str, int flags )\r
 {\r
+    TIXMLASSERT( str );\r
     Reset();\r
     size_t len = strlen( str );\r
+    TIXMLASSERT( _start == 0 );\r
     _start = new char[ len+1 ];\r
     memcpy( _start, str, len+1 );\r
     _end = _start + len;\r
@@ -243,8 +316,8 @@ const char* StrPair::GetStr()
                         }\r
                     }\r
                     else {\r
-                        int i=0;\r
-                        for(; i<NUM_ENTITIES; ++i ) {\r
+                        bool entityFound = false;\r
+                        for( int i = 0; i < NUM_ENTITIES; ++i ) {\r
                             const Entity& entity = entities[i];\r
                             if ( strncmp( p + 1, entity.pattern, entity.length ) == 0\r
                                     && *( p + entity.length + 1 ) == ';' ) {\r
@@ -252,10 +325,11 @@ const char* StrPair::GetStr()
                                 *q = entity.value;\r
                                 ++q;\r
                                 p += entity.length + 2;\r
+                                entityFound = true;\r
                                 break;\r
                             }\r
                         }\r
-                        if ( i == NUM_ENTITIES ) {\r
+                        if ( !entityFound ) {\r
                             // fixme: treat as error?\r
                             ++p;\r
                             ++q;\r
@@ -272,7 +346,7 @@ const char* StrPair::GetStr()
         }\r
         // The loop below has plenty going on, and this\r
         // is a less useful mode. Break it out.\r
-        if ( _flags & COLLAPSE_WHITESPACE ) {\r
+        if ( _flags & NEEDS_WHITESPACE_COLLAPSING ) {\r
             CollapseWhitespace();\r
         }\r
         _flags = (_flags & NEEDS_DELETE);\r
@@ -323,7 +397,7 @@ void XMLUtil::ConvertUTF32ToUTF8( unsigned long input, char* output, int* length
         *length = 4;\r
     }\r
     else {\r
-        *length = 0;    // This code won't covert this correctly anyway.\r
+        *length = 0;    // This code won't convert this correctly anyway.\r
         return;\r
     }\r
 \r
@@ -397,8 +471,8 @@ const char* XMLUtil::GetCharacterRef( const char* p, char* value, int* length )
                 else {\r
                     return 0;\r
                 }\r
+                TIXMLASSERT( digit < 16 );\r
                 TIXMLASSERT( digit == 0 || mult <= UINT_MAX / digit );\r
-                               TIXMLASSERT( digit >= 0 && digit < 16);\r
                 const unsigned int digitScaled = mult * digit;\r
                 TIXMLASSERT( ucs <= ULONG_MAX - digitScaled );\r
                 ucs += digitScaled;\r
@@ -427,6 +501,7 @@ const char* XMLUtil::GetCharacterRef( const char* p, char* value, int* length )
             while ( *q != '#' ) {\r
                 if ( *q >= '0' && *q <= '9' ) {\r
                     const unsigned int digit = *q - '0';\r
+                    TIXMLASSERT( digit < 10 );\r
                     TIXMLASSERT( digit == 0 || mult <= UINT_MAX / digit );\r
                     const unsigned int digitScaled = mult * digit;\r
                     TIXMLASSERT( ucs <= ULONG_MAX - digitScaled );\r
@@ -481,6 +556,12 @@ void XMLUtil::ToStr( double v, char* buffer, int bufferSize )
 }\r
 \r
 \r
+void XMLUtil::ToStr(int64_t v, char* buffer, int bufferSize)\r
+{\r
+       TIXML_SNPRINTF(buffer, bufferSize, "%lld", v);\r
+}\r
+\r
+\r
 bool XMLUtil::ToInt( const char* str, int* value )\r
 {\r
     if ( TIXML_SSCANF( str, "%d", value ) == 1 ) {\r
@@ -524,6 +605,7 @@ bool XMLUtil::ToFloat( const char* str, float* value )
     return false;\r
 }\r
 \r
+\r
 bool XMLUtil::ToDouble( const char* str, double* value )\r
 {\r
     if ( TIXML_SSCANF( str, "%lf", value ) == 1 ) {\r
@@ -533,6 +615,15 @@ bool XMLUtil::ToDouble( const char* str, double* value )
 }\r
 \r
 \r
+bool XMLUtil::ToInt64(const char* str, int64_t* value)\r
+{\r
+       if (TIXML_SSCANF(str, "%lld", value) == 1) {\r
+               return true;\r
+       }\r
+       return false;\r
+}\r
+\r
+\r
 char* XMLDocument::Identify( char* p, XMLNode** node )\r
 {\r
     TIXMLASSERT( node );\r
@@ -545,18 +636,17 @@ char* XMLDocument::Identify( char* p, XMLNode** node )
         return p;\r
     }\r
 \r
-    // What is this thing?\r
-       // These strings define the matching patters:\r
+    // These strings define the matching patterns:\r
     static const char* xmlHeader               = { "<?" };\r
     static const char* commentHeader   = { "<!--" };\r
-    static const char* dtdHeader               = { "<!" };\r
     static const char* cdataHeader             = { "<![CDATA[" };\r
+    static const char* dtdHeader               = { "<!" };\r
     static const char* elementHeader   = { "<" };      // and a header for everything else; check last.\r
 \r
     static const int xmlHeaderLen              = 2;\r
     static const int commentHeaderLen  = 4;\r
-    static const int dtdHeaderLen              = 2;\r
     static const int cdataHeaderLen            = 9;\r
+    static const int dtdHeaderLen              = 2;\r
     static const int elementHeaderLen  = 1;\r
 \r
     TIXMLASSERT( sizeof( XMLComment ) == sizeof( XMLUnknown ) );               // use same memory pool\r
@@ -629,6 +719,7 @@ XMLNode::XMLNode( XMLDocument* doc ) :
     _parent( 0 ),\r
     _firstChild( 0 ), _lastChild( 0 ),\r
     _prev( 0 ), _next( 0 ),\r
+       _userData( 0 ),\r
     _memPool( 0 )\r
 {\r
 }\r
@@ -644,6 +735,9 @@ XMLNode::~XMLNode()
 \r
 const char* XMLNode::Value() const \r
 {\r
+    // Catch an edge case: XMLDocuments don't have a a Value. Carefully return nullptr.\r
+    if ( this->ToDocument() )\r
+        return 0;\r
     return _value.GetStr();\r
 }\r
 \r
@@ -661,6 +755,7 @@ void XMLNode::SetValue( const char* str, bool staticMem )
 void XMLNode::DeleteChildren()\r
 {\r
     while( _firstChild ) {\r
+        TIXMLASSERT( _lastChild );\r
         TIXMLASSERT( _firstChild->_document == _document );\r
         XMLNode* node = _firstChild;\r
         Unlink( node );\r
@@ -675,6 +770,7 @@ void XMLNode::Unlink( XMLNode* child )
 {\r
     TIXMLASSERT( child );\r
     TIXMLASSERT( child->_document == _document );\r
+    TIXMLASSERT( child->_parent == this );\r
     if ( child == _firstChild ) {\r
         _firstChild = _firstChild->_next;\r
     }\r
@@ -697,6 +793,7 @@ void XMLNode::DeleteChild( XMLNode* node )
     TIXMLASSERT( node );\r
     TIXMLASSERT( node->_document == _document );\r
     TIXMLASSERT( node->_parent == this );\r
+    Unlink( node );\r
     DeleteNode( node );\r
 }\r
 \r
@@ -793,12 +890,12 @@ XMLNode* XMLNode::InsertAfterChild( XMLNode* afterThis, XMLNode* addThis )
 \r
 \r
 \r
-const XMLElement* XMLNode::FirstChildElement( const char* value ) const\r
+const XMLElement* XMLNode::FirstChildElement( const char* name ) const\r
 {\r
-    for( XMLNode* node=_firstChild; node; node=node->_next ) {\r
-        XMLElement* element = node->ToElement();\r
+    for( const XMLNode* node = _firstChild; node; node = node->_next ) {\r
+        const XMLElement* element = node->ToElement();\r
         if ( element ) {\r
-            if ( !value || XMLUtil::StringEqual( element->Name(), value ) ) {\r
+            if ( !name || XMLUtil::StringEqual( element->Name(), name ) ) {\r
                 return element;\r
             }\r
         }\r
@@ -807,12 +904,12 @@ const XMLElement* XMLNode::FirstChildElement( const char* value ) const
 }\r
 \r
 \r
-const XMLElement* XMLNode::LastChildElement( const char* value ) const\r
+const XMLElement* XMLNode::LastChildElement( const char* name ) const\r
 {\r
-    for( XMLNode* node=_lastChild; node; node=node->_prev ) {\r
-        XMLElement* element = node->ToElement();\r
+    for( const XMLNode* node = _lastChild; node; node = node->_prev ) {\r
+        const XMLElement* element = node->ToElement();\r
         if ( element ) {\r
-            if ( !value || XMLUtil::StringEqual( element->Name(), value ) ) {\r
+            if ( !name || XMLUtil::StringEqual( element->Name(), name ) ) {\r
                 return element;\r
             }\r
         }\r
@@ -821,12 +918,12 @@ const XMLElement* XMLNode::LastChildElement( const char* value ) const
 }\r
 \r
 \r
-const XMLElement* XMLNode::NextSiblingElement( const char* value ) const\r
+const XMLElement* XMLNode::NextSiblingElement( const char* name ) const\r
 {\r
-    for( XMLNode* node=this->_next; node; node = node->_next ) {\r
+    for( const XMLNode* node = _next; node; node = node->_next ) {\r
         const XMLElement* element = node->ToElement();\r
         if ( element\r
-                && (!value || XMLUtil::StringEqual( value, node->Value() ))) {\r
+                && (!name || XMLUtil::StringEqual( name, element->Name() ))) {\r
             return element;\r
         }\r
     }\r
@@ -834,12 +931,12 @@ const XMLElement* XMLNode::NextSiblingElement( const char* value ) const
 }\r
 \r
 \r
-const XMLElement* XMLNode::PreviousSiblingElement( const char* value ) const\r
+const XMLElement* XMLNode::PreviousSiblingElement( const char* name ) const\r
 {\r
-    for( XMLNode* node=_prev; node; node = node->_prev ) {\r
+    for( const XMLNode* node = _prev; node; node = node->_prev ) {\r
         const XMLElement* element = node->ToElement();\r
         if ( element\r
-                && (!value || XMLUtil::StringEqual( value, node->Value() ))) {\r
+                && (!name || XMLUtil::StringEqual( name, element->Name() ))) {\r
             return element;\r
         }\r
     }\r
@@ -884,6 +981,17 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEnd )
             break;\r
         }\r
 \r
+        XMLDeclaration* decl = node->ToDeclaration();\r
+        if ( decl ) {\r
+                // A declaration can only be the first child of a document.\r
+                // Set error, if document already has children.\r
+                if ( !_document->NoChildren() ) {\r
+                        _document->SetError( XML_ERROR_PARSING_DECLARATION, decl->Value(), 0);\r
+                        DeleteNode( decl );\r
+                        break;\r
+                }\r
+        }\r
+\r
         XMLElement* ele = node->ToElement();\r
         if ( ele ) {\r
             // We read the end tag. Return it to the parent.\r
@@ -908,12 +1016,12 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEnd )
                 if ( ele->ClosingType() != XMLElement::OPEN ) {\r
                     mismatch = true;\r
                 }\r
-                else if ( !XMLUtil::StringEqual( endTag.GetStr(), node->Value() ) ) {\r
+                else if ( !XMLUtil::StringEqual( endTag.GetStr(), ele->Name() ) ) {\r
                     mismatch = true;\r
                 }\r
             }\r
             if ( mismatch ) {\r
-                _document->SetError( XML_ERROR_MISMATCHED_ELEMENT, node->Value(), 0 );\r
+                _document->SetError( XML_ERROR_MISMATCHED_ELEMENT, ele->Name(), 0 );\r
                 DeleteNode( node );\r
                 break;\r
             }\r
@@ -958,7 +1066,7 @@ char* XMLText::ParseDeep( char* p, StrPair* )
     else {\r
         int flags = _document->ProcessEntities() ? StrPair::TEXT_ELEMENT : StrPair::TEXT_ELEMENT_LEAVE_ENTITIES;\r
         if ( _document->WhitespaceMode() == COLLAPSE_WHITESPACE ) {\r
-            flags |= StrPair::COLLAPSE_WHITESPACE;\r
+            flags |= StrPair::NEEDS_WHITESPACE_COLLAPSING;\r
         }\r
 \r
         p = _value.ParseText( p, "<", flags );\r
@@ -1195,7 +1303,7 @@ void XMLAttribute::SetName( const char* n )
 XMLError XMLAttribute::QueryIntValue( int* value ) const\r
 {\r
     if ( XMLUtil::ToInt( Value(), value )) {\r
-        return XML_NO_ERROR;\r
+        return XML_SUCCESS;\r
     }\r
     return XML_WRONG_ATTRIBUTE_TYPE;\r
 }\r
@@ -1204,16 +1312,25 @@ XMLError XMLAttribute::QueryIntValue( int* value ) const
 XMLError XMLAttribute::QueryUnsignedValue( unsigned int* value ) const\r
 {\r
     if ( XMLUtil::ToUnsigned( Value(), value )) {\r
-        return XML_NO_ERROR;\r
+        return XML_SUCCESS;\r
     }\r
     return XML_WRONG_ATTRIBUTE_TYPE;\r
 }\r
 \r
 \r
+XMLError XMLAttribute::QueryInt64Value(int64_t* value) const\r
+{\r
+       if (XMLUtil::ToInt64(Value(), value)) {\r
+               return XML_SUCCESS;\r
+       }\r
+       return XML_WRONG_ATTRIBUTE_TYPE;\r
+}\r
+\r
+\r
 XMLError XMLAttribute::QueryBoolValue( bool* value ) const\r
 {\r
     if ( XMLUtil::ToBool( Value(), value )) {\r
-        return XML_NO_ERROR;\r
+        return XML_SUCCESS;\r
     }\r
     return XML_WRONG_ATTRIBUTE_TYPE;\r
 }\r
@@ -1222,7 +1339,7 @@ XMLError XMLAttribute::QueryBoolValue( bool* value ) const
 XMLError XMLAttribute::QueryFloatValue( float* value ) const\r
 {\r
     if ( XMLUtil::ToFloat( Value(), value )) {\r
-        return XML_NO_ERROR;\r
+        return XML_SUCCESS;\r
     }\r
     return XML_WRONG_ATTRIBUTE_TYPE;\r
 }\r
@@ -1231,7 +1348,7 @@ XMLError XMLAttribute::QueryFloatValue( float* value ) const
 XMLError XMLAttribute::QueryDoubleValue( double* value ) const\r
 {\r
     if ( XMLUtil::ToDouble( Value(), value )) {\r
-        return XML_NO_ERROR;\r
+        return XML_SUCCESS;\r
     }\r
     return XML_WRONG_ATTRIBUTE_TYPE;\r
 }\r
@@ -1259,6 +1376,15 @@ void XMLAttribute::SetAttribute( unsigned v )
 }\r
 \r
 \r
+void XMLAttribute::SetAttribute(int64_t v)\r
+{\r
+       char buf[BUF_SIZE];\r
+       XMLUtil::ToStr(v, buf, BUF_SIZE);\r
+       _value.SetStr(buf);\r
+}\r
+\r
+\r
+\r
 void XMLAttribute::SetAttribute( bool v )\r
 {\r
     char buf[BUF_SIZE];\r
@@ -1359,7 +1485,15 @@ void XMLElement::SetText( unsigned v )
 }\r
 \r
 \r
-void XMLElement::SetText( bool v ) \r
+void XMLElement::SetText(int64_t v)\r
+{\r
+       char buf[BUF_SIZE];\r
+       XMLUtil::ToStr(v, buf, BUF_SIZE);\r
+       SetText(buf);\r
+}\r
+\r
+\r
+void XMLElement::SetText( bool v )\r
 {\r
     char buf[BUF_SIZE];\r
     XMLUtil::ToStr( v, buf, BUF_SIZE );\r
@@ -1409,6 +1543,19 @@ XMLError XMLElement::QueryUnsignedText( unsigned* uval ) const
 }\r
 \r
 \r
+XMLError XMLElement::QueryInt64Text(int64_t* ival) const\r
+{\r
+       if (FirstChild() && FirstChild()->ToText()) {\r
+               const char* t = FirstChild()->Value();\r
+               if (XMLUtil::ToInt64(t, ival)) {\r
+                       return XML_SUCCESS;\r
+               }\r
+               return XML_CAN_NOT_CONVERT_TEXT;\r
+       }\r
+       return XML_NO_TEXT_NODE;\r
+}\r
+\r
+\r
 XMLError XMLElement::QueryBoolText( bool* bval ) const\r
 {\r
     if ( FirstChild() && FirstChild()->ToText() ) {\r
@@ -1536,15 +1683,15 @@ char* XMLElement::ParseAttributes( char* p )
             prevAttribute = attrib;\r
         }\r
         // end of the tag\r
-        else if ( *p == '/' && *(p+1) == '>' ) {\r
-            _closingType = CLOSED;\r
-            return p+2;        // done; sealed element.\r
-        }\r
-        // end of the tag\r
         else if ( *p == '>' ) {\r
             ++p;\r
             break;\r
         }\r
+        // end of the tag\r
+        else if ( *p == '/' && *(p+1) == '>' ) {\r
+            _closingType = CLOSED;\r
+            return p+2;        // done; sealed element.\r
+        }\r
         else {\r
             _document->SetError( XML_ERROR_PARSING_ELEMENT, start, p );\r
             return 0;\r
@@ -1613,7 +1760,7 @@ bool XMLElement::ShallowEqual( const XMLNode* compare ) const
 {\r
     TIXMLASSERT( compare );\r
     const XMLElement* other = compare->ToElement();\r
-    if ( other && XMLUtil::StringEqual( other->Value(), Value() )) {\r
+    if ( other && XMLUtil::StringEqual( other->Name(), Name() )) {\r
 \r
         const XMLAttribute* a=FirstAttribute();\r
         const XMLAttribute* b=other->FirstAttribute();\r
@@ -1680,13 +1827,14 @@ XMLDocument::XMLDocument( bool processEntities, Whitespace whitespace ) :
     XMLNode( 0 ),\r
     _writeBOM( false ),\r
     _processEntities( processEntities ),\r
-    _errorID( XML_NO_ERROR ),\r
+    _errorID(XML_SUCCESS),\r
     _whitespace( whitespace ),\r
     _errorStr1( 0 ),\r
     _errorStr2( 0 ),\r
     _charBuffer( 0 )\r
 {\r
-    _document = this;  // avoid warning about 'this' in initializer list\r
+    // avoid VC++ C4355 warning about 'this' in initializer list (C4355 is off by default in VS2012+)\r
+    _document = this;\r
 }\r
 \r
 \r
@@ -1703,7 +1851,7 @@ void XMLDocument::Clear()
 #ifdef DEBUG\r
     const bool hadError = Error();\r
 #endif\r
-    _errorID = XML_NO_ERROR;\r
+    _errorID = XML_SUCCESS;\r
     _errorStr1 = 0;\r
     _errorStr2 = 0;\r
 \r
@@ -1824,6 +1972,28 @@ XMLError XMLDocument::LoadFile( const char* filename )
     return _errorID;\r
 }\r
 \r
+// This is likely overengineered template art to have a check that unsigned long value incremented\r
+// by one still fits into size_t. If size_t type is larger than unsigned long type\r
+// (x86_64-w64-mingw32 target) then the check is redundant and gcc and clang emit\r
+// -Wtype-limits warning. This piece makes the compiler select code with a check when a check\r
+// is useful and code with no check when a check is redundant depending on how size_t and unsigned long\r
+// types sizes relate to each other.\r
+template\r
+<bool = (sizeof(unsigned long) >= sizeof(size_t))>\r
+struct LongFitsIntoSizeTMinusOne {\r
+    static bool Fits( unsigned long value )\r
+    {\r
+        return value < (size_t)-1;\r
+    }\r
+};\r
+\r
+template <>\r
+struct LongFitsIntoSizeTMinusOne<false> {\r
+    static bool Fits( unsigned long )\r
+    {\r
+        return true;\r
+    }\r
+};\r
 \r
 XMLError XMLDocument::LoadFile( FILE* fp )\r
 {\r
@@ -1842,13 +2012,21 @@ XMLError XMLDocument::LoadFile( FILE* fp )
         SetError( XML_ERROR_FILE_READ_ERROR, 0, 0 );\r
         return _errorID;\r
     }\r
+    TIXMLASSERT( filelength >= 0 );\r
 \r
-    const size_t size = filelength;\r
-    if ( size == 0 ) {\r
+    if ( !LongFitsIntoSizeTMinusOne<>::Fits( filelength ) ) {\r
+        // Cannot handle files which won't fit in buffer together with null terminator\r
+        SetError( XML_ERROR_FILE_READ_ERROR, 0, 0 );\r
+        return _errorID;\r
+    }\r
+\r
+    if ( filelength == 0 ) {\r
         SetError( XML_ERROR_EMPTY_DOCUMENT, 0, 0 );\r
         return _errorID;\r
     }\r
 \r
+    const size_t size = filelength;\r
+    TIXMLASSERT( _charBuffer == 0 );\r
     _charBuffer = new char[size+1];\r
     size_t read = fread( _charBuffer, 1, size, fp );\r
     if ( read != size ) {\r
@@ -1878,6 +2056,9 @@ XMLError XMLDocument::SaveFile( const char* filename, bool compact )
 \r
 XMLError XMLDocument::SaveFile( FILE* fp, bool compact )\r
 {\r
+    // Clear any error from the last save, otherwise it will get reported\r
+    // for *this* call.\r
+       SetError(XML_SUCCESS, 0, 0);\r
     XMLPrinter stream( fp, compact );\r
     Print( &stream );\r
     return _errorID;\r
@@ -1895,6 +2076,7 @@ XMLError XMLDocument::Parse( const char* p, size_t len )
     if ( len == (size_t)(-1) ) {\r
         len = strlen( p );\r
     }\r
+    TIXMLASSERT( _charBuffer == 0 );\r
     _charBuffer = new char[ len+1 ];\r
     memcpy( _charBuffer, p, len );\r
     _charBuffer[len] = 0;\r
@@ -1916,11 +2098,13 @@ XMLError XMLDocument::Parse( const char* p, size_t len )
 \r
 void XMLDocument::Print( XMLPrinter* streamer ) const\r
 {\r
-    XMLPrinter stdStreamer( stdout );\r
-    if ( !streamer ) {\r
-        streamer = &stdStreamer;\r
+    if ( streamer ) {\r
+        Accept( streamer );\r
+    }\r
+    else {\r
+        XMLPrinter stdoutStreamer( stdout );\r
+        Accept( &stdoutStreamer );\r
     }\r
-    Accept( streamer );\r
 }\r
 \r
 \r
@@ -1935,7 +2119,9 @@ void XMLDocument::SetError( XMLError error, const char* str1, const char* str2 )
 const char* XMLDocument::ErrorName() const\r
 {\r
        TIXMLASSERT( _errorID >= 0 && _errorID < XML_ERROR_COUNT );\r
-       return _errorNames[_errorID];\r
+    const char* errorName = _errorNames[_errorID];\r
+    TIXMLASSERT( errorName && errorName[0] );\r
+    return errorName;\r
 }\r
 \r
 void XMLDocument::PrintError() const\r
@@ -1952,8 +2138,11 @@ void XMLDocument::PrintError() const
             TIXML_SNPRINTF( buf2, LEN, "%s", _errorStr2 );\r
         }\r
 \r
+        // Should check INT_MIN <= _errorID && _errorId <= INT_MAX, but that\r
+        // causes a clang "always true" -Wtautological-constant-out-of-range-compare warning\r
+        TIXMLASSERT( 0 <= _errorID && XML_ERROR_COUNT - 1 <= INT_MAX );\r
         printf( "XMLDocument error id=%d '%s' str1=%s str2=%s\n",\r
-                _errorID, ErrorName(), buf1, buf2 );\r
+                static_cast<int>( _errorID ), ErrorName(), buf1, buf2 );\r
     }\r
 }\r
 \r
@@ -2005,35 +2194,14 @@ void XMLPrinter::Print( const char* format, ... )
         vfprintf( _fp, format, va );\r
     }\r
     else {\r
-#if defined(_MSC_VER) && (_MSC_VER >= 1400 )\r
-               #if defined(WINCE)\r
-               int len = 512;\r
-               do {\r
-                   len = len*2;\r
-                   char* str = new char[len]();\r
-                       len = _vsnprintf(str, len, format, va);\r
-                       delete[] str;\r
-               }while (len < 0);\r
-               #else\r
-        int len = _vscprintf( format, va );\r
-               #endif\r
-#else\r
-        int len = vsnprintf( 0, 0, format, va );\r
-#endif\r
+        const int len = TIXML_VSCPRINTF( format, va );\r
         // Close out and re-start the va-args\r
         va_end( va );\r
+        TIXMLASSERT( len >= 0 );\r
         va_start( va, format );\r
         TIXMLASSERT( _buffer.Size() > 0 && _buffer[_buffer.Size() - 1] == 0 );\r
         char* p = _buffer.PushArr( len ) - 1;  // back up over the null terminator.\r
-#if defined(_MSC_VER) && (_MSC_VER >= 1400 )\r
-               #if defined(WINCE)\r
-               _vsnprintf( p, len+1, format, va );\r
-               #else\r
-               vsnprintf_s( p, len+1, _TRUNCATE, format, va );\r
-               #endif\r
-#else\r
-               vsnprintf( p, len+1, format, va );\r
-#endif\r
+               TIXML_VSNPRINTF( p, len+1, format, va );\r
     }\r
     va_end( va );\r
 }\r
@@ -2055,6 +2223,7 @@ void XMLPrinter::PrintString( const char* p, bool restricted )
     if ( _processEntities ) {\r
         const bool* flag = restricted ? _restrictedEntityFlag : _entityFlag;\r
         while ( *q ) {\r
+            TIXMLASSERT( p <= q );\r
             // Remember, char is sometimes signed. (How many times has that bitten me?)\r
             if ( *q > 0 && *q < ENTITY_RANGE ) {\r
                 // Check for entities. If one is found, flush\r
@@ -2062,24 +2231,35 @@ void XMLPrinter::PrintString( const char* p, bool restricted )
                 // entity, and keep looking.\r
                 if ( flag[(unsigned char)(*q)] ) {\r
                     while ( p < q ) {\r
-                        Print( "%c", *p );\r
-                        ++p;\r
+                        const size_t delta = q - p;\r
+                        // %.*s accepts type int as "precision"\r
+                        const int toPrint = ( INT_MAX < delta ) ? INT_MAX : (int)delta;\r
+                        Print( "%.*s", toPrint, p );\r
+                        p += toPrint;\r
                     }\r
+                    bool entityPatternPrinted = false;\r
                     for( int i=0; i<NUM_ENTITIES; ++i ) {\r
                         if ( entities[i].value == *q ) {\r
                             Print( "&%s;", entities[i].pattern );\r
+                            entityPatternPrinted = true;\r
                             break;\r
                         }\r
                     }\r
+                    if ( !entityPatternPrinted ) {\r
+                        // TIXMLASSERT( entityPatternPrinted ) causes gcc -Wunused-but-set-variable in release\r
+                        TIXMLASSERT( false );\r
+                    }\r
                     ++p;\r
                 }\r
             }\r
             ++q;\r
+            TIXMLASSERT( p <= q );\r
         }\r
     }\r
     // Flush the remaining string. This will be the entire\r
     // string if an entity wasn't found.\r
-    if ( !_processEntities || (q-p > 0) ) {\r
+    TIXMLASSERT( p <= q );\r
+    if ( !_processEntities || ( p < q ) ) {\r
         Print( "%s", p );\r
     }\r
 }\r
@@ -2141,6 +2321,14 @@ void XMLPrinter::PushAttribute( const char* name, unsigned v )
 }\r
 \r
 \r
+void XMLPrinter::PushAttribute(const char* name, int64_t v)\r
+{\r
+       char buf[BUF_SIZE];\r
+       XMLUtil::ToStr(v, buf, BUF_SIZE);\r
+       PushAttribute(name, buf);\r
+}\r
+\r
+\r
 void XMLPrinter::PushAttribute( const char* name, bool v )\r
 {\r
     char buf[BUF_SIZE];\r
@@ -2199,9 +2387,7 @@ void XMLPrinter::PushText( const char* text, bool cdata )
 \r
     SealElementIfJustOpened();\r
     if ( cdata ) {\r
-        Print( "<![CDATA[" );\r
-        Print( "%s", text );\r
-        Print( "]]>" );\r
+        Print( "<![CDATA[%s]]>", text );\r
     }\r
     else {\r
         PrintString( text, true );\r
@@ -2296,8 +2482,11 @@ bool XMLPrinter::VisitEnter( const XMLDocument& doc )
 \r
 bool XMLPrinter::VisitEnter( const XMLElement& element, const XMLAttribute* attribute )\r
 {\r
-       const XMLElement*       parentElem = element.Parent()->ToElement();\r
-       bool            compactMode = parentElem ? CompactMode(*parentElem) : _compactMode;\r
+    const XMLElement* parentElem = 0;\r
+    if ( element.Parent() ) {\r
+        parentElem = element.Parent()->ToElement();\r
+    }\r
+    const bool compactMode = parentElem ? CompactMode( *parentElem ) : _compactMode;\r
     OpenElement( element.Name(), compactMode );\r
     while ( attribute ) {\r
         PushAttribute( attribute->Name(), attribute->Value() );\r
index a6da2eceab1aba4a5d5a0bac61238e96b7f7927c..9dcc345a4921613718568ca91d3d3acea794aef0 100755 (executable)
@@ -30,15 +30,17 @@ distribution.
 #   include <stdio.h>\r
 #   include <stdlib.h>\r
 #   include <string.h>\r
-#   include <stdarg.h>\r
+#      if defined(__PS3__)\r
+#              include <stddef.h>\r
+#      endif\r
 #else\r
 #   include <cctype>\r
 #   include <climits>\r
 #   include <cstdio>\r
 #   include <cstdlib>\r
 #   include <cstring>\r
-#   include <cstdarg>\r
 #endif\r
+#include <stdint.h>\r
 \r
 /*\r
    TODO: intern strings instead of allocation.\r
@@ -78,7 +80,7 @@ distribution.
 #if defined(DEBUG)\r
 #   if defined(_MSC_VER)\r
 #       // "(void)0," is for suppressing C4127 warning in "assert(false)", "assert(true)" and the like\r
-#       define TIXMLASSERT( x )           if ( !((void)0,(x))) { __debugbreak(); } //if ( !(x)) WinDebugBreak()\r
+#       define TIXMLASSERT( x )           if ( !((void)0,(x))) { __debugbreak(); }\r
 #   elif defined (ANDROID_NDK)\r
 #       include <android/log.h>\r
 #       define TIXMLASSERT( x )           if ( !(x)) { __android_log_assert( "assert", "grinliz", "ASSERT in '%s' at %d.", __FILE__, __LINE__ ); }\r
@@ -86,45 +88,17 @@ distribution.
 #       include <assert.h>\r
 #       define TIXMLASSERT                assert\r
 #   endif\r
-#   else\r
-#       define TIXMLASSERT( x )           {}\r
-#endif\r
-\r
-\r
-#if defined(_MSC_VER) && (_MSC_VER >= 1400 ) && (!defined WINCE)\r
-// Microsoft visual studio, version 2005 and higher.\r
-/*int _snprintf_s(\r
-   char *buffer,\r
-   size_t sizeOfBuffer,\r
-   size_t count,\r
-   const char *format [,\r
-         argument] ...\r
-);*/\r
-inline int TIXML_SNPRINTF( char* buffer, size_t size, const char* format, ... )\r
-{\r
-    va_list va;\r
-    va_start( va, format );\r
-    int result = vsnprintf_s( buffer, size, _TRUNCATE, format, va );\r
-    va_end( va );\r
-    return result;\r
-}\r
-#define TIXML_SSCANF   sscanf_s\r
-#elif defined WINCE\r
-#define TIXML_SNPRINTF _snprintf\r
-#define TIXML_SSCANF   sscanf\r
 #else\r
-// GCC version 3 and higher\r
-//#warning( "Using sn* functions." )\r
-#define TIXML_SNPRINTF snprintf\r
-#define TIXML_SSCANF   sscanf\r
+#   define TIXMLASSERT( x )               {}\r
 #endif\r
 \r
+\r
 /* Versioning, past 1.0.14:\r
        http://semver.org/\r
 */\r
-static const int TIXML2_MAJOR_VERSION = 3;
-static const int TIXML2_MINOR_VERSION = 0;
-static const int TIXML2_PATCH_VERSION = 0;
+static const int TIXML2_MAJOR_VERSION = 4;\r
+static const int TIXML2_MINOR_VERSION = 0;\r
+static const int TIXML2_PATCH_VERSION = 0;\r
 \r
 namespace tinyxml2\r
 {\r
@@ -149,7 +123,7 @@ public:
     enum {\r
         NEEDS_ENTITY_PROCESSING                        = 0x01,\r
         NEEDS_NEWLINE_NORMALIZATION            = 0x02,\r
-        COLLAPSE_WHITESPACE                    = 0x04,\r
+        NEEDS_WHITESPACE_COLLAPSING     = 0x04,\r
 \r
         TEXT_ELEMENT                           = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION,\r
         TEXT_ELEMENT_LEAVE_ENTITIES            = NEEDS_NEWLINE_NORMALIZATION,\r
@@ -196,7 +170,6 @@ private:
         NEEDS_DELETE = 0x200\r
     };\r
 \r
-    // After parsing, if *_end != 0, it can be set to zero.\r
     int     _flags;\r
     char*   _start;\r
     char*   _end;\r
@@ -211,13 +184,13 @@ private:
        Has a small initial memory pool, so that low or no usage will not\r
        cause a call to new/delete\r
 */\r
-template <class T, int INIT>\r
+template <class T, int INITIAL_SIZE>\r
 class DynArray\r
 {\r
 public:\r
     DynArray() {\r
         _mem = _pool;\r
-        _allocated = INIT;\r
+        _allocated = INITIAL_SIZE;\r
         _size = 0;\r
     }\r
 \r
@@ -281,14 +254,17 @@ public:
     }\r
 \r
     int Capacity() const                               {\r
+        TIXMLASSERT( _allocated >= INITIAL_SIZE );\r
         return _allocated;\r
     }\r
 \r
     const T* Mem() const                               {\r
+        TIXMLASSERT( _mem );\r
         return _mem;\r
     }\r
 \r
     T* Mem()                                                   {\r
+        TIXMLASSERT( _mem );\r
         return _mem;\r
     }\r
 \r
@@ -312,7 +288,7 @@ private:
     }\r
 \r
     T*  _mem;\r
-    T   _pool[INIT];\r
+    T   _pool[INITIAL_SIZE];\r
     int _allocated;            // objects allocated\r
     int _size;                 // number objects in use\r
 };\r
@@ -513,7 +489,6 @@ public:
 // WARNING: must match XMLDocument::_errorNames[]\r
 enum XMLError {\r
     XML_SUCCESS = 0,\r
-    XML_NO_ERROR = 0,\r
     XML_NO_ATTRIBUTE,\r
     XML_WRONG_ATTRIBUTE_TYPE,\r
     XML_ERROR_FILE_NOT_FOUND,\r
@@ -584,19 +559,10 @@ public:
         if ( p == q ) {\r
             return true;\r
         }\r
-        int n = 0;\r
-        while( *p && *q && *p == *q && n<nChar ) {\r
-            ++p;\r
-            ++q;\r
-            ++n;\r
-        }\r
-        if ( (n == nChar) || ( *p == 0 && *q == 0 ) ) {\r
-            return true;\r
-        }\r
-        return false;\r
+        return strncmp( p, q, nChar ) == 0;\r
     }\r
     \r
-    inline static bool IsUTF8Continuation( const char p ) {\r
+    inline static bool IsUTF8Continuation( char p ) {\r
         return ( p & 0x80 ) != 0;\r
     }\r
 \r
@@ -612,6 +578,7 @@ public:
     static void ToStr( bool v, char* buffer, int bufferSize );\r
     static void ToStr( float v, char* buffer, int bufferSize );\r
     static void ToStr( double v, char* buffer, int bufferSize );\r
+       static void ToStr(int64_t v, char* buffer, int bufferSize);\r
 \r
     // converts strings to primitive types\r
     static bool        ToInt( const char* str, int* value );\r
@@ -619,6 +586,7 @@ public:
     static bool        ToBool( const char* str, bool* value );\r
     static bool        ToFloat( const char* str, float* value );\r
     static bool ToDouble( const char* str, double* value );\r
+       static bool ToInt64(const char* str, int64_t* value);\r
 };\r
 \r
 \r
@@ -655,10 +623,12 @@ public:
 \r
     /// Get the XMLDocument that owns this XMLNode.\r
     const XMLDocument* GetDocument() const     {\r
+        TIXMLASSERT( _document );\r
         return _document;\r
     }\r
     /// Get the XMLDocument that owns this XMLNode.\r
     XMLDocument* GetDocument()                         {\r
+        TIXMLASSERT( _document );\r
         return _document;\r
     }\r
 \r
@@ -708,7 +678,7 @@ public:
 \r
     /** The meaning of 'value' changes for the specific type.\r
        @verbatim\r
-       Document:       empty\r
+       Document:       empty (NULL is returned, not an empty string)\r
        Element:        name of the element\r
        Comment:        the comment text\r
        Unknown:        the tag contents\r
@@ -748,10 +718,10 @@ public:
     /** Get the first child element, or optionally the first child\r
         element with the specified name.\r
     */\r
-    const XMLElement* FirstChildElement( const char* value=0 ) const;\r
+    const XMLElement* FirstChildElement( const char* name = 0 ) const;\r
 \r
-    XMLElement* FirstChildElement( const char* value=0 )       {\r
-        return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->FirstChildElement( value ));\r
+    XMLElement* FirstChildElement( const char* name = 0 )      {\r
+        return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->FirstChildElement( name ));\r
     }\r
 \r
     /// Get the last child node, or null if none exists.\r
@@ -760,16 +730,16 @@ public:
     }\r
 \r
     XMLNode*           LastChild()                                                             {\r
-        return const_cast<XMLNode*>(const_cast<const XMLNode*>(this)->LastChild() );\r
+        return _lastChild;\r
     }\r
 \r
     /** Get the last child element or optionally the last child\r
         element with the specified name.\r
     */\r
-    const XMLElement* LastChildElement( const char* value=0 ) const;\r
+    const XMLElement* LastChildElement( const char* name = 0 ) const;\r
 \r
-    XMLElement* LastChildElement( const char* value=0 )        {\r
-        return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->LastChildElement(value) );\r
+    XMLElement* LastChildElement( const char* name = 0 )       {\r
+        return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->LastChildElement(name) );\r
     }\r
 \r
     /// Get the previous (left) sibling node of this node.\r
@@ -782,10 +752,10 @@ public:
     }\r
 \r
     /// Get the previous (left) sibling element of this node, with an optionally supplied name.\r
-    const XMLElement*  PreviousSiblingElement( const char* value=0 ) const ;\r
+    const XMLElement*  PreviousSiblingElement( const char* name = 0 ) const ;\r
 \r
-    XMLElement*        PreviousSiblingElement( const char* value=0 ) {\r
-        return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->PreviousSiblingElement( value ) );\r
+    XMLElement*        PreviousSiblingElement( const char* name = 0 ) {\r
+        return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->PreviousSiblingElement( name ) );\r
     }\r
 \r
     /// Get the next (right) sibling node of this node.\r
@@ -798,10 +768,10 @@ public:
     }\r
 \r
     /// Get the next (right) sibling element of this node, with an optionally supplied name.\r
-    const XMLElement*  NextSiblingElement( const char* value=0 ) const;\r
+    const XMLElement*  NextSiblingElement( const char* name = 0 ) const;\r
 \r
-    XMLElement*        NextSiblingElement( const char* value=0 )       {\r
-        return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->NextSiblingElement( value ) );\r
+    XMLElement*        NextSiblingElement( const char* name = 0 )      {\r
+        return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->NextSiblingElement( name ) );\r
     }\r
 \r
     /**\r
@@ -887,13 +857,26 @@ public:
     */\r
     virtual bool Accept( XMLVisitor* visitor ) const = 0;\r
 \r
-    // internal\r
-    virtual char* ParseDeep( char*, StrPair* );\r
+       /** \r
+               Set user data into the XMLNode. TinyXML-2 in \r
+               no way processes or interprets user data.\r
+               It is initially 0.\r
+       */\r
+       void SetUserData(void* userData)        { _userData = userData; }\r
+\r
+       /**\r
+               Get user data set into the XMLNode. TinyXML-2 in\r
+               no way processes or interprets user data.\r
+               It is initially 0.\r
+       */\r
+       void* GetUserData() const                       { return _userData; }\r
 \r
 protected:\r
     XMLNode( XMLDocument* );\r
     virtual ~XMLNode();\r
 \r
+    virtual char* ParseDeep( char*, StrPair* );\r
+\r
     XMLDocument*       _document;\r
     XMLNode*           _parent;\r
     mutable StrPair    _value;\r
@@ -904,6 +887,8 @@ protected:
     XMLNode*           _prev;\r
     XMLNode*           _next;\r
 \r
+       void*                   _userData;\r
+\r
 private:\r
     MemPool*           _memPool;\r
     void Unlink( XMLNode* child );\r
@@ -929,7 +914,6 @@ private:
 */\r
 class TINYXML2_LIB XMLText : public XMLNode\r
 {\r
-    friend class XMLBase;\r
     friend class XMLDocument;\r
 public:\r
     virtual bool Accept( XMLVisitor* visitor ) const;\r
@@ -950,7 +934,6 @@ public:
         return _isCData;\r
     }\r
 \r
-    char* ParseDeep( char*, StrPair* endTag );\r
     virtual XMLNode* ShallowClone( XMLDocument* document ) const;\r
     virtual bool ShallowEqual( const XMLNode* compare ) const;\r
 \r
@@ -958,6 +941,8 @@ protected:
     XMLText( XMLDocument* doc )        : XMLNode( doc ), _isCData( false )     {}\r
     virtual ~XMLText()                                                                                         {}\r
 \r
+    char* ParseDeep( char*, StrPair* endTag );\r
+\r
 private:\r
     bool _isCData;\r
 \r
@@ -980,7 +965,6 @@ public:
 \r
     virtual bool Accept( XMLVisitor* visitor ) const;\r
 \r
-    char* ParseDeep( char*, StrPair* endTag );\r
     virtual XMLNode* ShallowClone( XMLDocument* document ) const;\r
     virtual bool ShallowEqual( const XMLNode* compare ) const;\r
 \r
@@ -988,6 +972,8 @@ protected:
     XMLComment( XMLDocument* doc );\r
     virtual ~XMLComment();\r
 \r
+    char* ParseDeep( char*, StrPair* endTag );\r
+\r
 private:\r
     XMLComment( const XMLComment& );   // not supported\r
     XMLComment& operator=( const XMLComment& );        // not supported\r
@@ -1018,7 +1004,6 @@ public:
 \r
     virtual bool Accept( XMLVisitor* visitor ) const;\r
 \r
-    char* ParseDeep( char*, StrPair* endTag );\r
     virtual XMLNode* ShallowClone( XMLDocument* document ) const;\r
     virtual bool ShallowEqual( const XMLNode* compare ) const;\r
 \r
@@ -1026,6 +1011,8 @@ protected:
     XMLDeclaration( XMLDocument* doc );\r
     virtual ~XMLDeclaration();\r
 \r
+    char* ParseDeep( char*, StrPair* endTag );\r
+\r
 private:\r
     XMLDeclaration( const XMLDeclaration& );   // not supported\r
     XMLDeclaration& operator=( const XMLDeclaration& );        // not supported\r
@@ -1052,7 +1039,6 @@ public:
 \r
     virtual bool Accept( XMLVisitor* visitor ) const;\r
 \r
-    char* ParseDeep( char*, StrPair* endTag );\r
     virtual XMLNode* ShallowClone( XMLDocument* document ) const;\r
     virtual bool ShallowEqual( const XMLNode* compare ) const;\r
 \r
@@ -1060,6 +1046,8 @@ protected:
     XMLUnknown( XMLDocument* doc );\r
     virtual ~XMLUnknown();\r
 \r
+    char* ParseDeep( char*, StrPair* endTag );\r
+\r
 private:\r
     XMLUnknown( const XMLUnknown& );   // not supported\r
     XMLUnknown& operator=( const XMLUnknown& );        // not supported\r
@@ -1092,11 +1080,18 @@ public:
         If the value isn't an integer, 0 will be returned. There is no error checking;\r
        use QueryIntValue() if you need error checking.\r
     */\r
-    int                 IntValue() const                               {\r
-        int i=0;\r
-        QueryIntValue( &i );\r
-        return i;\r
-    }\r
+       int     IntValue() const {\r
+               int i = 0;\r
+               QueryIntValue(&i);\r
+               return i;\r
+       }\r
+\r
+       int64_t Int64Value() const {\r
+               int64_t i = 0;\r
+               QueryInt64Value(&i);\r
+               return i;\r
+       }\r
+\r
     /// Query as an unsigned integer. See IntValue()\r
     unsigned UnsignedValue() const                     {\r
         unsigned i=0;\r
@@ -1129,7 +1124,9 @@ public:
     XMLError QueryIntValue( int* value ) const;\r
     /// See QueryIntValue\r
     XMLError QueryUnsignedValue( unsigned int* value ) const;\r
-    /// See QueryIntValue\r
+       /// See QueryIntValue\r
+       XMLError QueryInt64Value(int64_t* value) const;\r
+       /// See QueryIntValue\r
     XMLError QueryBoolValue( bool* value ) const;\r
     /// See QueryIntValue\r
     XMLError QueryDoubleValue( double* value ) const;\r
@@ -1142,7 +1139,9 @@ public:
     void SetAttribute( int value );\r
     /// Set the attribute to value.\r
     void SetAttribute( unsigned value );\r
-    /// Set the attribute to value.\r
+       /// Set the attribute to value.\r
+       void SetAttribute(int64_t value);\r
+       /// Set the attribute to value.\r
     void SetAttribute( bool value );\r
     /// Set the attribute to value.\r
     void SetAttribute( double value );\r
@@ -1174,7 +1173,6 @@ private:
 */\r
 class TINYXML2_LIB XMLElement : public XMLNode\r
 {\r
-    friend class XMLBase;\r
     friend class XMLDocument;\r
 public:\r
     /// Get the name of an element (which is the Value() of the node.)\r
@@ -1229,26 +1227,35 @@ public:
         QueryIntAttribute( name, &i );\r
         return i;\r
     }\r
+\r
     /// See IntAttribute()\r
     unsigned UnsignedAttribute( const char* name ) const {\r
         unsigned i=0;\r
         QueryUnsignedAttribute( name, &i );\r
         return i;\r
     }\r
-    /// See IntAttribute()\r
-    bool        BoolAttribute( const char* name ) const        {\r
+\r
+       /// See IntAttribute()\r
+       int64_t Int64Attribute(const char* name) const {\r
+               int64_t i = 0;\r
+               QueryInt64Attribute(name, &i);\r
+               return i;\r
+       }\r
+\r
+       /// See IntAttribute()\r
+    bool BoolAttribute( const char* name ) const       {\r
         bool b=false;\r
         QueryBoolAttribute( name, &b );\r
         return b;\r
     }\r
     /// See IntAttribute()\r
-    double      DoubleAttribute( const char* name ) const      {\r
+    double DoubleAttribute( const char* name ) const   {\r
         double d=0;\r
         QueryDoubleAttribute( name, &d );\r
         return d;\r
     }\r
     /// See IntAttribute()\r
-    float       FloatAttribute( const char* name ) const       {\r
+    float FloatAttribute( const char* name ) const     {\r
         float f=0;\r
         QueryFloatAttribute( name, &f );\r
         return f;\r
@@ -1274,7 +1281,8 @@ public:
         }\r
         return a->QueryIntValue( value );\r
     }\r
-    /// See QueryIntAttribute()\r
+\r
+       /// See QueryIntAttribute()\r
     XMLError QueryUnsignedAttribute( const char* name, unsigned int* value ) const     {\r
         const XMLAttribute* a = FindAttribute( name );\r
         if ( !a ) {\r
@@ -1282,7 +1290,17 @@ public:
         }\r
         return a->QueryUnsignedValue( value );\r
     }\r
-    /// See QueryIntAttribute()\r
+\r
+       /// See QueryIntAttribute()\r
+       XMLError QueryInt64Attribute(const char* name, int64_t* value) const {\r
+               const XMLAttribute* a = FindAttribute(name);\r
+               if (!a) {\r
+                       return XML_NO_ATTRIBUTE;\r
+               }\r
+               return a->QueryInt64Value(value);\r
+       }\r
+\r
+       /// See QueryIntAttribute()\r
     XMLError QueryBoolAttribute( const char* name, bool* value ) const                         {\r
         const XMLAttribute* a = FindAttribute( name );\r
         if ( !a ) {\r
@@ -1333,6 +1351,10 @@ public:
                return QueryUnsignedAttribute( name, value );\r
        }\r
 \r
+       int QueryAttribute(const char* name, int64_t* value) const {\r
+               return QueryInt64Attribute(name, value);\r
+       }\r
+\r
        int QueryAttribute( const char* name, bool* value ) const {\r
                return QueryBoolAttribute( name, value );\r
        }\r
@@ -1360,7 +1382,14 @@ public:
         XMLAttribute* a = FindOrCreateAttribute( name );\r
         a->SetAttribute( value );\r
     }\r
-    /// Sets the named attribute to value.\r
+\r
+       /// Sets the named attribute to value.\r
+       void SetAttribute(const char* name, int64_t value) {\r
+               XMLAttribute* a = FindOrCreateAttribute(name);\r
+               a->SetAttribute(value);\r
+       }\r
+\r
+       /// Sets the named attribute to value.\r
     void SetAttribute( const char* name, bool value )                  {\r
         XMLAttribute* a = FindOrCreateAttribute( name );\r
         a->SetAttribute( value );\r
@@ -1453,15 +1482,17 @@ public:
        @endverbatim\r
     */\r
        void SetText( const char* inText );\r
-    /// Convenience method for setting text inside and element. See SetText() for important limitations.\r
+    /// Convenience method for setting text inside an element. See SetText() for important limitations.\r
     void SetText( int value );\r
-    /// Convenience method for setting text inside and element. See SetText() for important limitations.\r
+    /// Convenience method for setting text inside an element. See SetText() for important limitations.\r
     void SetText( unsigned value );  \r
-    /// Convenience method for setting text inside and element. See SetText() for important limitations.\r
+       /// Convenience method for setting text inside an element. See SetText() for important limitations.\r
+       void SetText(int64_t value);\r
+       /// Convenience method for setting text inside an element. See SetText() for important limitations.\r
     void SetText( bool value );  \r
-    /// Convenience method for setting text inside and element. See SetText() for important limitations.\r
+    /// Convenience method for setting text inside an element. See SetText() for important limitations.\r
     void SetText( double value );  \r
-    /// Convenience method for setting text inside and element. See SetText() for important limitations.\r
+    /// Convenience method for setting text inside an element. See SetText() for important limitations.\r
     void SetText( float value );  \r
 \r
     /**\r
@@ -1493,7 +1524,9 @@ public:
     XMLError QueryIntText( int* ival ) const;\r
     /// See QueryIntText()\r
     XMLError QueryUnsignedText( unsigned* uval ) const;\r
-    /// See QueryIntText()\r
+       /// See QueryIntText()\r
+       XMLError QueryInt64Text(int64_t* uval) const;\r
+       /// See QueryIntText()\r
     XMLError QueryBoolText( bool* bval ) const;\r
     /// See QueryIntText()\r
     XMLError QueryDoubleText( double* dval ) const;\r
@@ -1509,10 +1542,12 @@ public:
     int ClosingType() const {\r
         return _closingType;\r
     }\r
-    char* ParseDeep( char* p, StrPair* endTag );\r
     virtual XMLNode* ShallowClone( XMLDocument* document ) const;\r
     virtual bool ShallowEqual( const XMLNode* compare ) const;\r
 \r
+protected:\r
+    char* ParseDeep( char* p, StrPair* endTag );\r
+\r
 private:\r
     XMLElement( XMLDocument* doc );\r
     virtual ~XMLElement();\r
@@ -1556,9 +1591,11 @@ public:
     ~XMLDocument();\r
 \r
     virtual XMLDocument* ToDocument()                          {\r
+        TIXMLASSERT( this == _document );\r
         return this;\r
     }\r
     virtual const XMLDocument* ToDocument() const      {\r
+        TIXMLASSERT( this == _document );\r
         return this;\r
     }\r
 \r
@@ -1703,7 +1740,7 @@ public:
 \r
     /// Return true if there was an error parsing the document.\r
     bool Error() const {\r
-        return _errorID != XML_NO_ERROR;\r
+        return _errorID != XML_SUCCESS;\r
     }\r
     /// Return the errorID.\r
     XMLError  ErrorID() const {\r
@@ -1839,32 +1876,32 @@ public:
         return XMLHandle( _node ? _node->FirstChild() : 0 );\r
     }\r
     /// Get the first child element of this handle.\r
-    XMLHandle FirstChildElement( const char* value=0 )                                         {\r
-        return XMLHandle( _node ? _node->FirstChildElement( value ) : 0 );\r
+    XMLHandle FirstChildElement( const char* name = 0 )                                                {\r
+        return XMLHandle( _node ? _node->FirstChildElement( name ) : 0 );\r
     }\r
     /// Get the last child of this handle.\r
     XMLHandle LastChild()                                                                                                      {\r
         return XMLHandle( _node ? _node->LastChild() : 0 );\r
     }\r
     /// Get the last child element of this handle.\r
-    XMLHandle LastChildElement( const char* _value=0 )                                         {\r
-        return XMLHandle( _node ? _node->LastChildElement( _value ) : 0 );\r
+    XMLHandle LastChildElement( const char* name = 0 )                                         {\r
+        return XMLHandle( _node ? _node->LastChildElement( name ) : 0 );\r
     }\r
     /// Get the previous sibling of this handle.\r
     XMLHandle PreviousSibling()                                                                                                {\r
         return XMLHandle( _node ? _node->PreviousSibling() : 0 );\r
     }\r
     /// Get the previous sibling element of this handle.\r
-    XMLHandle PreviousSiblingElement( const char* _value=0 )                           {\r
-        return XMLHandle( _node ? _node->PreviousSiblingElement( _value ) : 0 );\r
+    XMLHandle PreviousSiblingElement( const char* name = 0 )                           {\r
+        return XMLHandle( _node ? _node->PreviousSiblingElement( name ) : 0 );\r
     }\r
     /// Get the next sibling of this handle.\r
     XMLHandle NextSibling()                                                                                                    {\r
         return XMLHandle( _node ? _node->NextSibling() : 0 );\r
     }\r
     /// Get the next sibling element of this handle.\r
-    XMLHandle NextSiblingElement( const char* _value=0 )                                       {\r
-        return XMLHandle( _node ? _node->NextSiblingElement( _value ) : 0 );\r
+    XMLHandle NextSiblingElement( const char* name = 0 )                                       {\r
+        return XMLHandle( _node ? _node->NextSiblingElement( name ) : 0 );\r
     }\r
 \r
     /// Safe cast to XMLNode. This can return null.\r
@@ -1918,26 +1955,26 @@ public:
     const XMLConstHandle FirstChild() const                                                                                    {\r
         return XMLConstHandle( _node ? _node->FirstChild() : 0 );\r
     }\r
-    const XMLConstHandle FirstChildElement( const char* value=0 ) const                                {\r
-        return XMLConstHandle( _node ? _node->FirstChildElement( value ) : 0 );\r
+    const XMLConstHandle FirstChildElement( const char* name = 0 ) const                               {\r
+        return XMLConstHandle( _node ? _node->FirstChildElement( name ) : 0 );\r
     }\r
     const XMLConstHandle LastChild()   const                                                                           {\r
         return XMLConstHandle( _node ? _node->LastChild() : 0 );\r
     }\r
-    const XMLConstHandle LastChildElement( const char* _value=0 ) const                                {\r
-        return XMLConstHandle( _node ? _node->LastChildElement( _value ) : 0 );\r
+    const XMLConstHandle LastChildElement( const char* name = 0 ) const                                {\r
+        return XMLConstHandle( _node ? _node->LastChildElement( name ) : 0 );\r
     }\r
     const XMLConstHandle PreviousSibling() const                                                                       {\r
         return XMLConstHandle( _node ? _node->PreviousSibling() : 0 );\r
     }\r
-    const XMLConstHandle PreviousSiblingElement( const char* _value=0 ) const          {\r
-        return XMLConstHandle( _node ? _node->PreviousSiblingElement( _value ) : 0 );\r
+    const XMLConstHandle PreviousSiblingElement( const char* name = 0 ) const          {\r
+        return XMLConstHandle( _node ? _node->PreviousSiblingElement( name ) : 0 );\r
     }\r
     const XMLConstHandle NextSibling() const                                                                           {\r
         return XMLConstHandle( _node ? _node->NextSibling() : 0 );\r
     }\r
-    const XMLConstHandle NextSiblingElement( const char* _value=0 ) const                      {\r
-        return XMLConstHandle( _node ? _node->NextSiblingElement( _value ) : 0 );\r
+    const XMLConstHandle NextSiblingElement( const char* name = 0 ) const                      {\r
+        return XMLConstHandle( _node ? _node->NextSiblingElement( name ) : 0 );\r
     }\r
 \r
 \r
@@ -2026,7 +2063,8 @@ public:
     void PushAttribute( const char* name, const char* value );\r
     void PushAttribute( const char* name, int value );\r
     void PushAttribute( const char* name, unsigned value );\r
-    void PushAttribute( const char* name, bool value );\r
+       void PushAttribute(const char* name, int64_t value);\r
+       void PushAttribute( const char* name, bool value );\r
     void PushAttribute( const char* name, double value );\r
     /// If streaming, close the Element.\r
     virtual void CloseElement( bool compactMode=false );\r
@@ -2037,7 +2075,9 @@ public:
     void PushText( int value );\r
     /// Add a text node from an unsigned.\r
     void PushText( unsigned value );\r
-    /// Add a text node from a bool.\r
+       /// Add a text node from an unsigned.\r
+       void PushText(int64_t value);\r
+       /// Add a text node from a bool.\r
     void PushText( bool value );\r
     /// Add a text node from a float.\r
     void PushText( float value );\r
index e61bb1baf1b1dc9e64b4c530af525aede99a2ef5..d46eb75d66304708ab237b14f128a3c045cbe932 100644 (file)
@@ -1,5 +1,5 @@
 ï»¿<?xml version="1.0" encoding="utf-8"?>\r
-<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">\r
+<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">\r
   <ItemGroup Label="ProjectConfigurations">\r
     <ProjectConfiguration Include="Debug-Dll|Win32">\r
       <Configuration>Debug-Dll</Configuration>\r
   <PropertyGroup Label="Globals">\r
     <ProjectGuid>{E8FB2712-8666-4662-A5B8-2B5B0FB1A260}</ProjectGuid>\r
     <RootNamespace>test</RootNamespace>\r
+    <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>\r
   </PropertyGroup>\r
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />\r
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug-Lib|Win32'" Label="Configuration">\r
     <ConfigurationType>Application</ConfigurationType>\r
     <UseDebugLibraries>true</UseDebugLibraries>\r
     <CharacterSet>Unicode</CharacterSet>\r
+    <PlatformToolset>v140</PlatformToolset>\r
   </PropertyGroup>\r
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug-Lib|x64'" Label="Configuration">\r
     <ConfigurationType>Application</ConfigurationType>\r
     <UseDebugLibraries>true</UseDebugLibraries>\r
     <CharacterSet>Unicode</CharacterSet>\r
+    <PlatformToolset>v140</PlatformToolset>\r
   </PropertyGroup>\r
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug-Dll|Win32'" Label="Configuration">\r
     <ConfigurationType>Application</ConfigurationType>\r
     <UseDebugLibraries>true</UseDebugLibraries>\r
     <CharacterSet>Unicode</CharacterSet>\r
+    <PlatformToolset>v140</PlatformToolset>\r
   </PropertyGroup>\r
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug-Dll|x64'" Label="Configuration">\r
     <ConfigurationType>Application</ConfigurationType>\r
     <UseDebugLibraries>true</UseDebugLibraries>\r
     <CharacterSet>Unicode</CharacterSet>\r
+    <PlatformToolset>v140</PlatformToolset>\r
   </PropertyGroup>\r
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release-Lib|Win32'" Label="Configuration">\r
     <ConfigurationType>Application</ConfigurationType>\r
     <UseDebugLibraries>false</UseDebugLibraries>\r
     <WholeProgramOptimization>true</WholeProgramOptimization>\r
     <CharacterSet>Unicode</CharacterSet>\r
+    <PlatformToolset>v140</PlatformToolset>\r
   </PropertyGroup>\r
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release-Lib|x64'" Label="Configuration">\r
     <ConfigurationType>Application</ConfigurationType>\r
     <UseDebugLibraries>false</UseDebugLibraries>\r
     <WholeProgramOptimization>true</WholeProgramOptimization>\r
     <CharacterSet>Unicode</CharacterSet>\r
+    <PlatformToolset>v140</PlatformToolset>\r
   </PropertyGroup>\r
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release-Dll|Win32'" Label="Configuration">\r
     <ConfigurationType>Application</ConfigurationType>\r
     <UseDebugLibraries>false</UseDebugLibraries>\r
     <WholeProgramOptimization>true</WholeProgramOptimization>\r
     <CharacterSet>Unicode</CharacterSet>\r
+    <PlatformToolset>v140</PlatformToolset>\r
   </PropertyGroup>\r
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release-Dll|x64'" Label="Configuration">\r
     <ConfigurationType>Application</ConfigurationType>\r
     <UseDebugLibraries>false</UseDebugLibraries>\r
     <WholeProgramOptimization>true</WholeProgramOptimization>\r
     <CharacterSet>Unicode</CharacterSet>\r
+    <PlatformToolset>v140</PlatformToolset>\r
   </PropertyGroup>\r
   <PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">\r
     <CharacterSet>Unicode</CharacterSet>\r
     <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />\r
   </ImportGroup>\r
   <PropertyGroup Label="UserMacros" />\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug-Dll|Win32'" />\r
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug-Dll|Win32'">\r
-    <OutDir>$(SolutionDir)bin\$(Platform)-$(Configuration)\</OutDir>\r
-  </PropertyGroup>\r
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug-Dll|Win32'">\r
-    <IntDir>$(SolutionDir)temp\$(Platform)-$(Configuration)\</IntDir>\r
+    <IntDir>$(SolutionDir)$(Configuration)\</IntDir>\r
+    <OutDir>$(SolutionDir)$(Configuration)\</OutDir>\r
   </PropertyGroup>\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug-Lib|Win32'" />\r
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug-Lib|Win32'">\r
-    <OutDir>$(SolutionDir)bin\$(Platform)-$(Configuration)\</OutDir>\r
-  </PropertyGroup>\r
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug-Lib|Win32'">\r
-    <IntDir>$(SolutionDir)temp\$(Platform)-$(Configuration)\</IntDir>\r
+    <IntDir>$(SolutionDir)$(Configuration)\</IntDir>\r
+    <OutDir>$(SolutionDir)$(Configuration)\</OutDir>\r
   </PropertyGroup>\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release-Dll|Win32'" />\r
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release-Dll|Win32'">\r
-    <OutDir>$(SolutionDir)bin\$(Platform)-$(Configuration)\</OutDir>\r
-  </PropertyGroup>\r
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release-Dll|Win32'">\r
-    <IntDir>$(SolutionDir)temp\$(Platform)-$(Configuration)\</IntDir>\r
+    <IntDir>$(SolutionDir)$(Configuration)\</IntDir>\r
+    <OutDir>$(SolutionDir)$(Configuration)\</OutDir>\r
   </PropertyGroup>\r
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release-Lib|Win32'" />\r
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release-Lib|Win32'">\r
-    <OutDir>$(SolutionDir)bin\$(Platform)-$(Configuration)\</OutDir>\r
-  </PropertyGroup>\r
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release-Lib|Win32'">\r
-    <IntDir>$(SolutionDir)temp\$(Platform)-$(Configuration)\</IntDir>\r
+    <IntDir>$(SolutionDir)$(Configuration)\</IntDir>\r
+    <OutDir>$(SolutionDir)$(Configuration)\</OutDir>\r
   </PropertyGroup>\r
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug-Dll|x64'">\r
     <OutDir>$(SolutionDir)bin\$(Platform)-$(Configuration)\</OutDir>\r
index 715597617f719b44ff00624017dd8f3f24f80c3a..4c46354ab9256e1a50730f6122150d46a3789667 100755 (executable)
@@ -1,5 +1,5 @@
 ï»¿<?xml version="1.0" encoding="utf-8"?>\r
-<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">\r
+<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">\r
   <ItemGroup Label="ProjectConfigurations">\r
     <ProjectConfiguration Include="Debug-Dll|Win32">\r
       <Configuration>Debug-Dll</Configuration>\r
     <ProjectGuid>{D1C528B6-AA02-4D29-9D61-DC08E317A70D}</ProjectGuid>\r
     <Keyword>Win32Proj</Keyword>\r
     <RootNamespace>tinyxml2</RootNamespace>\r
+    <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>\r
   </PropertyGroup>\r
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />\r
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug-Lib|Win32'" Label="Configuration">\r
     <ConfigurationType>StaticLibrary</ConfigurationType>\r
     <UseDebugLibraries>true</UseDebugLibraries>\r
     <CharacterSet>Unicode</CharacterSet>\r
+    <PlatformToolset>v140</PlatformToolset>\r
   </PropertyGroup>\r
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug-Dll|Win32'" Label="Configuration">\r
     <ConfigurationType>DynamicLibrary</ConfigurationType>\r
     <UseDebugLibraries>true</UseDebugLibraries>\r
     <CharacterSet>Unicode</CharacterSet>\r
+    <PlatformToolset>v140</PlatformToolset>\r
   </PropertyGroup>\r
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug-Lib|x64'" Label="Configuration">\r
     <ConfigurationType>StaticLibrary</ConfigurationType>\r
     <UseDebugLibraries>true</UseDebugLibraries>\r
     <CharacterSet>Unicode</CharacterSet>\r
+    <PlatformToolset>v140</PlatformToolset>\r
   </PropertyGroup>\r
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug-Dll|x64'" Label="Configuration">\r
     <ConfigurationType>DynamicLibrary</ConfigurationType>\r
     <UseDebugLibraries>true</UseDebugLibraries>\r
     <CharacterSet>Unicode</CharacterSet>\r
+    <PlatformToolset>v140</PlatformToolset>\r
   </PropertyGroup>\r
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release-Lib|Win32'" Label="Configuration">\r
     <ConfigurationType>StaticLibrary</ConfigurationType>\r
     <UseDebugLibraries>false</UseDebugLibraries>\r
     <WholeProgramOptimization>true</WholeProgramOptimization>\r
     <CharacterSet>Unicode</CharacterSet>\r
+    <PlatformToolset>v140</PlatformToolset>\r
   </PropertyGroup>\r
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release-Dll|Win32'" Label="Configuration">\r
     <ConfigurationType>DynamicLibrary</ConfigurationType>\r
     <UseDebugLibraries>false</UseDebugLibraries>\r
     <WholeProgramOptimization>true</WholeProgramOptimization>\r
     <CharacterSet>Unicode</CharacterSet>\r
+    <PlatformToolset>v140</PlatformToolset>\r
   </PropertyGroup>\r
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release-Lib|x64'" Label="Configuration">\r
     <ConfigurationType>StaticLibrary</ConfigurationType>\r
     <UseDebugLibraries>false</UseDebugLibraries>\r
     <WholeProgramOptimization>true</WholeProgramOptimization>\r
     <CharacterSet>Unicode</CharacterSet>\r
+    <PlatformToolset>v140</PlatformToolset>\r
   </PropertyGroup>\r
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release-Dll|x64'" Label="Configuration">\r
     <ConfigurationType>DynamicLibrary</ConfigurationType>\r
     <UseDebugLibraries>false</UseDebugLibraries>\r
     <WholeProgramOptimization>true</WholeProgramOptimization>\r
     <CharacterSet>Unicode</CharacterSet>\r
+    <PlatformToolset>v140</PlatformToolset>\r
   </PropertyGroup>\r
   <PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">\r
     <ConfigurationType>StaticLibrary</ConfigurationType>\r
   <PropertyGroup Label="UserMacros" />\r
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug-Lib|Win32'">\r
     <LinkIncremental>true</LinkIncremental>\r
-    <OutDir>$(SolutionDir)bin\$(Platform)-$(Configuration)\</OutDir>\r
-    <IntDir>$(SolutionDir)temp\$(Platform)-$(Configuration)\</IntDir>\r
   </PropertyGroup>\r
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug-Dll|Win32'">\r
     <LinkIncremental>true</LinkIncremental>\r
-    <OutDir>$(SolutionDir)bin\$(Platform)-$(Configuration)\</OutDir>\r
-    <IntDir>$(SolutionDir)temp\$(Platform)-$(Configuration)\</IntDir>\r
   </PropertyGroup>\r
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug-Lib|x64'">\r
     <LinkIncremental>true</LinkIncremental>\r
   </PropertyGroup>\r
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release-Lib|Win32'">\r
     <LinkIncremental>false</LinkIncremental>\r
-    <OutDir>$(SolutionDir)bin\$(Platform)-$(Configuration)\</OutDir>\r
-    <IntDir>$(SolutionDir)temp\$(Platform)-$(Configuration)\</IntDir>\r
   </PropertyGroup>\r
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release-Dll|Win32'">\r
     <LinkIncremental>false</LinkIncremental>\r
-    <OutDir>$(SolutionDir)bin\$(Platform)-$(Configuration)\</OutDir>\r
-    <IntDir>$(SolutionDir)temp\$(Platform)-$(Configuration)\</IntDir>\r
   </PropertyGroup>\r
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release-Lib|x64'">\r
     <LinkIncremental>false</LinkIncremental>\r
index 243628cc24d9a53d173c9ceba52c2efc6b6e7e72..3fdc0bd1955c19e9ec6d8e7be93acf02a0d07d38 100644 (file)
@@ -30,7 +30,13 @@ int gFail = 0;
 \r
 bool XMLTest (const char* testString, const char* expected, const char* found, bool echo=true, bool extraNL=false )\r
 {\r
-       bool pass = !strcmp( expected, found );\r
+       bool pass;\r
+       if ( !expected && !found )\r
+               pass = true;\r
+       else if ( !expected || !found )\r
+               pass = false;\r
+       else \r
+               pass = !strcmp( expected, found );\r
        if ( pass )\r
                printf ("[pass]");\r
        else\r
@@ -410,6 +416,7 @@ int main( int argc, const char ** argv )
                }\r
                element->InsertEndChild( sub[2] );\r
                XMLNode* comment = element->InsertFirstChild( doc->NewComment( "comment" ) );\r
+               comment->SetUserData((void*)2);\r
                element->InsertAfterChild( comment, sub[0] );\r
                element->InsertAfterChild( sub[0], sub[1] );\r
                sub[2]->InsertFirstChild( doc->NewText( "& Text!" ));\r
@@ -419,6 +426,7 @@ int main( int argc, const char ** argv )
                XMLTest( "Programmatic DOM", 2, doc->FirstChildElement()->LastChildElement( "sub" )->IntAttribute( "attrib" ) );\r
                XMLTest( "Programmatic DOM", "& Text!",\r
                                 doc->FirstChildElement()->LastChildElement( "sub" )->FirstChild()->ToText()->Value() );\r
+               XMLTest("User data", 2, (int)comment->GetUserData());\r
 \r
                // And now deletion:\r
                element->DeleteChild( sub[2] );\r
@@ -507,13 +515,13 @@ int main( int argc, const char ** argv )
                double dVal;\r
 \r
                result = ele->QueryDoubleAttribute( "attr0", &dVal );\r
-               XMLTest( "Query attribute: int as double", result, (int)XML_NO_ERROR );\r
+               XMLTest( "Query attribute: int as double", result, (int)XML_SUCCESS);\r
                XMLTest( "Query attribute: int as double", (int)dVal, 1 );\r
                result = ele->QueryDoubleAttribute( "attr1", &dVal );\r
-               XMLTest( "Query attribute: double as double", result, (int)XML_NO_ERROR );\r
+               XMLTest( "Query attribute: double as double", result, (int)XML_SUCCESS);\r
                XMLTest( "Query attribute: double as double", (int)dVal, 2 );\r
                result = ele->QueryIntAttribute( "attr1", &iVal );\r
-               XMLTest( "Query attribute: double as int", result, (int)XML_NO_ERROR );\r
+               XMLTest( "Query attribute: double as int", result, (int)XML_SUCCESS);\r
                XMLTest( "Query attribute: double as int", iVal, 2 );\r
                result = ele->QueryIntAttribute( "attr2", &iVal );\r
                XMLTest( "Query attribute: not a number", result, (int)XML_WRONG_ATTRIBUTE_TYPE );\r
@@ -680,6 +688,107 @@ int main( int argc, const char ** argv )
                XMLTest( "SetText types", "1.5", element->GetText() );\r
        }\r
 \r
+       // ---------- Attributes ---------\r
+       {\r
+               static const int64_t BIG = -123456789012345678;\r
+               XMLDocument doc;\r
+               XMLElement* element = doc.NewElement("element");\r
+               doc.InsertFirstChild(element);\r
+\r
+               {\r
+                       element->SetAttribute("attrib", int(-100));\r
+                       int v = 0;\r
+                       element->QueryIntAttribute("attrib", &v);\r
+                       XMLTest("Attribute: int", -100, v, true);\r
+                       element->QueryAttribute("attrib", &v);\r
+                       XMLTest("Attribute: int", -100, v, true);\r
+               }\r
+               {\r
+                       element->SetAttribute("attrib", unsigned(100));\r
+                       unsigned v = 0;\r
+                       element->QueryUnsignedAttribute("attrib", &v);\r
+                       XMLTest("Attribute: unsigned", unsigned(100), v, true);\r
+                       element->QueryAttribute("attrib", &v);\r
+                       XMLTest("Attribute: unsigned", unsigned(100), v, true);\r
+               }\r
+               {\r
+                       element->SetAttribute("attrib", BIG);\r
+                       int64_t v = 0;\r
+                       element->QueryInt64Attribute("attrib", &v);\r
+                       XMLTest("Attribute: int64_t", BIG, v, true);\r
+                       element->QueryAttribute("attrib", &v);\r
+                       XMLTest("Attribute: int64_t", BIG, v, true);\r
+               }\r
+               {\r
+                       element->SetAttribute("attrib", true);\r
+                       bool v = false;\r
+                       element->QueryBoolAttribute("attrib", &v);\r
+                       XMLTest("Attribute: bool", true, v, true);\r
+                       element->QueryAttribute("attrib", &v);\r
+                       XMLTest("Attribute: bool", true, v, true);\r
+               }\r
+               {\r
+                       element->SetAttribute("attrib", 100.0);\r
+                       double v = 0;\r
+                       element->QueryDoubleAttribute("attrib", &v);\r
+                       XMLTest("Attribute: double", 100.0, v, true);\r
+                       element->QueryAttribute("attrib", &v);\r
+                       XMLTest("Attribute: double", 100.0, v, true);\r
+               }\r
+               {\r
+                       element->SetAttribute("attrib", 100.0f);\r
+                       float v = 0;\r
+                       element->QueryFloatAttribute("attrib", &v);\r
+                       XMLTest("Attribute: float", 100.0f, v, true);\r
+                       element->QueryAttribute("attrib", &v);\r
+                       XMLTest("Attribute: float", 100.0f, v, true);\r
+               }\r
+               {\r
+                       element->SetText(BIG);\r
+                       int64_t v = 0;\r
+                       element->QueryInt64Text(&v);\r
+                       XMLTest("Element: int64_t", BIG, v, true);\r
+               }\r
+       }\r
+\r
+       // ---------- XMLPrinter stream mode ------\r
+       {\r
+               {\r
+                       FILE* printerfp = fopen("resources/printer.xml", "w");\r
+                       XMLPrinter printer(printerfp);\r
+                       printer.OpenElement("foo");\r
+                       printer.PushAttribute("attrib-text", "text");\r
+                       printer.PushAttribute("attrib-int", int(1));\r
+                       printer.PushAttribute("attrib-unsigned", unsigned(2));\r
+                       printer.PushAttribute("attrib-int64", int64_t(3));\r
+                       printer.PushAttribute("attrib-bool", true);\r
+                       printer.PushAttribute("attrib-double", 4.0);\r
+                       printer.CloseElement();\r
+                       fclose(printerfp);\r
+               }\r
+               {\r
+                       XMLDocument doc;\r
+                       doc.LoadFile("resources/printer.xml");\r
+                       XMLTest("XMLPrinter Stream mode: load", doc.ErrorID(), XML_SUCCESS, true);\r
+\r
+                       const XMLDocument& cdoc = doc;\r
+\r
+                       const XMLAttribute* attrib = cdoc.FirstChildElement("foo")->FindAttribute("attrib-text");\r
+                       XMLTest("attrib-text", "text", attrib->Value(), true);\r
+                       attrib = cdoc.FirstChildElement("foo")->FindAttribute("attrib-int");\r
+                       XMLTest("attrib-int", int(1), attrib->IntValue(), true);\r
+                       attrib = cdoc.FirstChildElement("foo")->FindAttribute("attrib-unsigned");\r
+                       XMLTest("attrib-unsigned", unsigned(2), attrib->UnsignedValue(), true);\r
+                       attrib = cdoc.FirstChildElement("foo")->FindAttribute("attrib-int64");\r
+                       XMLTest("attrib-int64", int64_t(3), attrib->Int64Value(), true);\r
+                       attrib = cdoc.FirstChildElement("foo")->FindAttribute("attrib-bool");\r
+                       XMLTest("attrib-bool", true, attrib->BoolValue(), true);\r
+                       attrib = cdoc.FirstChildElement("foo")->FindAttribute("attrib-double");\r
+                       XMLTest("attrib-double", 4.0, attrib->DoubleValue(), true);\r
+               }\r
+\r
+       }\r
+\r
 \r
        // ---------- CDATA ---------------\r
        {\r
@@ -997,7 +1106,7 @@ int main( int argc, const char ** argv )
        {\r
                // This shouldn't crash.\r
                XMLDocument doc;\r
-               if(XML_NO_ERROR != doc.LoadFile( "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" ))\r
+               if(XML_SUCCESS != doc.LoadFile( "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" ))\r
                {\r
                        doc.PrintError();\r
                }\r
@@ -1167,6 +1276,9 @@ int main( int argc, const char ** argv )
 \r
     {\r
         XMLDocument doc;\r
+        XMLTest( "Document is initially empty", doc.NoChildren(), true );\r
+        doc.Clear();\r
+        XMLTest( "Empty is empty after Clear()", doc.NoChildren(), true );\r
         doc.LoadFile( "resources/dream.xml" );\r
         XMLTest( "Document has something to Clear()", doc.NoChildren(), false );\r
         doc.Clear();\r
@@ -1247,7 +1359,7 @@ int main( int argc, const char ** argv )
         static const char* xml_bom_preservation  = "\xef\xbb\xbf<element/>\n";\r
         {\r
                        XMLDocument doc;\r
-                       XMLTest( "BOM preservation (parse)", XML_NO_ERROR, doc.Parse( xml_bom_preservation ), false );\r
+                       XMLTest( "BOM preservation (parse)", XML_SUCCESS, doc.Parse( xml_bom_preservation ), false );\r
             XMLPrinter printer;\r
             doc.Print( &printer );\r
 \r
@@ -1425,41 +1537,112 @@ int main( int argc, const char ** argv )
                XMLPrinter printer;\r
                doc.Print( &printer );\r
        }\r
+       {\r
+               // Issue 299. Can print elements that are not linked in. \r
+               // Will crash if issue not fixed.\r
+               XMLDocument doc;\r
+               XMLElement* newElement = doc.NewElement( "printme" );\r
+               XMLPrinter printer;\r
+               newElement->Accept( &printer );\r
+               // Delete the node to avoid possible memory leak report in debug output\r
+               doc.DeleteNode( newElement );\r
+       }\r
+       {\r
+               // Issue 302. Clear errors from LoadFile/SaveFile\r
+               XMLDocument doc;\r
+               XMLTest( "Issue 302. Should be no error initially", "XML_SUCCESS", doc.ErrorName() );\r
+               doc.SaveFile( "./no/such/path/pretty.xml" );\r
+               XMLTest( "Issue 302. Fail to save", "XML_ERROR_FILE_COULD_NOT_BE_OPENED", doc.ErrorName() );\r
+               doc.SaveFile( "./resources/out/compact.xml", true );\r
+               XMLTest( "Issue 302. Subsequent success in saving", "XML_SUCCESS", doc.ErrorName() );\r
+       }\r
+\r
+       {\r
+               // If a document fails to load then subsequent\r
+               // successful loads should clear the error\r
+               XMLDocument doc;\r
+               XMLTest( "Should be no error initially", false, doc.Error() );\r
+               doc.LoadFile( "resources/no-such-file.xml" );\r
+               XMLTest( "No such file - should fail", true, doc.Error() );\r
+\r
+               doc.LoadFile( "resources/dream.xml" );\r
+               XMLTest( "Error should be cleared", false, doc.Error() );\r
+       }\r
+\r
+       {\r
+               // Check that declarations are parsed only as the FirstChild\r
+           const char* xml0 = "<?xml version=\"1.0\" ?>"\r
+                              "   <!-- xml version=\"1.1\" -->"\r
+                              "<first />";\r
+           const char* xml1 = "<?xml version=\"1.0\" ?>"\r
+                              "   <?xml version=\"1.1\" ?>"\r
+                              "<first />";\r
+           const char* xml2 = "<first />"\r
+                              "<?xml version=\"1.0\" ?>";\r
+           XMLDocument doc;\r
+           doc.Parse(xml0);\r
+           XMLTest("Test that the code changes do not affect normal parsing", doc.Error(), false);\r
+           doc.Parse(xml1);\r
+           XMLTest("Test that the second declaration throws an error", doc.ErrorID(), XML_ERROR_PARSING_DECLARATION);\r
+           doc.Parse(xml2);\r
+           XMLTest("Test that declaration after a child throws an error", doc.ErrorID(), XML_ERROR_PARSING_DECLARATION);\r
+       }\r
+\r
+    {\r
+           // No matter - before or after successfully parsing a text -\r
+           // calling XMLDocument::Value() causes an assert in debug.\r
+           const char* validXml = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>"\r
+                                  "<first />"\r
+                                  "<second />";\r
+           XMLDocument* doc = new XMLDocument();\r
+           XMLTest( "XMLDocument::Value() returns null?", NULL, doc->Value() );\r
+           doc->Parse( validXml );\r
+           XMLTest( "XMLDocument::Value() returns null?", NULL, doc->Value() );\r
+           delete doc;\r
+    }\r
+\r
+       {\r
+               XMLDocument doc;\r
+               for( int i = 0; i < XML_ERROR_COUNT; i++ ) {\r
+                       doc.SetError( (XMLError)i, 0, 0 );\r
+                       doc.ErrorName();\r
+               }\r
+       }\r
 \r
-       // ----------- Performance tracking --------------\r
+    // ----------- Performance tracking --------------\r
        {\r
 #if defined( _MSC_VER )\r
                __int64 start, end, freq;\r
-               QueryPerformanceFrequency( (LARGE_INTEGER*) &freq );\r
+               QueryPerformanceFrequency((LARGE_INTEGER*)&freq);\r
 #endif\r
 \r
-               FILE* fp  = fopen( "resources/dream.xml", "r" );\r
-               fseek( fp, 0, SEEK_END );\r
-               long size = ftell( fp );\r
-               fseek( fp, 0, SEEK_SET );\r
+               FILE* perfFP = fopen("resources/dream.xml", "r");\r
+               fseek(perfFP, 0, SEEK_END);\r
+               long size = ftell(fp);\r
+               fseek(perfFP, 0, SEEK_SET);\r
 \r
-               char* mem = new char[size+1];\r
-               fread( mem, size, 1, fp );\r
-               fclose( fp );\r
+               char* mem = new char[size + 1];\r
+               fread(mem, size, 1, perfFP);\r
+               fclose(perfFP);\r
                mem[size] = 0;\r
 \r
 #if defined( _MSC_VER )\r
-               QueryPerformanceCounter( (LARGE_INTEGER*) &start );\r
+               QueryPerformanceCounter((LARGE_INTEGER*)&start);\r
 #else\r
                clock_t cstart = clock();\r
 #endif\r
                static const int COUNT = 10;\r
-               for( int i=0; i<COUNT; ++i ) {\r
+               for (int i = 0; i < COUNT; ++i) {\r
                        XMLDocument doc;\r
-                       doc.Parse( mem );\r
+                       doc.Parse(mem);\r
                }\r
 #if defined( _MSC_VER )\r
-               QueryPerformanceCounter( (LARGE_INTEGER*) &end );\r
+               QueryPerformanceCounter((LARGE_INTEGER*)&end);\r
 #else\r
                clock_t cend = clock();\r
 #endif\r
 \r
-               delete [] mem;\r
+               delete[] mem;\r
 \r
                static const char* note =\r
 #ifdef DEBUG\r
@@ -1469,9 +1652,9 @@ int main( int argc, const char ** argv )
 #endif\r
 \r
 #if defined( _MSC_VER )\r
-               printf( "\nParsing %s of dream.xml: %.3f milli-seconds\n", note, 1000.0 * (double)(end-start) / ( (double)freq * (double)COUNT) );\r
+               printf("\nParsing %s of dream.xml: %.3f milli-seconds\n", note, 1000.0 * (double)(end - start) / ((double)freq * (double)COUNT));\r
 #else\r
-               printf( "\nParsing %s of dream.xml: %.3f milli-seconds\n", note, (double)(cend - cstart)/(double)COUNT );\r
+               printf("\nParsing %s of dream.xml: %.3f milli-seconds\n", note, (double)(cend - cstart) / (double)COUNT);\r
 #endif\r
        }\r
 \r