27 Commits

Author SHA1 Message Date
Lee Thomason
8d3cdf50db now fix the badge 2023-11-21 12:02:26 -08:00
Lee Thomason
941e2d9018 fix the tests? 2023-11-21 11:58:20 -08:00
Lee Thomason
428cd1be42 update readme 2023-11-21 11:52:44 -08:00
Lee Thomason
9d026527a4 Merge branch 'pedantic-whitespace' of https://github.com/kcsaul/tinyxml2 into kcsaul-pedantic-whitespace 2023-11-21 11:40:52 -08:00
Lee Thomason
4c27b08f62 Merge pull request #949 from imba-tjd/master-1
fix compiler detection
2023-11-20 21:27:14 -08:00
Lee Thomason
ac23537e06 Merge pull request #933 from kb1sph/master
Added ChildElementCount()
2023-11-20 21:22:19 -08:00
Lee Thomason
52035717a3 Merge pull request #911 from JurajX/fix_warnings
Fix warnings
2023-11-20 21:11:09 -08:00
谭九鼎
cc4c1df7ec fix compiler detection 2023-08-09 18:28:44 +08:00
Kevin Saul
98303bbda3 add pedantic whitespace mode 2023-05-28 21:36:28 +12:00
kb1sph
904ad04bea Added ChildElementCount
Added ChildElementCount suggested by msteiger on sourceforge for original tinyxml.  Modified for TinyXML-2.
2023-02-06 19:07:13 -05:00
kb1sph
5926ec938a Added ChildElementCount()
Added the ChildElementCount function that was initially suggested by msteiger on sourceforge for the original tinyxml.  Modified to work with TinyXML-2.
2023-02-06 19:04:57 -05:00
Lee Thomason
e05956094c Merge pull request #925 from hordi/patch-1
Update tinyxml2.h
2023-01-14 18:02:53 -08:00
Lee Thomason
9a89766acc Merge pull request #910 from quagla/maxdepth
Increase depth recursion limit
2023-01-14 17:50:19 -08:00
Lee Thomason
9706d2cdc0 reorder tests 2023-01-14 17:43:38 -08:00
Lee Thomason
94f52b5cbe Merge branch 'dinghao188-dev' of https://github.com/dinghao188/tinyxml2 into dinghao188-dinghao188-dev 2023-01-14 17:41:42 -08:00
Lee Thomason
9ad3f2745b update to vs2022 2023-01-14 17:41:11 -08:00
Yurii Hordiienko
2555efa919 Update tinyxml2.h
do we really need that implicit memset call in line 378?
2022-11-15 17:49:45 -05:00
Juraj
8fd6cc6d2d fix gcc sizetype complaint 2022-06-07 08:07:33 +02:00
Juraj
beb2b2f82d fix more -Wsign-conversion warnings 2022-06-07 07:53:54 +02:00
Juraj
07f497d6d8 fix -Wsuggest-override warnings 2022-06-07 07:27:41 +02:00
Juraj
0691cf72b4 fix -Wsign-conversion warnings 2022-06-07 07:27:27 +02:00
Alessio Quaglino
736659015c Update tinyxml2.h
Increase maximum recursion depth
2022-06-06 14:08:40 +02:00
dinghao188
3e94e4a047 add testcase 2022-04-03 06:03:33 +08:00
Lee Thomason
e45d9d16d4 Merge pull request #907 from leethomason/leethomason/fix-android
Fix android build
2022-04-02 14:20:20 -07:00
Lee Thomason
7e310468f3 typo 2022-04-02 14:15:59 -07:00
Lee Thomason
953018ab93 fix android build 2022-04-02 14:14:20 -07:00
dinghao188
9efb6b0b66 fix assertion - Assertion '_elementPool.CurrentAllocs() == _elementPool.Untracked()' failed. 2021-09-17 17:49:01 +08:00
6 changed files with 317 additions and 79 deletions

View File

@@ -6,7 +6,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ windows-2019, macos-10.15, ubuntu-20.04 ]
os: [ windows-2019, macos-latest, ubuntu-20.04 ]
cmake: [ 3.15, 3.x ]
include:
- os: windows-2019
@@ -17,7 +17,7 @@ jobs:
- os: ubuntu-20.04
tree: tree
- os: macos-10.15
- os: macos-latest
tree: find
- cmake: 3.15

View File

