]>
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/xml/xml.h" | |
21 | #include "wx/wx.h" | |
22 | #include "xmlhelpr.h" | |
23 | ||
24 | ||
25 | ||
26 | wxXmlNode *XmlFindNode(wxXmlNode *parent, const wxString& param) | |
27 | { | |
28 | wxXmlNode *n = parent->GetChildren(); | |
29 | ||
30 | while (n) | |
31 | { | |
32 | if (n->GetType() == wxXML_ELEMENT_NODE && n->GetName() == param) | |
33 | return n; | |
34 | n = n->GetNext(); | |
35 | } | |
36 | return NULL; | |
37 | } | |
38 | ||
39 | ||
40 | void XmlWriteValue(wxXmlNode *parent, const wxString& name, const wxString& value) | |
41 | { | |
42 | wxXmlNode *n = XmlFindNode(parent, name); | |
43 | if (n == NULL) | |
44 | { | |
45 | n = new wxXmlNode(wxXML_ELEMENT_NODE, name); | |
46 | parent->AddChild(n); | |
47 | n->AddChild(new wxXmlNode(wxXML_TEXT_NODE, "")); | |
48 | } | |
49 | ||
50 | n = n->GetChildren(); | |
51 | ||
52 | while (n) | |
53 | { | |
54 | if (n->GetType() == wxXML_TEXT_NODE || | |
55 | n->GetType() == wxXML_CDATA_SECTION_NODE) | |
56 | { | |
57 | n->SetContent(value); | |
58 | break; | |
59 | } | |
60 | n = n->GetNext(); | |
61 | } | |
62 | } | |
63 | ||
64 | ||
65 | ||
66 | wxString XmlReadValue(wxXmlNode *parent, const wxString& name) | |
67 | { | |
68 | wxXmlNode *n = XmlFindNode(parent, name); | |
69 | if (n == NULL) return wxEmptyString; | |
70 | n = n->GetChildren(); | |
71 | ||
72 | while (n) | |
73 | { | |
74 | if (n->GetType() == wxXML_TEXT_NODE || | |
75 | n->GetType() == wxXML_CDATA_SECTION_NODE) | |
76 | return n->GetContent(); | |
77 | n = n->GetNext(); | |
78 | } | |
79 | return wxEmptyString; | |
80 | } | |
81 | ||
82 | ||
83 | ||
84 |