Просмотр исходного кода

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.
Sarat Addepalli 10 лет назад
Родитель
Сommit
a0f499dda1
1 измененных файлов с 12 добавлено и 1 удалено
  1. 12 1
      tinyxml2.cpp

+ 12 - 1
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.