From a0f499dda1ad45306e7f19de45a851c1124837ee Mon Sep 17 00:00:00 2001 From: Sarat Addepalli Date: Mon, 18 May 2015 09:25:17 +0530 Subject: [PATCH] Fix ParseDeep() to close issue #332 If the node to be added is an XML Declaration, then check if the document has any children already. XML Declarations can only be the FirstChild() s of an XML Document. --- tinyxml2.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tinyxml2.cpp b/tinyxml2.cpp index 6e1985b..a6f1a9f 100755 --- a/tinyxml2.cpp +++ b/tinyxml2.cpp @@ -886,7 +886,18 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEnd ) } break; } - + + XMLElement* ele = 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( decl ); + break; + } + } + XMLElement* ele = node->ToElement(); if ( ele ) { // We read the end tag. Return it to the parent.