]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/xmldocument.tex
Applied patch [ 1747059 ] wxAUIDefaultTabArt wxAUI_NB_BOTTOM
[wxWidgets.git] / docs / latex / wx / xmldocument.tex
CommitLineData
434cf5a4 1%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
f5ca194a 2%% Name: xmldocument.tex
434cf5a4
RR
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
288b6107
VS
39 // process attributes of <tag1>
40 wxString attrvalue1 =
41 child->GetAttribute(wxT("attr1"),
e8da6b7c 42 wxT("default-value"));
288b6107
VS
43 wxString attrvalue2 =
44 child->GetAttribute(wxT("attr2"),
e8da6b7c 45 wxT("default-value"));
434cf5a4
RR
46
47 ...
48
49 } else if (child->GetName() == wxT("tag2")) {
50
51 // process tag2 ...
52 }
53
54 child = child->GetNext();
55}
56\end{verbatim}
57
538f3830
VS
58{\bf Note:} if you want to preserve the original formatting of the loaded file including whitespaces
59and indentation, you need to turn off whitespace-only textnode removal and automatic indentation:
60
61\begin{verbatim}
62wxXmlDocument doc;
63doc.Load(wxT("myfile.xml"), wxT("UTF-8"), wxXMLDOC_KEEP_WHITESPACE_NODES);
e8da6b7c
RR
64
65// myfile2.xml will be indentic to myfile.xml saving it this way:
66doc.Save(wxT("myfile2.xml"), wxXML_NO_INDENTATION);
538f3830
VS
67\end{verbatim}
68
69Using default parameters, you will get a reformatted document which in general is different from
70the original loaded content:
71
72\begin{verbatim}
73wxXmlDocument doc;
74doc.Load(wxT("myfile.xml"));
e8da6b7c 75doc.Save(wxT("myfile2.xml")); // myfile2.xml != myfile.xml
538f3830 76\end{verbatim}
434cf5a4
RR
77
78
4c43dd90
JS
79\wxheading{Derived from}
80
81\helpref{wxObject}{wxobject}
82
83\wxheading{Include files}
84
85<wx/xml/xml.h>
86
a7af285d
VZ
87\wxheading{Library}
88
89\helpref{wxXml}{librarieslist}
90
4c43dd90
JS
91\wxheading{See also}
92
288b6107 93\helpref{wxXmlNode}{wxxmlnode}, \helpref{wxXmlAttribute}{wxxmlattribute}
4c43dd90
JS
94
95
96\latexignore{\rtfignore{\wxheading{Members}}}
97
98
74ecac1f 99
4c43dd90
JS
100\membersection{wxXmlDocument::wxXmlDocument}\label{wxxmldocumentwxxmldocument}
101
102\func{}{wxXmlDocument}{\void}
103
104
418ab1e7 105\func{}{wxXmlDocument}{\param{const wxString\& }{filename}, \param{const wxString\& }{encoding = wxT("UTF-8")}, \param{int }{flags = wxXMLDOC\_NONE}}
4c43dd90 106
e8da6b7c 107Loads the given {\it filename} using the given encoding. See \helpref{Load}{wxxmldocumentload}.
4c43dd90 108
418ab1e7 109\func{}{wxXmlDocument}{\param{wxInputStream\& }{stream}, \param{const wxString\& }{encoding = wxT("UTF-8")}, \param{int }{flags = wxXMLDOC\_NONE}}
4c43dd90 110
e8da6b7c 111Loads the XML document from given stream using the given encoding. See \helpref{Load}{wxxmldocumentload}.
4c43dd90
JS
112
113\func{}{wxXmlDocument}{\param{const wxXmlDocument\& }{doc}}
114
e8da6b7c 115Copy constructor. Deep copies all the XML tree of the given document.
4c43dd90 116
74ecac1f 117
4c43dd90
JS
118\membersection{wxXmlDocument::\destruct{wxXmlDocument}}\label{wxxmldocumentdtor}
119
120\func{}{\destruct{wxXmlDocument}}{\void}
121
122Virtual destructor. Frees the document root node.
123
a124f99a 124
74ecac1f 125
a124f99a
RR
126\membersection{wxXmlDocument::DetachRoot}\label{wxxmldocumentdetachroot}
127
128\func{wxXmlNode*}{DetachRoot}{\void}
129
130Detaches the document root node and returns it. The document root node will be set to \NULL
131and thus \helpref{IsOk}{wxxmldocumentisok} will return \false after calling this function.
132
133Note that the caller is reponsible for deleting the returned node in order to avoid memory leaks.
134
135
74ecac1f 136
4c43dd90
JS
137\membersection{wxXmlDocument::GetEncoding}\label{wxxmldocumentgetencoding}
138
139\constfunc{wxString}{GetEncoding}{\void}
140
141Returns encoding of in-memory representation of the document
e8da6b7c 142(same as passed to \helpref{Load}{wxxmldocumentload} or constructor, defaults to UTF-8).
4c43dd90 143
e8da6b7c 144NB: this is meaningless in Unicode build where data are stored as {\tt wchar\_t*}.
4c43dd90
JS
145
146
74ecac1f 147
4c43dd90
JS
148\membersection{wxXmlDocument::GetFileEncoding}\label{wxxmldocumentgetfileencoding}
149
150\constfunc{wxString}{GetFileEncoding}{\void}
151
152Returns encoding of document (may be empty).
153
e8da6b7c 154Note: this is the encoding original file was saved in, {\bf not} the
4c43dd90
JS
155encoding of in-memory representation!
156
157
74ecac1f 158
4c43dd90
JS
159\membersection{wxXmlDocument::GetRoot}\label{wxxmldocumentgetroot}
160
161\constfunc{wxXmlNode*}{GetRoot}{\void}
162
163Returns the root node of the document.
164
165
74ecac1f 166
4c43dd90
JS
167\membersection{wxXmlDocument::GetVersion}\label{wxxmldocumentgetversion}
168
169\constfunc{wxString}{GetVersion}{\void}
170
171Returns the version of document.
172This is the value in the {\tt <?xml version="1.0"?>} header of the XML document.
288b6107 173If the version attribute was not explicitely given in the header, this function
4c43dd90
JS
174returns an empty string.
175
176
74ecac1f 177
4c43dd90
JS
178\membersection{wxXmlDocument::IsOk}\label{wxxmldocumentisok}
179
180\constfunc{bool}{IsOk}{\void}
181
182Returns \true if the document has been loaded successfully.
183
184
74ecac1f 185
4c43dd90
JS
186\membersection{wxXmlDocument::Load}\label{wxxmldocumentload}
187
418ab1e7 188\func{bool}{Load}{\param{const wxString\& }{filename}, \param{const wxString\& }{encoding = wxT("UTF-8")}, \param{int }{flags = wxXMLDOC\_NONE}}
4c43dd90 189
538f3830 190Parses {\it filename} as an xml document and loads its data.
4c43dd90 191
418ab1e7
VZ
192If {\tt flags} does not contain {\tt wxXMLDOC\_KEEP\_WHITESPACE\_NODES}, then, while loading, all nodes of
193type {\tt wxXML\_TEXT\_NODE} (see \helpref{wxXmlNode}{wxxmlnode}) are automatically skipped if they
538f3830
VS
194contain whitespaces only.
195The removal of these nodes makes the load process slightly faster and requires less memory however
196makes impossible to recreate exactly the loaded text with a \helpref{Save}{wxxmldocumentsave} call later.
197Read the initial description of this class for more info.
198
199Returns \true on success, \false otherwise.
200
418ab1e7 201\func{bool}{Load}{\param{wxInputStream\& }{stream}, \param{const wxString\& }{encoding = wxT("UTF-8")}, \param{int }{flags = wxXMLDOC\_NONE}}
4c43dd90
JS
202
203Like above but takes the data from given input stream.
204
74ecac1f 205
4c43dd90
JS
206\membersection{wxXmlDocument::Save}\label{wxxmldocumentsave}
207
538f3830 208\constfunc{bool}{Save}{\param{const wxString\& }{filename}, \param{int }{indentstep = 1}}
4c43dd90
JS
209
210Saves XML tree creating a file named with given string.
211
538f3830
VS
212If {\tt indentstep} is greater than or equal to zero, then, while saving, an automatic indentation
213is added with steps composed by {\tt indentstep} spaces.
418ab1e7 214If {\tt indentstep} is {\tt wxXML\_NO\_INDENTATION}, then, automatic indentation is turned off.
538f3830
VS
215
216\constfunc{bool}{Save}{\param{wxOutputStream\& }{stream}, \param{int }{indentstep = 1}}
4c43dd90 217
538f3830 218Saves XML tree in the given output stream. See other overload for a description of {\tt indentstep}.
4c43dd90 219
74ecac1f 220
4c43dd90
JS
221\membersection{wxXmlDocument::SetEncoding}\label{wxxmldocumentsetencoding}
222
223\func{void}{SetEncoding}{\param{const wxString\& }{enc}}
224
225Sets the enconding of the document.
226
74ecac1f 227
4c43dd90
JS
228\membersection{wxXmlDocument::SetFileEncoding}\label{wxxmldocumentsetfileencoding}
229
230\func{void}{SetFileEncoding}{\param{const wxString\& }{encoding}}
231
232Sets the enconding of the file which will be used to save the document.
233
74ecac1f 234
4c43dd90
JS
235\membersection{wxXmlDocument::SetRoot}\label{wxxmldocumentsetroot}
236
237\func{void}{SetRoot}{\param{wxXmlNode* }{node}}
238
239Sets the root node of this document. Deletes previous root node.
e8da6b7c
RR
240Use \helpref{DetachRoot}{wxxmldocumentdetachroot} and then
241\helpref{SetRoot}{wxxmldocumentsetroot} if you want
74ecac1f
VZ
242to replace the root node without deleting the old document tree.
243
4c43dd90
JS
244
245\membersection{wxXmlDocument::SetVersion}\label{wxxmldocumentsetversion}
246
247\func{void}{SetVersion}{\param{const wxString\& }{version}}
248
249Sets the version of the XML file which will be used to save the document.
250
74ecac1f 251
4c43dd90
JS
252\membersection{wxXmlDocument::operator=}\label{wxxmldocumentoperatorassign}
253
254\func{wxXmlDocument\& operator}{operator=}{\param{const wxXmlDocument\& }{doc}}
255
e8da6b7c 256Deep copies the given document.
4c43dd90 257