Compare commits
25 Commits
leethomaso
...
kcsaul-ped
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8d3cdf50db | ||
|
|
941e2d9018 | ||
|
|
428cd1be42 | ||
|
|
9d026527a4 | ||
|
|
4c27b08f62 | ||
|
|
ac23537e06 | ||
|
|
52035717a3 | ||
|
|
cc4c1df7ec | ||
|
|
98303bbda3 | ||
|
|
904ad04bea | ||
|
|
5926ec938a | ||
|
|
e05956094c | ||
|
|
9a89766acc | ||
|
|
9706d2cdc0 | ||
|
|
94f52b5cbe | ||
|
|
9ad3f2745b | ||
|
|
2555efa919 | ||
|
|
8fd6cc6d2d | ||
|
|
beb2b2f82d | ||
|
|
07f497d6d8 | ||
|
|
0691cf72b4 | ||
|
|
736659015c | ||
|
|
3e94e4a047 | ||
|
|
e45d9d16d4 | ||
|
|
9efb6b0b66 |
4
.github/workflows/test.yml
vendored
4
.github/workflows/test.yml
vendored
@@ -6,7 +6,7 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [ windows-2019, macos-10.15, ubuntu-20.04 ]
|
os: [ windows-2019, macos-latest, ubuntu-20.04 ]
|
||||||
cmake: [ 3.15, 3.x ]
|
cmake: [ 3.15, 3.x ]
|
||||||
include:
|
include:
|
||||||
- os: windows-2019
|
- os: windows-2019
|
||||||
@@ -17,7 +17,7 @@ jobs:
|
|||||||
- os: ubuntu-20.04
|
- os: ubuntu-20.04
|
||||||
tree: tree
|
tree: tree
|
||||||
|
|
||||||
- os: macos-10.15
|
- os: macos-latest
|
||||||
tree: find
|
tree: find
|
||||||
|
|
||||||
- cmake: 3.15
|
- cmake: 3.15
|
||||||
|
|||||||
18
readme.md
18
readme.md
@@ -1,9 +1,7 @@
|
|||||||
TinyXML-2
|
TinyXML-2
|
||||||
=========
|
=========
|
||||||
|
|
||||||

