]> git.saurik.com Git - wxWidgets.git/blame - contrib/utils/wxrcedit/xmlhelpr.cpp
generated code for wxGTK for all the changes made earlier today
[wxWidgets.git] / contrib / utils / wxrcedit / xmlhelpr.cpp
CommitLineData
56d2f750
VS
1/////////////////////////////////////////////////////////////////////////////
2// Author: Vaclav Slavik
3// Created: 2000/05/05
4// RCS-ID: $Id$
5// Copyright: (c) 2000 Vaclav Slavik
6// Licence: wxWindows licence
7/////////////////////////////////////////////////////////////////////////////
8
9#ifdef __GNUG__
10 #pragma implementation "xmlhelpr.h"
11#endif
12
13// For compilers that support precompilation, includes "wx/wx.h".
14#include "wx/wxprec.h"
15
16#ifdef __BORLANDC__
17 #pragma hdrstop
18#endif
19
20#include "wx/xml/xml.h"
21#include "wx/wx.h"
12d9e308 22#include "wx/tokenzr.h"
56d2f750
VS
23#include "xmlhelpr.h"
24
25
26
12d9e308 27wxXmlNode *XmlFindNodeSimple(wxXmlNode *parent, const wxString& param)
56d2f750 28{
12d9e308
VS
29 if (param.IsEmpty()) return parent;
30
56d2f750
VS
31 wxXmlNode *n = parent->GetChildren();
32
33 while (n)
34 {
35 if (n->GetType() == wxXML_ELEMENT_NODE && n->GetName() == param)
36 return n;
37 n = n->GetNext();
38 }
39 return NULL;
40}
41
42
12d9e308
VS
43
44wxXmlNode *XmlFindNode(wxXmlNode *parent, const wxString& path)
45{
46 wxXmlNode *n = parent;
47 wxStringTokenizer tkn(path, _T("/"));
48 while (tkn.HasMoreTokens())
49 {
50 n = XmlFindNodeSimple(n, tkn.GetNextToken());
51 if (n == NULL) break;
52 }
53 return n;
54}
55
56
57
a62da4c5 58wxXmlNode *XmlCreateNode(wxXmlNode *parent, const wxString& name)
56d2f750 59{
a62da4c5
VS
60 wxXmlNode *n;
61 wxString nm;
62
63 wxStringTokenizer tkn(name, _T("/"));
64 n = parent;
65 while (tkn.HasMoreTokens())
56d2f750 66 {
a62da4c5
VS
67 parent = n;
68 nm = tkn.GetNextToken();
69 n = XmlFindNodeSimple(parent, nm);
70 if (n) continue;
71
72 // n == NULL:
73 n = new wxXmlNode(wxXML_ELEMENT_NODE, nm);
74 parent->AddChild(n);
56d2f750 75 }
a62da4c5
VS
76 n->AddChild(new wxXmlNode(wxXML_TEXT_NODE, wxEmptyString));
77
78 return n;
79}
80
81
82
83void XmlWriteValue(wxXmlNode *parent, const wxString& name, const wxString& value)
84{
85 wxXmlNode *n = XmlFindNode(parent, name);
86 if (n == NULL)
87 n = XmlCreateNode(parent, name);
56d2f750
VS
88
89 n = n->GetChildren();
90
91 while (n)
92 {
93 if (n->GetType() == wxXML_TEXT_NODE ||
94 n->GetType() == wxXML_CDATA_SECTION_NODE)
95 {
96 n->SetContent(value);
97 break;
98 }
99 n = n->GetNext();
100 }
101}
102
103
104
105wxString XmlReadValue(wxXmlNode *parent, const wxString& name)
106{
107 wxXmlNode *n = XmlFindNode(parent, name);
108 if (n == NULL) return wxEmptyString;
109 n = n->GetChildren();
110
111 while (n)
112 {
113 if (n->GetType() == wxXML_TEXT_NODE ||
114 n->GetType() == wxXML_CDATA_SECTION_NODE)
115 return n->GetContent();
116 n = n->GetNext();
117 }
118 return wxEmptyString;
119}
120
121
122
e066e256
VS
123wxString XmlGetClass(wxXmlNode *parent)
124{
125 return parent->GetPropVal(_T("class"), wxEmptyString);
126}
127
128
129
130void XmlSetClass(wxXmlNode *parent, const wxString& classname)
131{
132 parent->DeleteProperty(_T("class"));
133 parent->AddProperty(_T("class"), classname);
134}
135
136
137
138
56d2f750 139