1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: SWIG interface for other wxXml classes
7 // Created: 4-June-2001
9 // Copyright: (c) 2003 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
16 //---------------------------------------------------------------------------
20 // In order to provide wrappers for wxXmlResourceHandler we need to also
21 // provide the classes for representing and parsing XML.
24 // Represents XML node type.
27 // note: values are synchronized with xmlElementType from libxml
31 wxXML_CDATA_SECTION_NODE,
32 wxXML_ENTITY_REF_NODE,
37 wxXML_DOCUMENT_TYPE_NODE,
38 wxXML_DOCUMENT_FRAG_NODE,
40 wxXML_HTML_DOCUMENT_NODE
45 // Represents node property(ies).
46 // Example: in <img src="hello.gif" id="3"/> "src" is property with value
47 // "hello.gif" and "id" is property with value "3".
51 wxXmlProperty(const wxString& name = wxPyEmptyString,
52 const wxString& value = wxPyEmptyString,
53 wxXmlProperty *next = NULL);
55 wxString GetName() const;
56 wxString GetValue() const;
57 wxXmlProperty *GetNext() const;
59 void SetName(const wxString& name);
60 void SetValue(const wxString& value);
61 void SetNext(wxXmlProperty *next);
67 // Represents node in XML document. Node has name and may have content
68 // and properties. Most common node types are wxXML_TEXT_NODE (name and props
69 // are irrelevant) and wxXML_ELEMENT_NODE (e.g. in <title>hi</title> there is
70 // element with name="title", irrelevant content and one child (wxXML_TEXT_NODE
71 // with content="hi").
73 // If wxUSE_UNICODE is 0, all strings are encoded in the encoding given to Load
74 // (default is UTF-8).
78 wxXmlNode(wxXmlNode *parent = NULL,
79 wxXmlNodeType type = 0,
80 const wxString& name = wxPyEmptyString,
81 const wxString& content = wxPyEmptyString,
82 wxXmlProperty *props = NULL,
83 wxXmlNode *next = NULL);
87 // user-friendly creation:
88 %RenameCtor(XmlNodeEasy, wxXmlNode(wxXmlNodeType type, const wxString& name,
89 const wxString& content = wxPyEmptyString));
91 void AddChild(wxXmlNode *child);
92 bool InsertChild(wxXmlNode *child, wxXmlNode *before_node);
93 bool RemoveChild(wxXmlNode *child);
94 void AddProperty(wxXmlProperty *prop);
95 %Rename(AddPropertyName, void, AddProperty(const wxString& name, const wxString& value));
96 bool DeleteProperty(const wxString& name);
99 wxXmlNodeType GetType() const;
100 wxString GetName() const;
101 wxString GetContent() const;
103 bool IsWhitespaceOnly() const;
104 int GetDepth(wxXmlNode *grandparent = NULL) const;
106 // Gets node content from wxXML_ENTITY_NODE
107 // The problem is, <tag>content<tag> is represented as
108 // wxXML_ENTITY_NODE name="tag", content=""
109 // |-- wxXML_TEXT_NODE or
110 // wxXML_CDATA_SECTION_NODE name="" content="content"
111 wxString GetNodeContent() const;
113 wxXmlNode *GetParent() const;
114 wxXmlNode *GetNext() const;
115 wxXmlNode *GetChildren() const;
117 wxXmlProperty *GetProperties() const;
118 wxString GetPropVal(const wxString& propName,
119 const wxString& defaultVal) const;
120 bool HasProp(const wxString& propName) const;
122 void SetType(wxXmlNodeType type);
123 void SetName(const wxString& name);
124 void SetContent(const wxString& con);
126 void SetParent(wxXmlNode *parent);
127 void SetNext(wxXmlNode *next);
128 void SetChildren(wxXmlNode *child);
130 void SetProperties(wxXmlProperty *prop);
135 // special indentation value for wxXmlDocument::Save
140 // flags for wxXmlDocument::Load
141 enum wxXmlDocumentLoadFlag
144 wxXMLDOC_KEEP_WHITESPACE_NODES = 1
149 // This class holds XML data/document as parsed by XML parser.
150 class wxXmlDocument : public wxObject
153 wxXmlDocument(const wxString& filename,
154 const wxString& encoding = wxPyUTF8String);
155 %RenameCtor(XmlDocumentFromStream, wxXmlDocument(wxInputStream& stream,
156 const wxString& encoding = wxPyUTF8String));
157 %RenameCtor(EmptyXmlDocument, wxXmlDocument());
162 // Parses .xml file and loads data. Returns True on success, False
164 bool Load(const wxString& filename,
165 const wxString& encoding = wxPyUTF8String,
166 int flags = wxXMLDOC_NONE);
167 %Rename(LoadFromStream, bool, Load(wxInputStream& stream,
168 const wxString& encoding = wxPyUTF8String,
169 int flags = wxXMLDOC_NONE));
171 // Saves document as .xml file.
172 bool Save(const wxString& filename, int indentstep=1) const;
173 %Rename(SaveToStream, bool, Save(wxOutputStream& stream, int indentstep=1) const);
177 // Returns root node of the document.
178 wxXmlNode *GetRoot() const;
180 // Returns version of document (may be empty).
181 wxString GetVersion() const;
183 // Returns encoding of document (may be empty).
184 // Note: this is the encoding original file was saved in, *not* the
185 // encoding of in-memory representation!
186 wxString GetFileEncoding() const;
188 // Write-access methods:
189 wxXmlNode *DetachRoot();
190 void SetRoot(wxXmlNode *node);
191 void SetVersion(const wxString& version);
192 void SetFileEncoding(const wxString& encoding);
195 // // Returns encoding of in-memory representation of the document (same
196 // // as passed to Load or ctor, defaults to UTF-8). NB: this is
197 // // meaningless in Unicode build where data are stored as wchar_t*
198 // wxString GetEncoding() {
199 // %#if wxUSE_UNICODE
200 // return wxPyEmptyString;
202 // return self->GetEncoding();
205 // void SetEncoding(const wxString& enc) {
206 // %#if wxUSE_UNICODE
209 // self->SetEncoding(enc);
215 //---------------------------------------------------------------------------
216 //---------------------------------------------------------------------------