|
[](https://github.com/leethomason/tinyxml2/actions/workflows/test.yml)
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
TinyXML-2 is a simple, small, efficient, C++ XML parser that can be
|
TinyXML-2 is a simple, small, efficient, C++ XML parser that can be
|
||||||
easily integrated into other programs.
|
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
|
### 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
|
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>
|
<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
|
For some applications, it is preferable to collapse whitespace. Collapsing
|
||||||
whitespace gives you "HTML-like" behavior, which is sometimes more suitable
|
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.
|
Note that (currently) there is a performance impact for using COLLAPSE_WHITESPACE.
|
||||||
It essentially causes the XML to be parsed twice.
|
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
|
TinyXML-2 reports the line number of any errors in an XML document that
|
||||||
cannot be parsed correctly. In addition, all nodes (elements, declarations,
|
cannot be parsed correctly. In addition, all nodes (elements, declarations,
|
||||||
|
|||||||
50
tinyxml2.cpp
50
tinyxml2.cpp
@@ -715,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( node );
|
||||||
TIXMLASSERT( p );
|
TIXMLASSERT( p );
|
||||||
@@ -767,10 +767,20 @@ char* XMLDocument::Identify( char* p, XMLNode** node )
|
|||||||
p += dtdHeaderLen;
|
p += dtdHeaderLen;
|
||||||
}
|
}
|
||||||
else if ( XMLUtil::StringEqual( p, elementHeader, elementHeaderLen ) ) {
|
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 = CreateUnlinkedNode<XMLElement>(_elementPool);
|
||||||
returnNode->_parseLineNum = _parseCurLineNum;
|
returnNode->_parseLineNum = _parseCurLineNum;
|
||||||
p += elementHeaderLen;
|
p += elementHeaderLen;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
returnNode = CreateUnlinkedNode<XMLText>( _textPool );
|
returnNode = CreateUnlinkedNode<XMLText>( _textPool );
|
||||||
returnNode->_parseLineNum = _parseCurLineNum; // Report line of first non-whitespace character
|
returnNode->_parseLineNum = _parseCurLineNum; // Report line of first non-whitespace character
|
||||||
@@ -822,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
|
const char* XMLNode::Value() const
|
||||||
{
|
{
|
||||||
// Edge case: XMLDocuments don't have a Value. Return null.
|
// Edge case: XMLDocuments don't have a Value. Return null.
|
||||||
@@ -1070,21 +1108,23 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr )
|
|||||||
if (_document->Error())
|
if (_document->Error())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
bool first = true;
|
||||||
while( p && *p ) {
|
while( p && *p ) {
|
||||||
XMLNode* node = 0;
|
XMLNode* node = 0;
|
||||||
|
|
||||||
p = _document->Identify( p, &node );
|
p = _document->Identify( p, &node, first );
|
||||||
TIXMLASSERT( p );
|
TIXMLASSERT( p );
|
||||||
if ( node == 0 ) {
|
if ( node == 0 ) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
first = false;
|
||||||
|
|
||||||
const int initialLineNum = node->_parseLineNum;
|
const int initialLineNum = node->_parseLineNum;
|
||||||
|
|
||||||
StrPair endTag;
|
StrPair endTag;
|
||||||
p = node->ParseDeep( p, &endTag, curLineNumPtr );
|
p = node->ParseDeep( p, &endTag, curLineNumPtr );
|
||||||
if ( !p ) {
|
if ( !p ) {
|
||||||
DeleteNode( node );
|
_document->DeleteNode( node );
|
||||||
if ( !_document->Error() ) {
|
if ( !_document->Error() ) {
|
||||||
_document->SetError( XML_ERROR_PARSING, initialLineNum, 0);
|
_document->SetError( XML_ERROR_PARSING, initialLineNum, 0);
|
||||||
}
|
}
|
||||||
@@ -1117,7 +1157,7 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr )
|
|||||||
}
|
}
|
||||||
if ( !wellLocated ) {
|
if ( !wellLocated ) {
|
||||||
_document->SetError( XML_ERROR_PARSING_DECLARATION, initialLineNum, "XMLDeclaration value=%s", decl->Value());
|
_document->SetError( XML_ERROR_PARSING_DECLARATION, initialLineNum, "XMLDeclaration value=%s", decl->Value());
|
||||||
DeleteNode( node );
|
_document->DeleteNode( node );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1152,7 +1192,7 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr )
|
|||||||
}
|
}
|
||||||
if ( mismatch ) {
|
if ( mismatch ) {
|
||||||
_document->SetError( XML_ERROR_MISMATCHED_ELEMENT, initialLineNum, "XMLElement name=%s", ele->Name());
|
_document->SetError( XML_ERROR_MISMATCHED_ELEMENT, initialLineNum, "XMLElement name=%s", ele->Name());
|
||||||
DeleteNode( node );
|
_document->DeleteNode( node );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
121
tinyxml2.h
121
tinyxml2.h
@@ -64,7 +64,7 @@ distribution.
|
|||||||
# pragma warning(disable: 4251)
|
# pragma warning(disable: 4251)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _MSC_VER
|
||||||
# ifdef TINYXML2_EXPORT
|
# ifdef TINYXML2_EXPORT
|
||||||
# define TINYXML2_LIB __declspec(dllexport)
|
# define TINYXML2_LIB __declspec(dllexport)
|
||||||
# elif defined(TINYXML2_IMPORT)
|
# 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
|
// 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,
|
// attack that can result from ill, malicious, or even correctly formed XML,
|
||||||
// so there needs to be a limit in place.
|
// 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
|
namespace tinyxml2
|
||||||
{
|
{
|
||||||
@@ -305,9 +305,9 @@ private:
|
|||||||
if ( cap > _allocated ) {
|
if ( cap > _allocated ) {
|
||||||
TIXMLASSERT( cap <= INT_MAX / 2 );
|
TIXMLASSERT( cap <= INT_MAX / 2 );
|
||||||
const int newAllocated = cap * 2;
|
const int newAllocated = cap * 2;
|
||||||
T* newMem = new T[newAllocated];
|
T* newMem = new T[static_cast<unsigned int>(newAllocated)];
|
||||||
TIXMLASSERT( newAllocated >= _size );
|
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 ) {
|
if ( _mem != _pool ) {
|
||||||
delete [] _mem;
|
delete [] _mem;
|
||||||
}
|
}
|
||||||
@@ -317,7 +317,7 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
T* _mem;
|
T* _mem;
|
||||||
T _pool[INITIAL_SIZE];
|
T _pool[static_cast<size_t>(INITIAL_SIZE)];
|
||||||
int _allocated; // objects allocated
|
int _allocated; // objects allocated
|
||||||
int _size; // number objects in use
|
int _size; // number objects in use
|
||||||
};
|
};
|
||||||
@@ -365,17 +365,17 @@ public:
|
|||||||
_nUntracked = 0;
|
_nUntracked = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual int ItemSize() const {
|
virtual int ItemSize() const override{
|
||||||
return ITEM_SIZE;
|
return ITEM_SIZE;
|
||||||
}
|
}
|
||||||
int CurrentAllocs() const {
|
int CurrentAllocs() const {
|
||||||
return _currentAllocs;
|
return _currentAllocs;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void* Alloc() {
|
virtual void* Alloc() override{
|
||||||
if ( !_root ) {
|
if ( !_root ) {
|
||||||
// Need a new block.
|
// Need a new block.
|
||||||
Block* block = new Block();
|
Block* block = new Block;
|
||||||
_blockPtrs.Push( block );
|
_blockPtrs.Push( block );
|
||||||
|
|
||||||
Item* blockItems = block->items;
|
Item* blockItems = block->items;
|
||||||
@@ -398,7 +398,7 @@ public:
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void Free( void* mem ) {
|
virtual void Free( void* mem ) override {
|
||||||
if ( !mem ) {
|
if ( !mem ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -416,7 +416,7 @@ public:
|
|||||||
ITEM_SIZE, _nAllocs, _blockPtrs.Size() );
|
ITEM_SIZE, _nAllocs, _blockPtrs.Size() );
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetTracked() {
|
void SetTracked() override {
|
||||||
--_nUntracked;
|
--_nUntracked;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -443,7 +443,7 @@ private:
|
|||||||
|
|
||||||
union Item {
|
union Item {
|
||||||
Item* next;
|
Item* next;
|
||||||
char itemData[ITEM_SIZE];
|
char itemData[static_cast<size_t>(ITEM_SIZE)];
|
||||||
};
|
};
|
||||||
struct Block {
|
struct Block {
|
||||||
Item items[ITEMS_PER_BLOCK];
|
Item items[ITEMS_PER_BLOCK];
|
||||||
@@ -603,7 +603,7 @@ public:
|
|||||||
TIXMLASSERT( p );
|
TIXMLASSERT( p );
|
||||||
TIXMLASSERT( q );
|
TIXMLASSERT( q );
|
||||||
TIXMLASSERT( nChar >= 0 );
|
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 ) {
|
inline static bool IsUTF8Continuation( const char p ) {
|
||||||
@@ -732,6 +732,12 @@ public:
|
|||||||
return 0;
|
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.
|
/** The meaning of 'value' changes for the specific type.
|
||||||
@verbatim
|
@verbatim
|
||||||
Document: empty (NULL is returned, not an empty string)
|
Document: empty (NULL is returned, not an empty string)
|
||||||
@@ -992,12 +998,12 @@ class TINYXML2_LIB XMLText : public XMLNode
|
|||||||
{
|
{
|
||||||
friend class XMLDocument;
|
friend class XMLDocument;
|
||||||
public:
|
public:
|
||||||
virtual bool Accept( XMLVisitor* visitor ) const;
|
virtual bool Accept( XMLVisitor* visitor ) const override;
|
||||||
|
|
||||||
virtual XMLText* ToText() {
|
virtual XMLText* ToText() override {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
virtual const XMLText* ToText() const {
|
virtual const XMLText* ToText() const override {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1010,14 +1016,14 @@ public:
|
|||||||
return _isCData;
|
return _isCData;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual XMLNode* ShallowClone( XMLDocument* document ) const;
|
virtual XMLNode* ShallowClone( XMLDocument* document ) const override;
|
||||||
virtual bool ShallowEqual( const XMLNode* compare ) const;
|
virtual bool ShallowEqual( const XMLNode* compare ) const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit XMLText( XMLDocument* doc ) : XMLNode( doc ), _isCData( false ) {}
|
explicit XMLText( XMLDocument* doc ) : XMLNode( doc ), _isCData( false ) {}
|
||||||
virtual ~XMLText() {}
|
virtual ~XMLText() {}
|
||||||
|
|
||||||
char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr );
|
char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr ) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool _isCData;
|
bool _isCData;
|
||||||
@@ -1032,23 +1038,23 @@ class TINYXML2_LIB XMLComment : public XMLNode
|
|||||||
{
|
{
|
||||||
friend class XMLDocument;
|
friend class XMLDocument;
|
||||||
public:
|
public:
|
||||||
virtual XMLComment* ToComment() {
|
virtual XMLComment* ToComment() override {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
virtual const XMLComment* ToComment() const {
|
virtual const XMLComment* ToComment() const override {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool Accept( XMLVisitor* visitor ) const;
|
virtual bool Accept( XMLVisitor* visitor ) const override;
|
||||||
|
|
||||||
virtual XMLNode* ShallowClone( XMLDocument* document ) const;
|
virtual XMLNode* ShallowClone( XMLDocument* document ) const override;
|
||||||
virtual bool ShallowEqual( const XMLNode* compare ) const;
|
virtual bool ShallowEqual( const XMLNode* compare ) const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit XMLComment( XMLDocument* doc );
|
explicit XMLComment( XMLDocument* doc );
|
||||||
virtual ~XMLComment();
|
virtual ~XMLComment();
|
||||||
|
|
||||||
char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr);
|
char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
XMLComment( const XMLComment& ); // not supported
|
XMLComment( const XMLComment& ); // not supported
|
||||||
@@ -1071,23 +1077,23 @@ class TINYXML2_LIB XMLDeclaration : public XMLNode
|
|||||||
{
|
{
|
||||||
friend class XMLDocument;
|
friend class XMLDocument;
|
||||||
public:
|
public:
|
||||||
virtual XMLDeclaration* ToDeclaration() {
|
virtual XMLDeclaration* ToDeclaration() override {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
virtual const XMLDeclaration* ToDeclaration() const {
|
virtual const XMLDeclaration* ToDeclaration() const override {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool Accept( XMLVisitor* visitor ) const;
|
virtual bool Accept( XMLVisitor* visitor ) const override;
|
||||||
|
|
||||||
virtual XMLNode* ShallowClone( XMLDocument* document ) const;
|
virtual XMLNode* ShallowClone( XMLDocument* document ) const override;
|
||||||
virtual bool ShallowEqual( const XMLNode* compare ) const;
|
virtual bool ShallowEqual( const XMLNode* compare ) const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit XMLDeclaration( XMLDocument* doc );
|
explicit XMLDeclaration( XMLDocument* doc );
|
||||||
virtual ~XMLDeclaration();
|
virtual ~XMLDeclaration();
|
||||||
|
|
||||||
char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr );
|
char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr ) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
XMLDeclaration( const XMLDeclaration& ); // not supported
|
XMLDeclaration( const XMLDeclaration& ); // not supported
|
||||||
@@ -1106,23 +1112,23 @@ class TINYXML2_LIB XMLUnknown : public XMLNode
|
|||||||
{
|
{
|
||||||
friend class XMLDocument;
|
friend class XMLDocument;
|
||||||
public:
|
public:
|
||||||
virtual XMLUnknown* ToUnknown() {
|
virtual XMLUnknown* ToUnknown() override {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
virtual const XMLUnknown* ToUnknown() const {
|
virtual const XMLUnknown* ToUnknown() const override {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool Accept( XMLVisitor* visitor ) const;
|
virtual bool Accept( XMLVisitor* visitor ) const override;
|
||||||
|
|
||||||
virtual XMLNode* ShallowClone( XMLDocument* document ) const;
|
virtual XMLNode* ShallowClone( XMLDocument* document ) const override;
|
||||||
virtual bool ShallowEqual( const XMLNode* compare ) const;
|
virtual bool ShallowEqual( const XMLNode* compare ) const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit XMLUnknown( XMLDocument* doc );
|
explicit XMLUnknown( XMLDocument* doc );
|
||||||
virtual ~XMLUnknown();
|
virtual ~XMLUnknown();
|
||||||
|
|
||||||
char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr );
|
char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr ) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
XMLUnknown( const XMLUnknown& ); // not supported
|
XMLUnknown( const XMLUnknown& ); // not supported
|
||||||
@@ -1274,13 +1280,13 @@ public:
|
|||||||
SetValue( str, staticMem );
|
SetValue( str, staticMem );
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual XMLElement* ToElement() {
|
virtual XMLElement* ToElement() override {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
virtual const XMLElement* ToElement() const {
|
virtual const XMLElement* ToElement() const override {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
virtual bool Accept( XMLVisitor* visitor ) const;
|
virtual bool Accept( XMLVisitor* visitor ) const override;
|
||||||
|
|
||||||
/** Given an attribute name, Attribute() returns the value
|
/** Given an attribute name, Attribute() returns the value
|
||||||
for the attribute of that name, or null if none
|
for the attribute of that name, or null if none
|
||||||
@@ -1676,11 +1682,11 @@ public:
|
|||||||
ElementClosingType ClosingType() const {
|
ElementClosingType ClosingType() const {
|
||||||
return _closingType;
|
return _closingType;
|
||||||
}
|
}
|
||||||
virtual XMLNode* ShallowClone( XMLDocument* document ) const;
|
virtual XMLNode* ShallowClone( XMLDocument* document ) const override;
|
||||||
virtual bool ShallowEqual( const XMLNode* compare ) const;
|
virtual bool ShallowEqual( const XMLNode* compare ) const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr );
|
char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr ) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
XMLElement( XMLDocument* doc );
|
XMLElement( XMLDocument* doc );
|
||||||
@@ -1704,7 +1710,8 @@ private:
|
|||||||
|
|
||||||
enum Whitespace {
|
enum Whitespace {
|
||||||
PRESERVE_WHITESPACE,
|
PRESERVE_WHITESPACE,
|
||||||
COLLAPSE_WHITESPACE
|
COLLAPSE_WHITESPACE,
|
||||||
|
PEDANTIC_WHITESPACE
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -1728,11 +1735,11 @@ public:
|
|||||||
XMLDocument( bool processEntities = true, Whitespace whitespaceMode = PRESERVE_WHITESPACE );
|
XMLDocument( bool processEntities = true, Whitespace whitespaceMode = PRESERVE_WHITESPACE );
|
||||||
~XMLDocument();
|
~XMLDocument();
|
||||||
|
|
||||||
virtual XMLDocument* ToDocument() {
|
virtual XMLDocument* ToDocument() override {
|
||||||
TIXMLASSERT( this == _document );
|
TIXMLASSERT( this == _document );
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
virtual const XMLDocument* ToDocument() const {
|
virtual const XMLDocument* ToDocument() const override {
|
||||||
TIXMLASSERT( this == _document );
|
TIXMLASSERT( this == _document );
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -1829,7 +1836,7 @@ public:
|
|||||||
@endverbatim
|
@endverbatim
|
||||||
*/
|
*/
|
||||||
void Print( XMLPrinter* streamer=0 ) const;
|
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
|
Create a new Element associated with
|
||||||
@@ -1915,15 +1922,15 @@ public:
|
|||||||
void DeepCopy(XMLDocument* target) const;
|
void DeepCopy(XMLDocument* target) const;
|
||||||
|
|
||||||
// internal
|
// internal
|
||||||
char* Identify( char* p, XMLNode** node );
|
char* Identify( char* p, XMLNode** node, bool first );
|
||||||
|
|
||||||
// internal
|
// internal
|
||||||
void MarkInUse(const XMLNode* const);
|
void MarkInUse(const XMLNode* const);
|
||||||
|
|
||||||
virtual XMLNode* ShallowClone( XMLDocument* /*document*/ ) const {
|
virtual XMLNode* ShallowClone( XMLDocument* /*document*/ ) const override{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
virtual bool ShallowEqual( const XMLNode* /*compare*/ ) const {
|
virtual bool ShallowEqual( const XMLNode* /*compare*/ ) const override{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2286,18 +2293,18 @@ public:
|
|||||||
void PushDeclaration( const char* value );
|
void PushDeclaration( const char* value );
|
||||||
void PushUnknown( const char* value );
|
void PushUnknown( const char* value );
|
||||||
|
|
||||||
virtual bool VisitEnter( const XMLDocument& /*doc*/ );
|
virtual bool VisitEnter( const XMLDocument& /*doc*/ ) override;
|
||||||
virtual bool VisitExit( const XMLDocument& /*doc*/ ) {
|
virtual bool VisitExit( const XMLDocument& /*doc*/ ) override {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool VisitEnter( const XMLElement& element, const XMLAttribute* attribute );
|
virtual bool VisitEnter( const XMLElement& element, const XMLAttribute* attribute ) override;
|
||||||
virtual bool VisitExit( const XMLElement& element );
|
virtual bool VisitExit( const XMLElement& element ) override;
|
||||||
|
|
||||||
virtual bool Visit( const XMLText& text );
|
virtual bool Visit( const XMLText& text ) override;
|
||||||
virtual bool Visit( const XMLComment& comment );
|
virtual bool Visit( const XMLComment& comment ) override;
|
||||||
virtual bool Visit( const XMLDeclaration& declaration );
|
virtual bool Visit( const XMLDeclaration& declaration ) override;
|
||||||
virtual bool Visit( const XMLUnknown& unknown );
|
virtual bool Visit( const XMLUnknown& unknown ) override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
If in print to memory mode, return a pointer to
|
If in print to memory mode, return a pointer to
|
||||||
|
|||||||
@@ -29,26 +29,26 @@
|
|||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>true</UseDebugLibraries>
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
<PlatformToolset>v142</PlatformToolset>
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
<CharacterSet>Unicode</CharacterSet>
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>false</UseDebugLibraries>
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
<PlatformToolset>v142</PlatformToolset>
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
<CharacterSet>Unicode</CharacterSet>
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>true</UseDebugLibraries>
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
<PlatformToolset>v142</PlatformToolset>
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
<CharacterSet>Unicode</CharacterSet>
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>false</UseDebugLibraries>
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
<PlatformToolset>v142</PlatformToolset>
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
<CharacterSet>Unicode</CharacterSet>
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|||||||
178
xmltest.cpp
178
xmltest.cpp
@@ -1869,6 +1869,178 @@ int main( int argc, const char ** argv )
|
|||||||
XMLTest( "Whitespace all space", true, 0 == doc.FirstChildElement()->FirstChild() );
|
XMLTest( "Whitespace all space", true, 0 == doc.FirstChildElement()->FirstChild() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------- Preserve Whitespace ------------
|
||||||
|
{
|
||||||
|
const char* xml = "<element>This is ' \n\n text '</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 ' text ' </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 ' text ' \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 ' \n\n text '</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 ' text ' </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 ' text ' \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.
|
// An assert should not fire.
|
||||||
const char* xml = "<element/>";
|
const char* xml = "<element/>";
|
||||||
@@ -2152,6 +2324,12 @@ int main( int argc, const char ** argv )
|
|||||||
|
|
||||||
doc.LoadFile("resources/dream.xml");
|
doc.LoadFile("resources/dream.xml");
|
||||||
XMLTest("Error should be cleared", false, doc.Error());
|
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() );
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user