]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/xmldocument.tex
[ 1564113 ] wxComboCtrl and wxODComboBox documentation update
[wxWidgets.git] / docs / latex / wx / xmldocument.tex
CommitLineData
434cf5a4
RR
1%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2%% Name: xmlnode.tex
3%% Purpose: wxXmlDocument documentation
4%% Author: Francesco Montorsi
5%% Created: 2006-04-18
6%% RCS-ID: $Id$
7%% Copyright: (c) 2006 Francesco Montorsi
8%% License: wxWindows license
9%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
10
4c43dd90
JS
11\section{\class{wxXmlDocument}}\label{wxxmldocument}
12
13This class holds XML data/document as parsed by XML parser in the root node.
14
15wxXmlDocument internally uses the expat library which comes with wxWidgets to parse the given stream.
16
434cf5a4
RR
17A simple example of using XML classes is:
18
19\begin{verbatim}
20wxXmlDocument doc;
538f3830 21if (!doc.Load(wxT("myfile.xml")))
434cf5a4
RR
22 return false;
23
24// start processing the XML file
25if (doc.GetRoot()->GetName() != wxT("myroot-node"))
26 return false;
27
28wxXmlNode *child = doc.GetRoot()->GetChildren();
29while (child) {
30
31 if (child->GetName() == wxT("tag1")) {
32
33 // process text enclosed by <tag1></tag1>
34 wxString content = child->GetNodeContent();
35
36 ...
37
38
39 // process properties of <tag1>
40 wxString propvalue1 = child->GetPropVal(wxT("prop1"), wxT("default-value"));
41 wxString propvalue2 = child->GetPropVal(wxT("prop2"), wxT("default-value"));
42
43 ...
44
45 } else if (child->GetName() == wxT("tag2")) {
46
47 // process tag2 ...
48 }
49
50 child = child->GetNext();
51}
52\end{verbatim}
53
538f3830
VS
54{\bf Note:} if you want to preserve the original formatting of the loaded file including whitespaces
55and indentation, you need to turn off whitespace-only textnode removal and automatic indentation:
56
57\begin{verbatim}
58wxXmlDocument doc;
59doc.Load(wxT("myfile.xml"), wxT("UTF-8"), wxXMLDOC_KEEP_WHITESPACE_NODES);
60doc.Save(wxT("myfile2.xml"), wxXML_NO_INDENTATION); // myfile2.xml will be indentic to myfile.xml
61\end{verbatim}
62
63Using default parameters, you will get a reformatted document which in general is different from
64the original loaded content:
65
66\begin{verbatim}
67wxXmlDocument doc;
68doc.Load(wxT("myfile.xml"));
69doc.Save(wxT("myfile2.xml")); // myfile2.xml != myfile.xml
70\end{verbatim}
434cf5a4
RR
71
72
4c43dd90
JS
73\wxheading{Derived from}
74
75\helpref{wxObject}{wxobject}
76
77\wxheading{Include files}
78
79<wx/xml/xml.h>
80
81\wxheading{See also}
82
83\helpref{wxXmlNode}{wxxmlnode}, \helpref{wxXmlProperty}{wxxmlproperty}
84
85
86\latexignore{\rtfignore{\wxheading{Members}}}
87
88
89\membersection{wxXmlDocument::wxXmlDocument}\label{wxxmldocumentwxxmldocument}
90
91\func{}{wxXmlDocument}{\void}
92
93
418ab1e7 94\func{}{wxXmlDocument}{\param{const wxString\& }{filename}, \param{const wxString\& }{encoding = wxT("UTF-8")}, \param{int }{flags = wxXMLDOC\_NONE}}
4c43dd90
JS
95
96Loads the given {\it filename} using the given encoding. See \helpref{Load()}{wxxmldocumentload}.
97
418ab1e7 98\func{}{wxXmlDocument}{\param{wxInputStream\& }{stream}, \param{const wxString\& }{encoding = wxT("UTF-8")}, \param{int }{flags = wxXMLDOC\_NONE}}
4c43dd90
JS
99
100Loads the XML document from given stream using the given encoding. See \helpref{Load()}{wxxmldocumentload}.
101
102\func{}{wxXmlDocument}{\param{const wxXmlDocument\& }{doc}}
103
104Copy constructor.
105
106\membersection{wxXmlDocument::\destruct{wxXmlDocument}}\label{wxxmldocumentdtor}
107
108\func{}{\destruct{wxXmlDocument}}{\void}
109
110Virtual destructor. Frees the document root node.
111
a124f99a
RR
112
113\membersection{wxXmlDocument::DetachRoot}\label{wxxmldocumentdetachroot}
114
115\func{wxXmlNode*}{DetachRoot}{\void}
116
117Detaches the document root node and returns it. The document root node will be set to \NULL
118and thus \helpref{IsOk}{wxxmldocumentisok} will return \false after calling this function.
119
120Note that the caller is reponsible for deleting the returned node in order to avoid memory leaks.
121
122
4c43dd90
JS
123\membersection{wxXmlDocument::GetEncoding}\label{wxxmldocumentgetencoding}
124
125\constfunc{wxString}{GetEncoding}{\void}
126
127Returns encoding of in-memory representation of the document
128(same as passed to \helpref{Load()}{wxxmldocumentload} or constructor, defaults to UTF-8).
129
130NB: this is meaningless in Unicode build where data are stored as wchar\_t*.
131
132
133\membersection{wxXmlDocument::GetFileEncoding}\label{wxxmldocumentgetfileencoding}
134
135\constfunc{wxString}{GetFileEncoding}{\void}
136
137Returns encoding of document (may be empty).
138
139Note: this is the encoding original file was saved in, *not* the
140encoding of in-memory representation!
141
142
143\membersection{wxXmlDocument::GetRoot}\label{wxxmldocumentgetroot}
144
145\constfunc{wxXmlNode*}{GetRoot}{\void}
146
147Returns the root node of the document.
148
149
150\membersection{wxXmlDocument::GetVersion}\label{wxxmldocumentgetversion}
151
152\constfunc{wxString}{GetVersion}{\void}
153
154Returns the version of document.
155This is the value in the {\tt <?xml version="1.0"?>} header of the XML document.
156If the version property was not explicitely given in the header, this function
157returns an empty string.
158
159
160\membersection{wxXmlDocument::IsOk}\label{wxxmldocumentisok}
161
162\constfunc{bool}{IsOk}{\void}
163
164Returns \true if the document has been loaded successfully.
165
166
167\membersection{wxXmlDocument::Load}\label{wxxmldocumentload}
168
418ab1e7 169\func{bool}{Load}{\param{const wxString\& }{filename}, \param{const wxString\& }{encoding = wxT("UTF-8")}, \param{int }{flags = wxXMLDOC\_NONE}}
4c43dd90 170
538f3830 171Parses {\it filename} as an xml document and loads its data.
4c43dd90 172
418ab1e7
VZ
173If {\tt flags} does not contain {\tt wxXMLDOC\_KEEP\_WHITESPACE\_NODES}, then, while loading, all nodes of
174type {\tt wxXML\_TEXT\_NODE} (see \helpref{wxXmlNode}{wxxmlnode}) are automatically skipped if they
538f3830
VS
175contain whitespaces only.
176The removal of these nodes makes the load process slightly faster and requires less memory however
177makes impossible to recreate exactly the loaded text with a \helpref{Save}{wxxmldocumentsave} call later.
178Read the initial description of this class for more info.
179
180Returns \true on success, \false otherwise.
181
418ab1e7 182\func{bool}{Load}{\param{wxInputStream\& }{stream}, \param{const wxString\& }{encoding = wxT("UTF-8")}, \param{int }{flags = wxXMLDOC\_NONE}}
4c43dd90
JS
183
184Like above but takes the data from given input stream.
185
186\membersection{wxXmlDocument::Save}\label{wxxmldocumentsave}
187
538f3830 188\constfunc{bool}{Save}{\param{const wxString\& }{filename}, \param{int }{indentstep = 1}}
4c43dd90
JS
189
190Saves XML tree creating a file named with given string.
191
538f3830
VS
192If {\tt indentstep} is greater than or equal to zero, then, while saving, an automatic indentation
193is added with steps composed by {\tt indentstep} spaces.
418ab1e7 194If {\tt indentstep} is {\tt wxXML\_NO\_INDENTATION}, then, automatic indentation is turned off.
538f3830
VS
195
196\constfunc{bool}{Save}{\param{wxOutputStream\& }{stream}, \param{int }{indentstep = 1}}
4c43dd90 197
538f3830 198Saves XML tree in the given output stream. See other overload for a description of {\tt indentstep}.
4c43dd90
JS
199
200\membersection{wxXmlDocument::SetEncoding}\label{wxxmldocumentsetencoding}
201
202\func{void}{SetEncoding}{\param{const wxString\& }{enc}}
203
204Sets the enconding of the document.
205
206\membersection{wxXmlDocument::SetFileEncoding}\label{wxxmldocumentsetfileencoding}
207
208\func{void}{SetFileEncoding}{\param{const wxString\& }{encoding}}
209
210Sets the enconding of the file which will be used to save the document.
211
212\membersection{wxXmlDocument::SetRoot}\label{wxxmldocumentsetroot}
213
214\func{void}{SetRoot}{\param{wxXmlNode* }{node}}
215
216Sets the root node of this document. Deletes previous root node.
a124f99a
RR
217Use \helpref{DetachRoot}{wxxmlnodedetachroot} and then SetRoot if you want to
218replace the root node without deleting the old document tree.
4c43dd90
JS
219
220\membersection{wxXmlDocument::SetVersion}\label{wxxmldocumentsetversion}
221
222\func{void}{SetVersion}{\param{const wxString\& }{version}}
223
224Sets the version of the XML file which will be used to save the document.
225
226\membersection{wxXmlDocument::operator=}\label{wxxmldocumentoperatorassign}
227
228\func{wxXmlDocument\& operator}{operator=}{\param{const wxXmlDocument\& }{doc}}
229
230Copies the given document.
231