Merge pull request #496 from Dmitry-Me/detectDeclarationPlacement
Declarations should occur before anything else
This commit is contained in:
20
tinyxml2.cpp
20
tinyxml2.cpp
@@ -982,13 +982,23 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEnd )
|
||||
|
||||
XMLDeclaration* decl = node->ToDeclaration();
|
||||
if ( decl ) {
|
||||
// A declaration can only be the first child of a document.
|
||||
// Set error, if document already has children.
|
||||
if ( !_document->NoChildren() ) {
|
||||
_document->SetError( XML_ERROR_PARSING_DECLARATION, decl->Value(), 0);
|
||||
DeleteNode( node );
|
||||
// Declarations are only allowed at document level
|
||||
bool wellLocated = ( ToDocument() != 0 );
|
||||
if ( wellLocated ) {
|
||||
// Multiple declarations are allowed but all declarations
|
||||
// must occur before anything else
|
||||
for ( const XMLNode* existingNode = _document->FirstChild(); existingNode; existingNode = existingNode->NextSibling() ) {
|
||||
if ( !existingNode->ToDeclaration() ) {
|
||||
wellLocated = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( !wellLocated ) {
|
||||
_document->SetError( XML_ERROR_PARSING_DECLARATION, decl->Value(), 0 );
|
||||
DeleteNode( node );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
XMLElement* ele = node->ToElement();
|
||||
|
||||
Reference in New Issue
Block a user