X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/cee8636e94d49319b1c108d8b2d826e080e2e366..c7e94140cd436c6c234a382ad4e16ec5da65830c:/src/xml/xml.cpp diff --git a/src/xml/xml.cpp b/src/xml/xml.cpp index 0e82fffd01..f9209d0fff 100644 --- a/src/xml/xml.cpp +++ b/src/xml/xml.cpp @@ -505,6 +505,12 @@ wxXmlNode *wxXmlDocument::DetachRoot() void wxXmlDocument::SetRoot(wxXmlNode *root) { + if (root) + { + wxASSERT_MSG( root->GetType() == wxXML_ELEMENT_NODE, + "Can only set an element type node as root" ); + } + wxXmlNode *node = m_docNode; if (node) { @@ -515,7 +521,7 @@ void wxXmlDocument::SetRoot(wxXmlNode *root) prev = node; node = node->GetNext(); } - if (node) + if (node && root) { root->SetNext( node->GetNext() ); wxDELETE(node); @@ -528,8 +534,10 @@ void wxXmlDocument::SetRoot(wxXmlNode *root) else { m_docNode = new wxXmlNode(wxXML_DOCUMENT_NODE, wxEmptyString); + m_docNode->SetChildren(root); } - root->SetParent(m_docNode); + if (root) + root->SetParent(m_docNode); } void wxXmlDocument::AppendToProlog(wxXmlNode *node)