################################\r
# set lib version here\r
\r
-set(GENERIC_LIB_VERSION "7.0.1")\r
+set(GENERIC_LIB_VERSION "7.1.0")\r
set(GENERIC_LIB_SOVERSION "7")\r
\r
################################\r
"${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}Config.cmake"\r
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${CMAKE_PROJECT_NAME}"\r
)\r
+write_basic_package_version_file(\r
+ "${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}ConfigVersion.cmake"\r
+ VERSION ${GENERIC_LIB_VERSION}\r
+ COMPATIBILITY SameMajorVersion\r
+)\r
install(FILES\r
${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}Config.cmake\r
+ ${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}ConfigVersion.cmake\r
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${CMAKE_PROJECT_NAME})\r
\r
install(EXPORT ${CMAKE_PROJECT_NAME}Targets NAMESPACE tinyxml2::\r
--- /dev/null
+This software is provided 'as-is', without any express or implied
+warranty. In no event will the authors be held liable for any
+damages arising from the use of this software.
+
+Permission is granted to anyone to use this software for any
+purpose, including commercial applications, and to alter it and
+redistribute it freely, subject to the following restrictions:
+
+1. The origin of this software must not be misrepresented; you must
+not claim that you wrote the original software. If you use this
+software in a product, an acknowledgment in the product documentation
+would be appreciated but is not required.
+
+2. Altered source versions must be plainly marked as such, and
+must not be misrepresented as being the original software.
+
+3. This notice may not be removed or altered from any source
+distribution.
# could be handy for archiving the generated documentation or if some version\r
# control system is used.\r
\r
-<<<<<<< HEAD\r
-PROJECT_NUMBER = 7.0.1\r
-=======\r
-PROJECT_NUMBER = 7.0.1\r
->>>>>>> master\r
+PROJECT_NUMBER = 7.1.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 doesn't parse or use DTDs (Document Type Definitions) or XSLs
(eXtensible Stylesheet Language.) There are other parsers out there
-that are much more fully featured. But they are also much bigger,
-take longer to set up in your project, have a higher learning curve,
-and often have a more restrictive license. If you are working with
+that are much more fully featured. But they are generally bigger and
+more difficult to use. If you are working with
browsers or have more complete XML needs, TinyXML-2 is not the parser for you.
TinyXML-1 vs. TinyXML-2
Simply compile and run. There is a visual studio 2017 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 Unix/Linuk/BSD and
+The top of tinyxml.h even has a simple g++ command line if you are using Unix/Linux/BSD and
don't want to use a build system.
Versioning
Documentation
-------------
-The documentation is build with Doxygen, using the 'dox'
+The documentation is built with Doxygen, using the 'dox'
configuration file.
License
{\r
va_list va;\r
va_start( va, format );\r
- int result = vsnprintf_s( buffer, size, _TRUNCATE, format, va );\r
+ const 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
+ const int result = vsnprintf_s( buffer, size, _TRUNCATE, format, va );\r
return result;\r
}\r
\r
#endif\r
\r
\r
-static const char LINE_FEED = (char)0x0a; // all line endings are normalized to LF\r
+static const char LINE_FEED = static_cast<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
+static const char CARRIAGE_RETURN = static_cast<char>(0x0d); // CR gets filtered out\r
static const char CR = CARRIAGE_RETURN;\r
static const char SINGLE_QUOTE = '\'';\r
static const char DOUBLE_QUOTE = '\"';\r
TIXMLASSERT(curLineNumPtr);\r
\r
char* start = p;\r
- char endChar = *endTag;\r
+ const char endChar = *endTag;\r
size_t length = strlen( endTag );\r
\r
// Inner loop of text parsing.\r
const int buflen = 10;\r
char buf[buflen] = { 0 };\r
int len = 0;\r
- char* adjusted = const_cast<char*>( XMLUtil::GetCharacterRef( p, buf, &len ) );\r
+ const char* adjusted = const_cast<char*>( XMLUtil::GetCharacterRef( p, buf, &len ) );\r
if ( adjusted == 0 ) {\r
*q = *p;\r
++p;\r
switch (*length) {\r
case 4:\r
--output;\r
- *output = (char)((input | BYTE_MARK) & BYTE_MASK);\r
+ *output = static_cast<char>((input | BYTE_MARK) & BYTE_MASK);\r
input >>= 6;\r
//fall through\r
case 3:\r
--output;\r
- *output = (char)((input | BYTE_MARK) & BYTE_MASK);\r
+ *output = static_cast<char>((input | BYTE_MARK) & BYTE_MASK);\r
input >>= 6;\r
//fall through\r
case 2:\r
--output;\r
- *output = (char)((input | BYTE_MARK) & BYTE_MASK);\r
+ *output = static_cast<char>((input | BYTE_MARK) & BYTE_MASK);\r
input >>= 6;\r
//fall through\r
case 1:\r
--output;\r
- *output = (char)(input | FIRST_BYTE_MARK[*length]);\r
+ *output = static_cast<char>(input | FIRST_BYTE_MARK[*length]);\r
break;\r
default:\r
TIXMLASSERT( false );\r
}\r
\r
\r
-void XMLUtil::ToStr(int64_t v, char* buffer, int bufferSize)\r
+void XMLUtil::ToStr( int64_t v, char* buffer, int bufferSize )\r
{\r
// horrible syntax trick to make the compiler happy about %lld\r
- TIXML_SNPRINTF(buffer, bufferSize, "%lld", (long long)v);\r
+ TIXML_SNPRINTF(buffer, bufferSize, "%lld", static_cast<long long>(v));\r
}\r
\r
+void XMLUtil::ToStr( uint64_t v, char* buffer, int bufferSize )\r
+{\r
+ // horrible syntax trick to make the compiler happy about %llu\r
+ TIXML_SNPRINTF(buffer, bufferSize, "%llu", (long long)v);\r
+}\r
\r
bool XMLUtil::ToInt( const char* str, int* value )\r
{\r
*value = (ival==0) ? false : true;\r
return true;\r
}\r
- if ( StringEqual( str, "true" ) ) {\r
- *value = true;\r
- return true;\r
+ static const char* TRUE[] = { "true", "True", "TRUE", 0 };\r
+ static const char* FALSE[] = { "false", "False", "FALSE", 0 };\r
+\r
+ for (int i = 0; TRUE[i]; ++i) {\r
+ if (StringEqual(str, TRUE[i])) {\r
+ *value = true;\r
+ return true;\r
+ }\r
}\r
- else if ( StringEqual( str, "false" ) ) {\r
- *value = false;\r
- return true;\r
+ for (int i = 0; FALSE[i]; ++i) {\r
+ if (StringEqual(str, FALSE[i])) {\r
+ *value = false;\r
+ return true;\r
+ }\r
}\r
return false;\r
}\r
{\r
long long v = 0; // horrible syntax trick to make the compiler happy about %lld\r
if (TIXML_SSCANF(str, "%lld", &v) == 1) {\r
- *value = (int64_t)v;\r
+ *value = static_cast<int64_t>(v);\r
return true;\r
}\r
return false;\r
}\r
\r
\r
+bool XMLUtil::ToUnsigned64(const char* str, uint64_t* value) {\r
+ unsigned long long v = 0; // horrible syntax trick to make the compiler happy about %llu\r
+ if(TIXML_SSCANF(str, "%llu", &v) == 1) {\r
+ *value = (uint64_t)v;\r
+ return true;\r
+ }\r
+ return false;\r
+}\r
+\r
+\r
char* XMLDocument::Identify( char* p, XMLNode** node )\r
{\r
TIXMLASSERT( node );\r
break;\r
}\r
\r
- int initialLineNum = node->_parseLineNum;\r
+ const int initialLineNum = node->_parseLineNum;\r
\r
StrPair endTag;\r
p = node->ParseDeep( p, &endTag, curLineNumPtr );\r
break;\r
}\r
\r
- XMLDeclaration* decl = node->ToDeclaration();\r
+ const XMLDeclaration* const decl = node->ToDeclaration();\r
if ( decl ) {\r
// Declarations are only allowed at document level\r
//\r
//\r
// Optimized due to a security test case. If the first node is \r
// a declaration, and the last node is a declaration, then only \r
- // declarations have so far been addded.\r
+ // declarations have so far been added.\r
bool wellLocated = false;\r
\r
if (ToDocument()) {\r
return 0;\r
}\r
\r
- char endTag[2] = { *p, 0 };\r
+ const char endTag[2] = { *p, 0 };\r
++p; // move past opening quote\r
\r
p = _value.ParseText( p, endTag, processEntities ? StrPair::ATTRIBUTE_VALUE : StrPair::ATTRIBUTE_VALUE_LEAVE_ENTITIES, curLineNumPtr );\r
}\r
\r
\r
+XMLError XMLAttribute::QueryUnsigned64Value(uint64_t* value) const\r
+{\r
+ if(XMLUtil::ToUnsigned64(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
_value.SetStr(buf);\r
}\r
\r
+void XMLAttribute::SetAttribute(uint64_t v)\r
+{\r
+ char buf[BUF_SIZE];\r
+ XMLUtil::ToStr(v, buf, BUF_SIZE);\r
+ _value.SetStr(buf);\r
+}\r
\r
\r
void XMLAttribute::SetAttribute( bool v )\r
return i;\r
}\r
\r
+uint64_t XMLElement::Unsigned64Attribute(const char* name, uint64_t defaultValue) const\r
+{\r
+ uint64_t i = defaultValue;\r
+ QueryUnsigned64Attribute(name, &i);\r
+ return i;\r
+}\r
+\r
bool XMLElement::BoolAttribute(const char* name, bool defaultValue) const\r
{\r
bool b = defaultValue;\r
SetText(buf);\r
}\r
\r
+void XMLElement::SetText(uint64_t v) {\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
}\r
\r
\r
+XMLError XMLElement::QueryUnsigned64Text(uint64_t* ival) const\r
+{\r
+ if(FirstChild() && FirstChild()->ToText()) {\r
+ const char* t = FirstChild()->Value();\r
+ if(XMLUtil::ToUnsigned64(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
return i;\r
}\r
\r
+uint64_t XMLElement::Unsigned64Text(uint64_t defaultValue) const\r
+{\r
+ uint64_t i = defaultValue;\r
+ QueryUnsigned64Text(&i);\r
+ return i;\r
+}\r
+\r
bool XMLElement::BoolText(bool defaultValue) const\r
{\r
bool b = defaultValue;\r
TIXMLASSERT( attrib );\r
attrib->_parseLineNum = _document->_parseCurLineNum;\r
\r
- int attrLineNum = attrib->_parseLineNum;\r
+ const int attrLineNum = attrib->_parseLineNum;\r
\r
p = attrib->ParseDeep( p, _document->ProcessEntities(), curLineNumPtr );\r
if ( !p || Attribute( attrib->Name() ) ) {\r
TIXMLASSERT( mode );\r
#if defined(_MSC_VER) && (_MSC_VER >= 1400 ) && (!defined WINCE)\r
FILE* fp = 0;\r
- errno_t err = fopen_s( &fp, filepath, mode );\r
+ const errno_t err = fopen_s( &fp, filepath, mode );\r
if ( err ) {\r
return 0;\r
}\r
struct LongFitsIntoSizeTMinusOne {\r
static bool Fits( unsigned long value )\r
{\r
- return value < (size_t)-1;\r
+ return value < static_cast<size_t>(-1);\r
}\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
+ const size_t read = fread( _charBuffer, 1, size, fp );\r
if ( read != size ) {\r
SetError( XML_ERROR_FILE_READ_ERROR, 0, 0 );\r
return _errorID;\r
SetError( XML_ERROR_EMPTY_DOCUMENT, 0, 0 );\r
return _errorID;\r
}\r
- if ( len == (size_t)(-1) ) {\r
+ if ( len == static_cast<size_t>(-1) ) {\r
len = strlen( p );\r
}\r
TIXMLASSERT( _charBuffer == 0 );\r
_errorLineNum = lineNum;\r
_errorStr.Reset();\r
\r
- size_t BUFFER_SIZE = 1000;\r
+ const size_t BUFFER_SIZE = 1000;\r
char* buffer = new char[BUFFER_SIZE];\r
\r
TIXMLASSERT(sizeof(error) <= sizeof(int));\r
}\r
for( int i=0; i<NUM_ENTITIES; ++i ) {\r
const char entityValue = entities[i].value;\r
- const unsigned char flagIndex = (unsigned char)entityValue;\r
+ const unsigned char flagIndex = static_cast<unsigned char>(entityValue);\r
TIXMLASSERT( flagIndex < ENTITY_RANGE );\r
_entityFlag[flagIndex] = true;\r
}\r
- _restrictedEntityFlag[(unsigned char)'&'] = true;\r
- _restrictedEntityFlag[(unsigned char)'<'] = true;\r
- _restrictedEntityFlag[(unsigned char)'>'] = true; // not required, but consistency is nice\r
+ _restrictedEntityFlag[static_cast<unsigned char>('&')] = true;\r
+ _restrictedEntityFlag[static_cast<unsigned char>('<')] = true;\r
+ _restrictedEntityFlag[static_cast<unsigned char>('>')] = true; // not required, but consistency is nice\r
_buffer.Push( 0 );\r
}\r
\r
// Check for entities. If one is found, flush\r
// the stream up until the entity, write the\r
// entity, and keep looking.\r
- if ( flag[(unsigned char)(*q)] ) {\r
+ if ( flag[static_cast<unsigned char>(*q)] ) {\r
while ( p < q ) {\r
const size_t delta = q - p;\r
- const int toPrint = ( INT_MAX < delta ) ? INT_MAX : (int)delta;\r
+ const int toPrint = ( INT_MAX < delta ) ? INT_MAX : static_cast<int>(delta);\r
Write( p, toPrint );\r
p += toPrint;\r
}\r
// string if an entity wasn't found.\r
if ( p < q ) {\r
const size_t delta = q - p;\r
- const int toPrint = ( INT_MAX < delta ) ? INT_MAX : (int)delta;\r
+ const int toPrint = ( INT_MAX < delta ) ? INT_MAX : static_cast<int>(delta);\r
Write( p, toPrint );\r
}\r
}\r
}\r
\r
\r
+void XMLPrinter::PushAttribute(const char* name, uint64_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
}\r
\r
+\r
void XMLPrinter::PushText( int64_t value )\r
{\r
char buf[BUF_SIZE];\r
PushText( buf, false );\r
}\r
\r
+\r
+void XMLPrinter::PushText( uint64_t value )\r
+{\r
+ char buf[BUF_SIZE];\r
+ XMLUtil::ToStr(value, buf, BUF_SIZE);\r
+ PushText(buf, false);\r
+}\r
+\r
+\r
void XMLPrinter::PushText( int value )\r
{\r
char buf[BUF_SIZE];\r
http://semver.org/\r
*/\r
static const int TIXML2_MAJOR_VERSION = 7;\r
-static const int TIXML2_MINOR_VERSION = 0;\r
-static const int TIXML2_PATCH_VERSION = 1;\r
+static const int TIXML2_MINOR_VERSION = 1;\r
+static const int TIXML2_PATCH_VERSION = 0;\r
\r
#define TINYXML2_MAJOR_VERSION 7\r
-#define TINYXML2_MINOR_VERSION 0\r
-#define TINYXML2_PATCH_VERSION 1\r
+#define TINYXML2_MINOR_VERSION 1\r
+#define TINYXML2_PATCH_VERSION 0\r
\r
// A fixed element depth limit is problematic. There needs to be a\r
// limit to avoid a stack overflow. However, that limit varies per\r
TIXMLASSERT( cap > 0 );\r
if ( cap > _allocated ) {\r
TIXMLASSERT( cap <= INT_MAX / 2 );\r
- int newAllocated = cap * 2;\r
+ const int newAllocated = cap * 2;\r
T* newMem = new T[newAllocated];\r
TIXMLASSERT( newAllocated >= _size );\r
memcpy( newMem, _mem, sizeof(T)*_size ); // warning: not using constructors, only works for PODs\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
+ static void ToStr(uint64_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 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
+ static bool ToUnsigned64(const char* str, uint64_t* value);\r
// Changes what is serialized for a boolean value.\r
// Default to "true" and "false". Shouldn't be changed\r
// unless you have a special testing or compatibility need.\r
return i;\r
}\r
\r
+ uint64_t Unsigned64Value() const {\r
+ uint64_t i = 0;\r
+ QueryUnsigned64Value(&i);\r
+ return i;\r
+ }\r
+\r
/// Query as an unsigned integer. See IntValue()\r
unsigned UnsignedValue() const {\r
unsigned i=0;\r
XMLError QueryUnsignedValue( unsigned int* value ) const;\r
/// See QueryIntValue\r
XMLError QueryInt64Value(int64_t* value) const;\r
+ /// See QueryIntValue\r
+ XMLError QueryUnsigned64Value(uint64_t* value) const;\r
/// See QueryIntValue\r
XMLError QueryBoolValue( bool* value ) const;\r
/// See QueryIntValue\r
void SetAttribute( unsigned value );\r
/// Set the attribute to value.\r
void SetAttribute(int64_t value);\r
- /// Set the attribute to value.\r
+ /// Set the attribute to value.\r
+ void SetAttribute(uint64_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
unsigned UnsignedAttribute(const char* name, unsigned defaultValue = 0) const;\r
/// See IntAttribute()\r
int64_t Int64Attribute(const char* name, int64_t defaultValue = 0) const;\r
+ /// See IntAttribute()\r
+ uint64_t Unsigned64Attribute(const char* name, uint64_t defaultValue = 0) const;\r
/// See IntAttribute()\r
bool BoolAttribute(const char* name, bool defaultValue = false) const;\r
/// See IntAttribute()\r
return a->QueryInt64Value(value);\r
}\r
\r
+ /// See QueryIntAttribute()\r
+ XMLError QueryUnsigned64Attribute(const char* name, uint64_t* value) const {\r
+ const XMLAttribute* a = FindAttribute(name);\r
+ if(!a) {\r
+ return XML_NO_ATTRIBUTE;\r
+ }\r
+ return a->QueryUnsigned64Value(value);\r
+ }\r
+\r
/// See QueryIntAttribute()\r
XMLError QueryBoolAttribute( const char* name, bool* value ) const {\r
const XMLAttribute* a = FindAttribute( name );\r
return QueryInt64Attribute(name, value);\r
}\r
\r
- XMLError QueryAttribute( const char* name, bool* value ) const {\r
+ XMLError QueryAttribute(const char* name, uint64_t* value) const {\r
+ return QueryUnsigned64Attribute(name, value);\r
+ }\r
+\r
+ XMLError QueryAttribute( const char* name, bool* value ) const {\r
return QueryBoolAttribute( name, value );\r
}\r
\r
a->SetAttribute(value);\r
}\r
\r
- /// Sets the named attribute to value.\r
+ /// Sets the named attribute to value.\r
+ void SetAttribute(const char* name, uint64_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
void SetText( unsigned value );\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(uint64_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 an element. See SetText() for important limitations.\r
/// See QueryIntText()\r
XMLError QueryInt64Text(int64_t* uval) const;\r
/// See QueryIntText()\r
+ XMLError QueryUnsigned64Text(uint64_t* uval) const;\r
+ /// See QueryIntText()\r
XMLError QueryBoolText( bool* bval ) const;\r
/// See QueryIntText()\r
XMLError QueryDoubleText( double* dval ) const;\r
unsigned UnsignedText(unsigned defaultValue = 0) const;\r
/// See QueryIntText()\r
int64_t Int64Text(int64_t defaultValue = 0) const;\r
+ /// See QueryIntText()\r
+ uint64_t Unsigned64Text(uint64_t defaultValue = 0) const;\r
/// See QueryIntText()\r
bool BoolText(bool defaultValue = false) const;\r
/// See QueryIntText()\r
specified, TinyXML-2 will assume 'xml' points to a\r
null terminated string.\r
*/\r
- XMLError Parse( const char* xml, size_t nBytes=(size_t)(-1) );\r
+ XMLError Parse( const char* xml, size_t nBytes=static_cast<size_t>(-1) );\r
\r
/**\r
Load an XML file from disk.\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, int64_t value);\r
+ void PushAttribute( const char* name, int64_t value );\r
+ void PushAttribute( const char* name, uint64_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
void PushText( int value );\r
/// Add a text node from an unsigned.\r
void PushText( unsigned value );\r
- /// Add a text node from an unsigned.\r
- void PushText(int64_t value);\r
+ /// Add a text node from a signed 64bit integer.\r
+ void PushText( int64_t value );\r
+ /// Add a text node from an unsigned 64bit integer.\r
+ void PushText( uint64_t value );\r
/// Add a text node from a bool.\r
void PushText( bool value );\r
/// Add a text node from a float.\r
If in print to memory mode, reset the buffer to the\r
beginning.\r
*/\r
- void ClearBuffer() {\r
+ void ClearBuffer( bool resetToFirstElement = true ) {\r
_buffer.Clear();\r
_buffer.Push(0);\r
- _firstElement = true;\r
+ _firstElement = resetToFirstElement;\r
}\r
\r
protected:\r
// Build:\r
// <element>\r
// <!--comment-->\r
+ // <sub attrib="0" />\r
// <sub attrib="1" />\r
- // <sub attrib="2" />\r
- // <sub attrib="3" >& Text!</sub>\r
+ // <sub attrib="2" >& Text!</sub>\r
// <element>\r
\r
XMLDocument* doc = new XMLDocument();\r
// ---------- Attributes ---------\r
{\r
static const int64_t BIG = -123456789012345678;\r
+ static const uint64_t BIG_POS = 123456789012345678;\r
XMLDocument doc;\r
XMLElement* element = doc.NewElement("element");\r
doc.InsertFirstChild(element);\r
}\r
XMLTest("Attribute: int64_t", BIG, element->Int64Attribute("attrib"), true);\r
}\r
- {\r
+ {\r
+ element->SetAttribute("attrib", BIG_POS);\r
+ {\r
+ uint64_t v = 0;\r
+ XMLError queryResult = element->QueryUnsigned64Attribute("attrib", &v);\r
+ XMLTest("Attribute: uint64_t", XML_SUCCESS, queryResult, true);\r
+ XMLTest("Attribute: uint64_t", BIG_POS, v, true);\r
+ }\r
+ {\r
+ uint64_t v = 0;\r
+ int queryResult = element->QueryAttribute("attrib", &v);\r
+ XMLTest("Attribute: uint64_t", (int)XML_SUCCESS, queryResult, true);\r
+ XMLTest("Attribute: uint64_t", BIG_POS, v, true);\r
+ }\r
+ XMLTest("Attribute: uint64_t", BIG_POS, element->Unsigned64Attribute("attrib"), true);\r
+ }\r
+ {\r
element->SetAttribute("attrib", true);\r
{\r
bool v = false;\r
XMLTest("Element: int64_t", XML_SUCCESS, queryResult, true);\r
XMLTest("Element: int64_t", BIG, v, true);\r
}\r
- }\r
+ {\r
+ element->SetText(BIG_POS);\r
+ uint64_t v = 0;\r
+ XMLError queryResult = element->QueryUnsigned64Text(&v);\r
+ XMLTest("Element: uint64_t", XML_SUCCESS, queryResult, true);\r
+ XMLTest("Element: uint64_t", BIG_POS, v, true);\r
+ }\r
+ }\r
\r
// ---------- XMLPrinter stream mode ------\r
{\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-uint64", uint64_t(37));\r
+ printer.PushAttribute("attrib-bool", true);\r
printer.PushAttribute("attrib-double", 4.0);\r
printer.CloseElement();\r
fclose(printerfp);\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
+ attrib = cdoc.FirstChildElement("foo")->FindAttribute("attrib-uint64");\r
+ XMLTest("attrib-uint64", uint64_t(37), attrib->Unsigned64Value(), 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
XMLTest( "Ill formed XML", true, doc.Error() );\r
}\r
\r
+ {\r
+ //API:IntText(),UnsignedText(),Int64Text(),DoubleText(),BoolText() and FloatText() test\r
+ const char* xml = "<point> <IntText>-24</IntText> <UnsignedText>42</UnsignedText> \\r
+ <Int64Text>38</Int64Text> <BoolText>true</BoolText> <DoubleText>2.35</DoubleText> </point>";\r
+ XMLDocument doc;\r
+ doc.Parse(xml);\r
+\r
+ const XMLElement* pointElement = doc.RootElement();\r
+ int test1 = pointElement->FirstChildElement("IntText")->IntText();\r
+ XMLTest("IntText() test", -24, test1);\r
+\r
+ unsigned test2 = pointElement->FirstChildElement("UnsignedText")->UnsignedText();\r
+ XMLTest("UnsignedText() test", static_cast<unsigned>(42), test2);\r
+\r
+ int64_t test3 = pointElement->FirstChildElement("Int64Text")->Int64Text();\r
+ XMLTest("Int64Text() test", static_cast<int64_t>(38), test3);\r
+\r
+ double test4 = pointElement->FirstChildElement("DoubleText")->DoubleText();\r
+ XMLTest("DoubleText() test", 2.35, test4);\r
+\r
+ float test5 = pointElement->FirstChildElement("DoubleText")->FloatText();\r
+ XMLTest("FloatText()) test", 2.35f, test5);\r
+\r
+ bool test6 = pointElement->FirstChildElement("BoolText")->BoolText();\r
+ XMLTest("FloatText()) test", true, test6);\r
+ }\r
+\r
+ {\r
+ //API:ShallowEqual() test\r
+ const char* xml = "<playlist id = 'playlist'>"\r
+ "<property name = 'track_name'>voice</property>"\r
+ "</playlist>";\r
+ XMLDocument doc;\r
+ doc.Parse( xml );\r
+ const XMLNode* PlaylistNode = doc.RootElement();\r
+ const XMLNode* PropertyNode = PlaylistNode->FirstChildElement();\r
+ bool result;\r
+ result = PlaylistNode->ShallowEqual(PropertyNode);\r
+ XMLTest("ShallowEqual() test",false,result);\r
+ result = PlaylistNode->ShallowEqual(PlaylistNode);\r
+ XMLTest("ShallowEqual() test",true,result);\r
+ }\r
+\r
+ {\r
+ //API: previousSiblingElement() and NextSiblingElement() test\r
+ const char* xml = "<playlist id = 'playlist'>"\r
+ "<property name = 'track_name'>voice</property>"\r
+ "<entry out = '946' producer = '2_playlist1' in = '0'/>"\r
+ "<blank length = '1'/>"\r
+ "</playlist>";\r
+ XMLDocument doc;\r
+ doc.Parse( xml );\r
+ XMLElement* ElementPlaylist = doc.FirstChildElement("playlist");\r
+ XMLTest("previousSiblingElement() test",true,ElementPlaylist != 0);\r
+ const XMLElement* pre = ElementPlaylist->PreviousSiblingElement();\r
+ XMLTest("previousSiblingElement() test",true,pre == 0);\r
+ const XMLElement* ElementBlank = ElementPlaylist->FirstChildElement("entry")->NextSiblingElement("blank");\r
+ XMLTest("NextSiblingElement() test",true,ElementBlank != 0);\r
+ const XMLElement* next = ElementBlank->NextSiblingElement();\r
+ XMLTest("NextSiblingElement() test",true,next == 0);\r
+ const XMLElement* ElementEntry = ElementBlank->PreviousSiblingElement("entry");\r
+ XMLTest("PreviousSiblingElement test",true,ElementEntry != 0);\r
+ }\r
+\r
// QueryXYZText\r
{\r
const char* xml = "<point> <x>1.2</x> <y>1</y> <z>38</z> <valid>true</valid> </point>";\r
doc.Print( &printer );\r
\r
XMLTest( "BOM preservation (compare)", xml_bom_preservation, printer.CStr(), false, true );\r
- doc.SaveFile( "resources/bomtest.xml" );\r
+ doc.SaveFile( "resources/out/bomtest.xml" );\r
XMLTest( "Save bomtest.xml", false, doc.Error() );\r
}\r
{\r
XMLDocument doc;\r
- doc.LoadFile( "resources/bomtest.xml" );\r
+ doc.LoadFile( "resources/out/bomtest.xml" );\r
XMLTest( "Load bomtest.xml", false, doc.Error() );\r
XMLTest( "BOM preservation (load)", true, doc.HasBOM(), false );\r
\r