*.opensdf
*.user
*.depend
-*.layout
\ No newline at end of file
+*.layout
+*.o
--- /dev/null
+language: cpp
+
+os:
+ - linux
+ - osx
+
+compiler:
+ - g++
+ - clang
+
+before_script: cmake .
+
+script:
+ - make -j3
+ - ./xmltest
+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
################################\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
# 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
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
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
-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
+
--- /dev/null
+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
--- /dev/null
+# Biicode configuration file
+
+[paths]
+ /
+
+[dependencies]
+ xmltest.cpp + resources/*.xml
\ No newline at end of file
--- /dev/null
+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
protected:
virtual void CloseElement () {
if (_elementJustOpened && !isVoidElement (_stack.PeekTop())) {
- SealElement();
+ SealElementIfJustOpened();
}
XMLPrinter::CloseElement();
}
# 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
-TinyXML-2
+TinyXML-2 [](https://travis-ci.org/leethomason/tinyxml2) [](https://ci.appveyor.com/project/leethomason/tinyxml2)
=========

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 " " or " " are both to the non-breaking space characher.
+The syntax ` ` or ` ` 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.
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.
#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
\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
}\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
*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
}\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
*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
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
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
}\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
return false;\r
}\r
\r
+\r
bool XMLUtil::ToDouble( const char* str, double* value )\r
{\r
if ( TIXML_SSCANF( str, "%lf", value ) == 1 ) {\r
}\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
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
_parent( 0 ),\r
_firstChild( 0 ), _lastChild( 0 ),\r
_prev( 0 ), _next( 0 ),\r
+ _userData( 0 ),\r
_memPool( 0 )\r
{\r
}\r
\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
void XMLNode::DeleteChildren()\r
{\r
while( _firstChild ) {\r
+ TIXMLASSERT( _lastChild );\r
TIXMLASSERT( _firstChild->_document == _document );\r
XMLNode* node = _firstChild;\r
Unlink( node );\r
{\r
TIXMLASSERT( child );\r
TIXMLASSERT( child->_document == _document );\r
+ TIXMLASSERT( child->_parent == this );\r
if ( child == _firstChild ) {\r
_firstChild = _firstChild->_next;\r
}\r
TIXMLASSERT( node );\r
TIXMLASSERT( node->_document == _document );\r
TIXMLASSERT( node->_parent == this );\r
+ Unlink( node );\r
DeleteNode( node );\r
}\r
\r
\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
}\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
}\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
}\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
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
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
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
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
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
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
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
}\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
}\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
}\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
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
{\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
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
#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
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
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
\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
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
\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
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
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
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
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
// 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
}\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
\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
\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
# 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
#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
# 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
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
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
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
}\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
}\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
// 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
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
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
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
\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
\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
/** 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
}\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
}\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
}\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
*/\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
XMLNode* _prev;\r
XMLNode* _next;\r
\r
+ void* _userData;\r
+\r
private:\r
MemPool* _memPool;\r
void Unlink( XMLNode* child );\r
*/\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
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
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
\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
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
\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
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
\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
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
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
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
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
*/\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
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
}\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
}\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
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
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
@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
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
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
~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
\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
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
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
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
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
<?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
<?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
\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
}\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
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
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
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
{\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
\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
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
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
#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