m_lineNo(lineNo),
m_noConversion(false)
{
+ wxASSERT_MSG ( type != wxXML_ELEMENT_NODE || content.empty(), "element nodes can't have content" );
+
if (m_parent)
{
if (m_parent->m_children)
m_attrs(NULL), m_parent(NULL),
m_children(NULL), m_next(NULL),
m_lineNo(lineNo), m_noConversion(false)
-{}
+{
+ wxASSERT_MSG ( type != wxXML_ELEMENT_NODE || content.empty(), "element nodes can't have content" );
+}
wxXmlNode::wxXmlNode(const wxXmlNode& node)
{
}
wxXmlNode::~wxXmlNode()
+{
+ DoFree();
+}
+
+wxXmlNode& wxXmlNode::operator=(const wxXmlNode& node)
+{
+ if ( &node != this )
+ {
+ DoFree();
+ DoCopy(node);
+ }
+
+ return *this;
+}
+
+void wxXmlNode::DoFree()
{
wxXmlNode *c, *c2;
for (c = m_children; c; c = c2)
}
}
-wxXmlNode& wxXmlNode::operator=(const wxXmlNode& node)
-{
- wxDELETE(m_attrs);
- wxDELETE(m_children);
- DoCopy(node);
- return *this;
-}
-
void wxXmlNode::DoCopy(const wxXmlNode& node)
{
m_type = node.m_type;
bool wxXmlDocument::Load(const wxString& filename, const wxString& encoding, int flags)
{
wxFileInputStream stream(filename);
- if (!stream.Ok())
+ if (!stream.IsOk())
return false;
return Load(stream, encoding, flags);
}
bool wxXmlDocument::Save(const wxString& filename, int indentstep) const
{
wxFileOutputStream stream(filename);
- if (!stream.Ok())
+ if (!stream.IsOk())
return false;
return Save(stream, indentstep);
}
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)
{
prev = node;
node = node->GetNext();
}
- if (node)
+ if (node && root)
{
root->SetNext( node->GetNext() );
wxDELETE(node);
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)