X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e066e2566a4e5db3510fe6a204d66850eaeceade..749a05ee85ea5453f155454e4640ebf795233ad3:/contrib/utils/wxrcedit/xmlhelpr.cpp?ds=sidebyside diff --git a/contrib/utils/wxrcedit/xmlhelpr.cpp b/contrib/utils/wxrcedit/xmlhelpr.cpp index c920dad77c..a8fa0886af 100644 --- a/contrib/utils/wxrcedit/xmlhelpr.cpp +++ b/contrib/utils/wxrcedit/xmlhelpr.cpp @@ -19,14 +19,17 @@ #include "wx/xml/xml.h" #include "wx/wx.h" +#include "wx/tokenzr.h" #include "xmlhelpr.h" -wxXmlNode *XmlFindNode(wxXmlNode *parent, const wxString& param) +wxXmlNode *XmlFindNodeSimple(wxXmlNode *parent, const wxString& param) { + if (param.IsEmpty()) return parent; + wxXmlNode *n = parent->GetChildren(); - + while (n) { if (n->GetType() == wxXML_ELEMENT_NODE && n->GetName() == param) @@ -37,21 +40,57 @@ wxXmlNode *XmlFindNode(wxXmlNode *parent, const wxString& param) } -void XmlWriteValue(wxXmlNode *parent, const wxString& name, const wxString& value) + +wxXmlNode *XmlFindNode(wxXmlNode *parent, const wxString& path) { - wxXmlNode *n = XmlFindNode(parent, name); - if (n == NULL) + wxXmlNode *n = parent; + wxStringTokenizer tkn(path, _T("/")); + while (tkn.HasMoreTokens()) + { + n = XmlFindNodeSimple(n, tkn.GetNextToken()); + if (n == NULL) break; + } + return n; +} + + + +wxXmlNode *XmlCreateNode(wxXmlNode *parent, const wxString& name) +{ + wxXmlNode *n; + wxString nm; + + wxStringTokenizer tkn(name, _T("/")); + n = parent; + while (tkn.HasMoreTokens()) { - n = new wxXmlNode(wxXML_ELEMENT_NODE, name); + parent = n; + nm = tkn.GetNextToken(); + n = XmlFindNodeSimple(parent, nm); + if (n) continue; + + // n == NULL: + n = new wxXmlNode(wxXML_ELEMENT_NODE, nm); parent->AddChild(n); - n->AddChild(new wxXmlNode(wxXML_TEXT_NODE, "")); } - + n->AddChild(new wxXmlNode(wxXML_TEXT_NODE, wxEmptyString)); + + return n; +} + + + +void XmlWriteValue(wxXmlNode *parent, const wxString& name, const wxString& value) +{ + wxXmlNode *n = XmlFindNode(parent, name); + if (n == NULL) + n = XmlCreateNode(parent, name); + n = n->GetChildren(); - + while (n) { - if (n->GetType() == wxXML_TEXT_NODE || + if (n->GetType() == wxXML_TEXT_NODE || n->GetType() == wxXML_CDATA_SECTION_NODE) { n->SetContent(value); @@ -68,10 +107,10 @@ 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 || + if (n->GetType() == wxXML_TEXT_NODE || n->GetType() == wxXML_CDATA_SECTION_NODE) return n->GetContent(); n = n->GetNext();