Fix wxXmlDocument::SetRoot() broken by recent changes.

Support for wxXML_PI_NODE introduced in r67346 broke SetRoot() and, because of
this, saving XML documents.

Correct this and add a unit test for this method.

Closes #13135.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@67519 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2011-04-17 00:09:45 +00:00
parent 32bd17fcb5
commit 6f24b81707
2 changed files with 55 additions and 2 deletions

View File

@@ -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)