@@ -1,9 +1,7 @@
TinyXML-2
=========
![Build](https://github.com/leethomason/tinyxml2/actions/workflows/test.yml/badge.svg)
![TinyXML-2 Logo](http://www.grinninglizard.com/tinyxml2/TinyXML2_small.png)
[![Test](https://github.com/leethomason/tinyxml2/actions/workflows/test.yml/badge.svg)](https://github.com/leethomason/tinyxml2/actions/workflows/test.yml)
TinyXML-2 is a simple, small, efficient, C++ XML parser that can be
easily integrated into other programs.
@@ -93,7 +91,7 @@ by the Document. When the Document is deleted, so are all the nodes it contains.
### White Space
#### Whitespace Preservation (default)
#### Whitespace Preservation (default, PRESERVE_WHITESPACE)
Microsoft has an excellent article on white space: http://msdn.microsoft.com/en-us/library/ms256097.aspx
@@ -125,7 +123,7 @@ valuable. TinyXML-2 sees these as the same XML:
<document><data>1</data><data>2</data><data>3</data></document>
#### Whitespace Collapse
#### Whitespace Collapse (COLLAPSE_WHITESPACE)
For some applications, it is preferable to collapse whitespace. Collapsing
whitespace gives you "HTML-like" behavior, which is sometimes more suitable
@@ -143,7 +141,15 @@ However, you may also use COLLAPSE_WHITESPACE, which will:
Note that (currently) there is a performance impact for using COLLAPSE_WHITESPACE.
It essentially causes the XML to be parsed twice.
#### Error Reporting
#### Pedantic Whitespace (PEDANTIC_WHITESPACE)
For applications that need to know about text nodes that are composed entirely of
whitespace, PEDANTIC_WHITESPACE is available. PEDANTIC_WHITESPACE maintains all the
whilespace between elements.
PEDANTIC_WHITESPACE is a new mode and not as tested as the other whitespace modes.
### Error Reporting
TinyXML-2 reports the line number of any errors in an XML document that
cannot be parsed correctly. In addition, all nodes (elements, declarations,

View File

@@ -103,10 +103,17 @@ distribution.
#if defined(_WIN64)
#define TIXML_FSEEK _fseeki64
#define TIXML_FTELL _ftelli64
#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) \
|| defined(__NetBSD__) || defined(__DragonFly__) || defined(__ANDROID__) || (__CYGWIN__)
#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || (__CYGWIN__)
#define TIXML_FSEEK fseeko
#define TIXML_FTELL ftello
#elif defined(__ANDROID__)
#if __ANDROID_API__ > 24
#define TIXML_FSEEK fseeko64
#define TIXML_FTELL ftello64
#else
#define TIXML_FSEEK fseeko
#define TIXML_FTELL ftello
#endif
#elif defined(__unix__) && defined(__x86_64__)
#define TIXML_FSEEK fseeko64
#define TIXML_FTELL ftello64
@@ -708,7 +715,7 @@ bool XMLUtil::ToUnsigned64(const char* str, uint64_t* value) {
}
char* XMLDocument::Identify( char* p, XMLNode** node )
char* XMLDocument::Identify( char* p, XMLNode** node, bool first )
{
TIXMLASSERT( node );
TIXMLASSERT( p );
@@ -760,10 +767,20 @@ char* XMLDocument::Identify( char* p, XMLNode** node )
p += dtdHeaderLen;
}
else if ( XMLUtil::StringEqual( p, elementHeader, elementHeaderLen ) ) {
// Preserve whitespace pedantically before closing tag, when it's immediately after opening tag
if (WhitespaceMode() == PEDANTIC_WHITESPACE && first && p != start && *(p + elementHeaderLen) == '/') {
returnNode = CreateUnlinkedNode<XMLText>(_textPool);
returnNode->_parseLineNum = startLine;
p = start; // Back it up, all the text counts.
_parseCurLineNum = startLine;
}
else {
returnNode = CreateUnlinkedNode<XMLElement>(_elementPool);
returnNode->_parseLineNum = _parseCurLineNum;
p += elementHeaderLen;
}
}
else {
returnNode = CreateUnlinkedNode<XMLText>( _textPool );
returnNode->_parseLineNum = _parseCurLineNum; // Report line of first non-whitespace character
@@ -815,6 +832,34 @@ XMLNode::~XMLNode()
}
}
// ChildElementCount was originally suggested by msteiger on the sourceforge page for TinyXML and modified by KB1SPH for TinyXML-2.
int XMLNode::ChildElementCount(const char *value) const {
int count = 0;
const XMLElement *e = FirstChildElement(value);
while (e) {
e = e->NextSiblingElement(value);
count++;
}
return count;
}
int XMLNode::ChildElementCount() const {
int count = 0;
const XMLElement *e = FirstChildElement();
while (e) {
e = e->NextSiblingElement();
count++;
}
return count;
}
const char* XMLNode::Value() const
{
// Edge case: XMLDocuments don't have a Value. Return null.
@@ -1063,21 +1108,23 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr )
if (_document->Error())
return 0;
bool first = true;
while( p && *p ) {
XMLNode* node = 0;
p = _document->Identify( p, &node );
p = _document->Identify( p, &node, first );
TIXMLASSERT( p );
if ( node == 0 ) {
break;
}
first = false;
const int initialLineNum = node->_parseLineNum;
StrPair endTag;
p = node->ParseDeep( p, &endTag, curLineNumPtr );
if ( !p ) {
DeleteNode( node );
_document->DeleteNode( node );
if ( !_document->Error() ) {
_document->SetError( XML_ERROR_PARSING, initialLineNum, 0);
}
@@ -1110,7 +1157,7 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr )
}
if ( !wellLocated ) {
_document->SetError( XML_ERROR_PARSING_DECLARATION, initialLineNum, "XMLDeclaration value=%s", decl->Value());
DeleteNode( node );
_document->DeleteNode( node );
break;
}
}
@@ -1145,7 +1192,7 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr )
}
if ( mismatch ) {
_document->SetError( XML_ERROR_MISMATCHED_ELEMENT, initialLineNum, "XMLElement name=%s", ele->Name());
DeleteNode( node );
_document->DeleteNode( node );
break;
}
}

