]>
git.saurik.com Git - wxWidgets.git/blob - contrib/utils/wxrcedit/xmlhelpr.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Author: Vaclav Slavik
5 // Copyright: (c) 2000 Vaclav Slavik
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
10 #pragma implementation "xmlhelpr.h"
13 // For compilers that support precompilation, includes "wx/wx.h".
14 #include "wx/wxprec.h"
20 #include "wx/xml/xml.h"
22 #include "wx/tokenzr.h"
27 wxXmlNode
*XmlFindNodeSimple(wxXmlNode
*parent
, const wxString
& param
)
29 if (param
.IsEmpty()) return parent
;
31 wxXmlNode
*n
= parent
->GetChildren();
35 if (n
->GetType() == wxXML_ELEMENT_NODE
&& n
->GetName() == param
)
44 wxXmlNode
*XmlFindNode(wxXmlNode
*parent
, const wxString
& path
)
46 wxXmlNode
*n
= parent
;
47 wxStringTokenizer
tkn(path
, _T("/"));
48 while (tkn
.HasMoreTokens())
50 n
= XmlFindNodeSimple(n
, tkn
.GetNextToken());
58 wxXmlNode
*XmlCreateNode(wxXmlNode
*parent
, const wxString
& name
)
63 wxStringTokenizer
tkn(name
, _T("/"));
65 while (tkn
.HasMoreTokens())
68 nm
= tkn
.GetNextToken();
69 n
= XmlFindNodeSimple(parent
, nm
);
73 n
= new wxXmlNode(wxXML_ELEMENT_NODE
, nm
);
76 n
->AddChild(new wxXmlNode(wxXML_TEXT_NODE
, wxEmptyString
));
83 void XmlWriteValue(wxXmlNode
*parent
, const wxString
& name
, const wxString
& value
)
85 wxXmlNode
*n
= XmlFindNode(parent
, name
);
87 n
= XmlCreateNode(parent
, name
);
93 if (n
->GetType() == wxXML_TEXT_NODE
||
94 n
->GetType() == wxXML_CDATA_SECTION_NODE
)
105 wxString
XmlReadValue(wxXmlNode
*parent
, const wxString
& name
)
107 wxXmlNode
*n
= XmlFindNode(parent
, name
);
108 if (n
== NULL
) return wxEmptyString
;
109 n
= n
->GetChildren();
113 if (n
->GetType() == wxXML_TEXT_NODE
||
114 n
->GetType() == wxXML_CDATA_SECTION_NODE
)
115 return n
->GetContent();
118 return wxEmptyString
;
123 wxString
XmlGetClass(wxXmlNode
*parent
)
125 return parent
->GetPropVal(_T("class"), wxEmptyString
);
130 void XmlSetClass(wxXmlNode
*parent
, const wxString
& classname
)
132 parent
->DeleteProperty(_T("class"));
133 parent
->AddProperty(_T("class"), classname
);