2000-07-25 18:47:21 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Author: Vaclav Slavik
|
|
|
|
// Created: 2000/05/05
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) 2000 Vaclav Slavik
|
|
|
|
// Licence: wxWindows licence
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation "xmlhelpr.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// For compilers that support precompilation, includes "wx/wx.h".
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "wx/xml/xml.h"
|
|
|
|
#include "wx/wx.h"
|
2000-11-04 23:34:33 +00:00
|
|
|
#include "wx/tokenzr.h"
|
2000-07-25 18:47:21 +00:00
|
|
|
#include "xmlhelpr.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-11-04 23:34:33 +00:00
|
|
|
wxXmlNode *XmlFindNodeSimple(wxXmlNode *parent, const wxString& param)
|
2000-07-25 18:47:21 +00:00
|
|
|
{
|
2000-11-04 23:34:33 +00:00
|
|
|
if (param.IsEmpty()) return parent;
|
|
|
|
|
2000-07-25 18:47:21 +00:00
|
|
|
wxXmlNode *n = parent->GetChildren();
|
|
|
|
|
|
|
|
while (n)
|
|
|
|
{
|
|
|
|
if (n->GetType() == wxXML_ELEMENT_NODE && n->GetName() == param)
|
|
|
|
return n;
|
|
|
|
n = n->GetNext();
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-11-04 23:34:33 +00:00
|
|
|
|
|
|
|
wxXmlNode *XmlFindNode(wxXmlNode *parent, const wxString& path)
|
|
|
|
{
|
|
|
|
wxXmlNode *n = parent;
|
|
|
|
wxStringTokenizer tkn(path, _T("/"));
|
|
|
|
while (tkn.HasMoreTokens())
|
|
|
|
{
|
|
|
|
n = XmlFindNodeSimple(n, tkn.GetNextToken());
|
|
|
|
if (n == NULL) break;
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-07-25 18:47:21 +00:00
|
|
|
void XmlWriteValue(wxXmlNode *parent, const wxString& name, const wxString& value)
|
|
|
|
{
|
|
|
|
wxXmlNode *n = XmlFindNode(parent, name);
|
|
|
|
if (n == NULL)
|
|
|
|
{
|
2000-11-04 23:34:33 +00:00
|
|
|
wxString pname = name.BeforeLast(_T('/'));
|
|
|
|
if (pname.IsEmpty()) pname = name;
|
|
|
|
wxXmlNode *p = XmlFindNode(parent, pname);
|
|
|
|
if (p == NULL) p = parent;
|
|
|
|
n = new wxXmlNode(wxXML_ELEMENT_NODE, name.AfterLast(_T('/')));
|
|
|
|
p->AddChild(n);
|
|
|
|
n->AddChild(new wxXmlNode(wxXML_TEXT_NODE, wxEmptyString));
|
2000-07-25 18:47:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
n = n->GetChildren();
|
|
|
|
|
|
|
|
while (n)
|
|
|
|
{
|
|
|
|
if (n->GetType() == wxXML_TEXT_NODE ||
|
|
|
|
n->GetType() == wxXML_CDATA_SECTION_NODE)
|
|
|
|
{
|
|
|
|
n->SetContent(value);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
n = n->GetNext();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wxString XmlReadValue(wxXmlNode *parent, const wxString& name)
|
|
|
|
{
|
|
|
|
wxXmlNode *n = XmlFindNode(parent, name);
|
|
|
|
if (n == NULL) return wxEmptyString;
|
|
|
|
n = n->GetChildren();
|
|
|
|
|
|
|
|
while (n)
|
|
|
|
{
|
|
|
|
if (n->GetType() == wxXML_TEXT_NODE ||
|
|
|
|
n->GetType() == wxXML_CDATA_SECTION_NODE)
|
|
|
|
return n->GetContent();
|
|
|
|
n = n->GetNext();
|
|
|
|
}
|
|
|
|
return wxEmptyString;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-10-07 21:56:37 +00:00
|
|
|
wxString XmlGetClass(wxXmlNode *parent)
|
|
|
|
{
|
|
|
|
return parent->GetPropVal(_T("class"), wxEmptyString);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void XmlSetClass(wxXmlNode *parent, const wxString& classname)
|
|
|
|
{
|
|
|
|
parent->DeleteProperty(_T("class"));
|
|
|
|
parent->AddProperty(_T("class"), classname);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-07-25 18:47:21 +00:00
|
|
|
|