+wxXmlNode *wxXmlDocument::GetRoot() const
+{
+ wxXmlNode *node = m_docNode;
+ if (node)
+ {
+ node = m_docNode->GetChildren();
+ while (node != NULL && node->GetType() != wxXML_ELEMENT_NODE)
+ node = node->GetNext();
+ }
+ return node;
+}
+
+wxXmlNode *wxXmlDocument::DetachRoot()
+{
+ wxXmlNode *node = m_docNode;
+ if (node)
+ {
+ node = m_docNode->GetChildren();
+ wxXmlNode *prev = NULL;
+ while (node != NULL && node->GetType() != wxXML_ELEMENT_NODE)
+ {
+ prev = node;
+ node = node->GetNext();
+ }
+ if (node)
+ {
+ if (node == m_docNode->GetChildren())
+ m_docNode->SetChildren(node->GetNext());
+
+ if (prev)
+ prev->SetNext(node->GetNext());
+
+ node->SetParent(NULL);
+ node->SetNext(NULL);
+ }
+ }
+ return node;
+}
+
+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)
+ {
+ node = m_docNode->GetChildren();
+ wxXmlNode *prev = NULL;
+ while (node != NULL && node->GetType() != wxXML_ELEMENT_NODE)
+ {
+ prev = node;
+ node = node->GetNext();
+ }
+ if (node && root)
+ {
+ root->SetNext( node->GetNext() );
+ wxDELETE(node);
+ }
+ if (prev)
+ prev->SetNext(root);
+ else
+ m_docNode->SetChildren(root);
+ }
+ else
+ {
+ m_docNode = new wxXmlNode(wxXML_DOCUMENT_NODE, wxEmptyString);
+ m_docNode->SetChildren(root);
+ }
+ if (root)
+ root->SetParent(m_docNode);
+}