View File

@@ -64,7 +64,7 @@ distribution.
# pragma warning(disable: 4251)
#endif
#ifdef _WIN32
#ifdef _MSC_VER
# ifdef TINYXML2_EXPORT
# define TINYXML2_LIB __declspec(dllexport)
# elif defined(TINYXML2_IMPORT)
@@ -112,7 +112,7 @@ static const int TIXML2_PATCH_VERSION = 0;
// system, and the capacity of the stack. On the other hand, it's a trivial
// attack that can result from ill, malicious, or even correctly formed XML,
// so there needs to be a limit in place.
static const int TINYXML2_MAX_ELEMENT_DEPTH = 100;
static const int TINYXML2_MAX_ELEMENT_DEPTH = 500;
namespace tinyxml2
{
@@ -305,9 +305,9 @@ private:
if ( cap > _allocated ) {
TIXMLASSERT( cap <= INT_MAX / 2 );
const int newAllocated = cap * 2;
T* newMem = new T[newAllocated];
T* newMem = new T[static_cast<unsigned int>(newAllocated)];
TIXMLASSERT( newAllocated >= _size );
memcpy( newMem, _mem, sizeof(T)*_size ); // warning: not using constructors, only works for PODs
memcpy( newMem, _mem, sizeof(T)*static_cast<size_t>(_size) ); // warning: not using constructors, only works for PODs
if ( _mem != _pool ) {
delete [] _mem;
}
@@ -317,7 +317,7 @@ private:
}
T* _mem;
T _pool[INITIAL_SIZE];
T _pool[static_cast<size_t>(INITIAL_SIZE)];
int _allocated; // objects allocated
int _size; // number objects in use
};
@@ -365,17 +365,17 @@ public:
_nUntracked = 0;
}
virtual int ItemSize() const {
virtual int ItemSize() const override{
return ITEM_SIZE;
}
int CurrentAllocs() const {
return _currentAllocs;
}
virtual void* Alloc() {
virtual void* Alloc() override{
if ( !_root ) {
// Need a new block.
Block* block = new Block();
Block* block = new Block;
_blockPtrs.Push( block );
Item* blockItems = block->items;
@@ -398,7 +398,7 @@ public:
return result;
}
virtual void Free( void* mem ) {
virtual void Free( void* mem ) override {
if ( !mem ) {
return;
}
@@ -416,7 +416,7 @@ public:
ITEM_SIZE, _nAllocs, _blockPtrs.Size() );
}
void SetTracked() {
void SetTracked() override {
--_nUntracked;
}
@@ -443,7 +443,7 @@ private:
union Item {
Item* next;
char itemData[ITEM_SIZE];
char itemData[static_cast<size_t>(ITEM_SIZE)];
};
struct Block {
Item items[ITEMS_PER_BLOCK];
@@ -603,7 +603,7 @@ public:
TIXMLASSERT( p );
TIXMLASSERT( q );
TIXMLASSERT( nChar >= 0 );
return strncmp( p, q, nChar ) == 0;
return strncmp( p, q, static_cast<size_t>(nChar) ) == 0;
}
inline static bool IsUTF8Continuation( const char p ) {
@@ -732,6 +732,12 @@ public:
return 0;
}
// ChildElementCount was originally suggested by msteiger on the sourceforge page for TinyXML and modified by KB1SPH for TinyXML-2.
int ChildElementCount(const char *value) const;
int ChildElementCount() const;
/** The meaning of 'value' changes for the specific type.
@verbatim
Document: empty (NULL is returned, not an empty string)
@@ -992,12 +998,12 @@ class TINYXML2_LIB XMLText : public XMLNode
{
friend class XMLDocument;
public:
virtual bool Accept( XMLVisitor* visitor ) const;
virtual bool Accept( XMLVisitor* visitor ) const override;
virtual XMLText* ToText() {
virtual XMLText* ToText() override {
return this;
}
virtual const XMLText* ToText() const {
virtual const XMLText* ToText() const override {
return this;
}
@@ -1010,14 +1016,14 @@ public:
return _isCData;
}
virtual XMLNode* ShallowClone( XMLDocument* document ) const;
virtual bool ShallowEqual( const XMLNode* compare ) const;
virtual XMLNode* ShallowClone( XMLDocument* document ) const override;
virtual bool ShallowEqual( const XMLNode* compare ) const override;
protected:
explicit XMLText( XMLDocument* doc ) : XMLNode( doc ), _isCData( false ) {}
virtual ~XMLText() {}
char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr );
char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr ) override;
private:
bool _isCData;
@@ -1032,23 +1038,23 @@ class TINYXML2_LIB XMLComment : public XMLNode
{
friend class XMLDocument;
public:
virtual XMLComment* ToComment() {
virtual XMLComment* ToComment() override {
return this;
}
virtual const XMLComment* ToComment() const {
virtual const XMLComment* ToComment() const override {
return this;
}
virtual bool Accept( XMLVisitor* visitor ) const;
virtual bool Accept( XMLVisitor* visitor ) const override;
virtual XMLNode* ShallowClone( XMLDocument* document ) const;
virtual bool ShallowEqual( const XMLNode* compare ) const;
virtual XMLNode* ShallowClone( XMLDocument* document ) const override;
virtual bool ShallowEqual( const XMLNode* compare ) const override;
protected:
explicit XMLComment( XMLDocument* doc );
virtual ~XMLComment();
char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr);
char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr) override;
private:
XMLComment( const XMLComment& ); // not supported
@@ -1071,23 +1077,23 @@ class TINYXML2_LIB XMLDeclaration : public XMLNode
{
friend class XMLDocument;
public:
virtual XMLDeclaration* ToDeclaration() {
virtual XMLDeclaration* ToDeclaration() override {
return this;
}
virtual const XMLDeclaration* ToDeclaration() const {
virtual const XMLDeclaration* ToDeclaration() const override {
return this;
}
virtual bool Accept( XMLVisitor* visitor ) const;
virtual bool Accept( XMLVisitor* visitor ) const override;
virtual XMLNode* ShallowClone( XMLDocument* document ) const;
virtual bool ShallowEqual( const XMLNode* compare ) const;
virtual XMLNode* ShallowClone( XMLDocument* document ) const override;
virtual bool ShallowEqual( const XMLNode* compare ) const override;
protected:
explicit XMLDeclaration( XMLDocument* doc );
virtual ~XMLDeclaration();
char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr );
char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr ) override;
private:
XMLDeclaration( const XMLDeclaration& ); // not supported
@@ -1106,23 +1112,23 @@ class TINYXML2_LIB XMLUnknown : public XMLNode
{
friend class XMLDocument;
public:
virtual XMLUnknown* ToUnknown() {
virtual XMLUnknown* ToUnknown() override {
return this;
}
virtual const XMLUnknown* ToUnknown() const {
virtual const XMLUnknown* ToUnknown() const override {
return this;
}
virtual bool Accept( XMLVisitor* visitor ) const;
virtual bool Accept( XMLVisitor* visitor ) const override;
virtual XMLNode* ShallowClone( XMLDocument* document ) const;
virtual bool ShallowEqual( const XMLNode* compare ) const;
virtual XMLNode* ShallowClone( XMLDocument* document ) const override;
virtual bool ShallowEqual( const XMLNode* compare ) const override;
protected:
explicit XMLUnknown( XMLDocument* doc );
virtual ~XMLUnknown();
char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr );
char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr ) override;
private:
XMLUnknown( const XMLUnknown& ); // not supported
@@ -1274,13 +1280,13 @@ public:
SetValue( str, staticMem );
}
virtual XMLElement* ToElement() {
virtual XMLElement* ToElement() override {
return this;
}
virtual const XMLElement* ToElement() const {
virtual const XMLElement* ToElement() const override {
return this;
}
virtual bool Accept( XMLVisitor* visitor ) const;
virtual bool Accept( XMLVisitor* visitor ) const override;
/** Given an attribute name, Attribute() returns the value
for the attribute of that name, or null if none
@@ -1676,11 +1682,11 @@ public:
ElementClosingType ClosingType() const {
return _closingType;
}
virtual XMLNode* ShallowClone( XMLDocument* document ) const;
virtual bool ShallowEqual( const XMLNode* compare ) const;
virtual XMLNode* ShallowClone( XMLDocument* document ) const override;
virtual bool ShallowEqual( const XMLNode* compare ) const override;
protected:
char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr );
char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr ) override;
private:
XMLElement( XMLDocument* doc );
@@ -1704,7 +1710,8 @@ private:
enum Whitespace {
PRESERVE_WHITESPACE,
COLLAPSE_WHITESPACE
COLLAPSE_WHITESPACE,
PEDANTIC_WHITESPACE
};
@@ -1728,11 +1735,11 @@ public:
XMLDocument( bool processEntities = true, Whitespace whitespaceMode = PRESERVE_WHITESPACE );
~XMLDocument();
virtual XMLDocument* ToDocument() {
virtual XMLDocument* ToDocument() override {
TIXMLASSERT( this == _document );
return this;
}
virtual const XMLDocument* ToDocument() const {
virtual const XMLDocument* ToDocument() const override {
TIXMLASSERT( this == _document );
return this;
}
@@ -1829,7 +1836,7 @@ public:
@endverbatim
*/
void Print( XMLPrinter* streamer=0 ) const;
virtual bool Accept( XMLVisitor* visitor ) const;
virtual bool Accept( XMLVisitor* visitor ) const override;
/**
Create a new Element associated with
@@ -1915,15 +1922,15 @@ public:
void DeepCopy(XMLDocument* target) const;
// internal
char* Identify( char* p, XMLNode** node );
char* Identify( char* p, XMLNode** node, bool first );
// internal
void MarkInUse(const XMLNode* const);
virtual XMLNode* ShallowClone( XMLDocument* /*document*/ ) const {
virtual XMLNode* ShallowClone( XMLDocument* /*document*/ ) const override{
return 0;
}
virtual bool ShallowEqual( const XMLNode* /*compare*/ ) const {
virtual bool ShallowEqual( const XMLNode* /*compare*/ ) const override{
return false;
}
@@ -2286,18 +2293,18 @@ public:
void PushDeclaration( const char* value );
void PushUnknown( const char* value );
virtual bool VisitEnter( const XMLDocument& /*doc*/ );
virtual bool VisitExit( const XMLDocument& /*doc*/ ) {
virtual bool VisitEnter( const XMLDocument& /*doc*/ ) override;
virtual bool VisitExit( const XMLDocument& /*doc*/ ) override {
return true;
}
virtual bool VisitEnter( const XMLElement& element, const XMLAttribute* attribute );
virtual bool VisitExit( const XMLElement& element );
virtual bool VisitEnter( const XMLElement& element, const XMLAttribute* attribute ) override;
virtual bool VisitExit( const XMLElement& element ) override;
virtual bool Visit( const XMLText& text );
virtual bool Visit( const XMLComment& comment );
virtual bool Visit( const XMLDeclaration& declaration );
virtual bool Visit( const XMLUnknown& unknown );
virtual bool Visit( const XMLText& text ) override;
virtual bool Visit( const XMLComment& comment ) override;
virtual bool Visit( const XMLDeclaration& declaration ) override;
virtual bool Visit( const XMLUnknown& unknown ) override;
/**
If in print to memory mode, return a pointer to

View File

@@ -29,26 +29,26 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>

View File

@@ -1869,6 +1869,178 @@ int main( int argc, const char ** argv )
XMLTest( "Whitespace all space", true, 0 == doc.FirstChildElement()->FirstChild() );
}
// ----------- Preserve Whitespace ------------
{
const char* xml = "<element>This is &apos; \n\n text &apos;</element>";
XMLDocument doc(true, PRESERVE_WHITESPACE);
doc.Parse(xml);
XMLTest("Parse with whitespace preserved", false, doc.Error());
XMLTest("Whitespace preserved", "This is ' \n\n text '", doc.FirstChildElement()->GetText());
}
{
const char* xml = "<element> This \nis &apos; text &apos; </element>";
XMLDocument doc(true, PRESERVE_WHITESPACE);
doc.Parse(xml);
XMLTest("Parse with whitespace preserved", false, doc.Error());
XMLTest("Whitespace preserved", " This \nis ' text ' ", doc.FirstChildElement()->GetText());
}
{
const char* xml = "<element> \n This is &apos; text &apos; \n</element>";
XMLDocument doc(true, PRESERVE_WHITESPACE);
doc.Parse(xml);
XMLTest("Parse with whitespace preserved", false, doc.Error());
XMLTest("Whitespace preserved", " \n This is ' text ' \n", doc.FirstChildElement()->GetText());
}
// Following cases are for text that is all whitespace which are not preserved intentionally
{
const char* xml = "<element> </element>";
XMLDocument doc(true, PRESERVE_WHITESPACE);
doc.Parse(xml);
XMLTest("Parse with whitespace preserved", false, doc.Error());
XMLTest("Whitespace preserved", true, 0 == doc.FirstChildElement()->GetText());
}
{
const char* xml = "<element> </element>";
XMLDocument doc(true, PRESERVE_WHITESPACE);
doc.Parse(xml);
XMLTest("Parse with whitespace preserved", false, doc.Error());
XMLTest("Whitespace preserved", true, 0 == doc.FirstChildElement()->GetText());
}
{
const char* xml = "<element>\n\n</element>";
XMLDocument doc(true, PRESERVE_WHITESPACE);
doc.Parse(xml);
XMLTest("Parse with whitespace preserved", false, doc.Error());
XMLTest("Whitespace preserved", true, 0 == doc.FirstChildElement()->GetText());
}
{
const char* xml = "<element> \n</element>";
XMLDocument doc(true, PRESERVE_WHITESPACE);
doc.Parse(xml);
XMLTest("Parse with whitespace preserved", false, doc.Error());
XMLTest("Whitespace preserved", true, 0 == doc.FirstChildElement()->GetText());
}
{
const char* xml = "<element> \n \n </element>";
XMLDocument doc(true, PRESERVE_WHITESPACE);
doc.Parse(xml);
XMLTest("Parse with whitespace preserved", false, doc.Error());
XMLTest("Whitespace preserved", true, 0 == doc.FirstChildElement()->GetText());
}
// ----------- Pedantic Whitespace ------------
{
const char* xml = "<element>This is &apos; \n\n text &apos;</element>";
XMLDocument doc(true, PEDANTIC_WHITESPACE);
doc.Parse(xml);
XMLTest("Parse with pedantic whitespace", false, doc.Error());
XMLTest("Pedantic whitespace", "This is ' \n\n text '", doc.FirstChildElement()->GetText());
}
{
const char* xml = "<element> This \nis &apos; text &apos; </element>";
XMLDocument doc(true, PEDANTIC_WHITESPACE);
doc.Parse(xml);
XMLTest("Parse with pedantic whitespace", false, doc.Error());
XMLTest("Pedantic whitespace", " This \nis ' text ' ", doc.FirstChildElement()->GetText());
}
{
const char* xml = "<element> \n This is &apos; text &apos; \n</element>";
XMLDocument doc(true, PEDANTIC_WHITESPACE);
doc.Parse(xml);
XMLTest("Parse with pedantic whitespace", false, doc.Error());
XMLTest("Pedantic whitespace", " \n This is ' text ' \n", doc.FirstChildElement()->GetText());
}
// Following cases are for text that is all whitespace which is preserved with pedantic mode
{
const char* xml = "<element> </element>";
XMLDocument doc(true, PEDANTIC_WHITESPACE);
doc.Parse(xml);
XMLTest("Parse with pedantic whitespace", false, doc.Error());
XMLTest("Pedantic whitespace", " ", doc.FirstChildElement()->GetText());
}
{
const char* xml = "<element> </element>";
XMLDocument doc(true, PEDANTIC_WHITESPACE);
doc.Parse(xml);
XMLTest("Parse with pedantic whitespace", false, doc.Error());
XMLTest("Pedantic whitespace", " ", doc.FirstChildElement()->GetText());
}
{
const char* xml = "<element>\n\n</element>\n";
XMLDocument doc(true, PEDANTIC_WHITESPACE);
doc.Parse(xml);
XMLTest("Parse with pedantic whitespace", false, doc.Error());
XMLTest("Pedantic whitespace", "\n\n", doc.FirstChildElement()->GetText());
}
{
const char* xml = "<element> \n</element> \n ";
XMLDocument doc(true, PEDANTIC_WHITESPACE);
doc.Parse(xml);
XMLTest("Parse with pedantic whitespace", false, doc.Error());
XMLTest("Pedantic whitespace", " \n", doc.FirstChildElement()->GetText());
}
{
const char* xml = "<element> \n \n </element> ";
XMLDocument doc(true, PEDANTIC_WHITESPACE);
doc.Parse(xml);
XMLTest("Parse with pedantic whitespace", false, doc.Error());
XMLTest("Pedantic whitespace", " \n \n ", doc.FirstChildElement()->GetText());
}
// Following cases are for checking nested elements are still parsed with pedantic whitespace
{
const char* xml = "<element>\n\t<a> This is nested text </a>\n</element> ";
XMLDocument doc(true, PEDANTIC_WHITESPACE);
doc.Parse(xml);
XMLTest("Parse nested elements with pedantic whitespace", false, doc.Error());
XMLTest("Pedantic whitespace", " This is nested text ", doc.RootElement()->FirstChildElement()->GetText());
}
{
const char* xml = "<element> <b> </b> </element>\n";
XMLDocument doc(true, PEDANTIC_WHITESPACE);
doc.Parse(xml);
XMLTest("Parse nested elements with pedantic whitespace", false, doc.Error());
XMLTest("Pedantic whitespace", " ", doc.RootElement()->FirstChildElement()->GetText());
}
{
const char* xml = "<element> <c attribute=\"test\"/> </element>\n ";
XMLDocument doc(true, PEDANTIC_WHITESPACE);
doc.Parse(xml);
XMLTest("Parse nested elements with pedantic whitespace", false, doc.Error());
XMLTest("Pedantic whitespace", true, 0 == doc.RootElement()->FirstChildElement()->GetText());
}
// Check sample xml can be parsed with pedantic mode
{
XMLDocument doc(true, PEDANTIC_WHITESPACE);
doc.LoadFile("resources/dream.xml");
XMLTest("Load dream.xml with pedantic whitespace mode", false, doc.Error());
XMLTest("Dream", "xml version=\"1.0\"",
doc.FirstChild()->ToDeclaration()->Value());
XMLTest("Dream", true, doc.FirstChild()->NextSibling()->ToUnknown() != 0);
XMLTest("Dream", "DOCTYPE PLAY SYSTEM \"play.dtd\"",
doc.FirstChild()->NextSibling()->ToUnknown()->Value());
XMLTest("Dream", "And Robin shall restore amends.",
doc.LastChild()->LastChild()->LastChild()->LastChild()->LastChildElement()->GetText());
}
{
// An assert should not fire.
const char* xml = "<element/>";
@@ -2152,6 +2324,12 @@ int main( int argc, const char ** argv )
doc.LoadFile("resources/dream.xml");
XMLTest("Error should be cleared", false, doc.Error());
doc.LoadFile( "resources/xmltest-5330.xml" );
XMLTest( "parse errors occur - should fail", true, doc.Error() );
doc.LoadFile( "resources/dream.xml" );
XMLTest( "Error should be cleared", false, doc.Error() );
}
{