]>
Commit | Line | Data |
---|---|---|
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/xrc/xml.h" | |
21 | #include "wx/wx.h" | |
22 | #include "wx/tokenzr.h" | |
23 | #include "xmlhelpr.h" | |
24 | ||
25 | ||
26 | ||
27 | wxXmlNode *XmlFindNodeSimple(wxXmlNode *parent, const wxString& param) | |
28 | { | |
29 | if (param.IsEmpty()) return parent; | |
30 | ||
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 | ||
43 | ||
44 | wxXmlNode *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 | ||
58 | wxXmlNode *XmlCreateNode(wxXmlNode *parent, const wxString& name) | |
59 | { | |
60 | wxXmlNode *n; | |
61 | wxString nm; | |
62 | ||
63 | wxStringTokenizer tkn(name, _T("/")); | |
64 | n = parent; | |
65 | while (tkn.HasMoreTokens()) | |
66 | { | |
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); | |
75 | } | |
76 | n->AddChild(new wxXmlNode(wxXML_TEXT_NODE, wxEmptyString)); | |
77 | ||
78 | return n; | |
79 | } | |
80 | ||
81 | ||
82 | ||
83 | void 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); | |
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 | ||
105 | wxString 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 | ||
123 | wxString XmlGetClass(wxXmlNode *parent) | |
124 | { | |
125 | return parent->GetPropVal(_T("class"), wxEmptyString); | |
126 | } | |
127 | ||
128 | ||
129 | ||
130 | void XmlSetClass(wxXmlNode *parent, const wxString& classname) | |
131 | { | |
132 | parent->DeleteProperty(_T("class")); | |
133 | parent->AddProperty(_T("class"), classname); | |
134 | } | |
135 | ||
136 | ||
137 | ||
138 | ||
139 |