1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %% Purpose: wxXmlDocument documentation
4 %% Author: Francesco Montorsi
7 %% Copyright: (c) 2006 Francesco Montorsi
8 %% License: wxWindows license
9 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
11 \section{\class{wxXmlDocument
}}\label{wxxmldocument
}
13 This class holds XML data/
document as parsed by XML parser in the root node.
15 wxXmlDocument internally uses the expat library which comes with wxWidgets to parse the given stream.
17 A simple example of using XML classes is:
21 if (!doc.Load(wxT("myfile.xml"))
24 // start processing the XML file
25 if (doc.GetRoot()->GetName() != wxT("myroot-node"))
28 wxXmlNode *child = doc.GetRoot()->GetChildren();
31 if (child->GetName() == wxT("tag1"))
{
33 // process text enclosed by <tag1></tag1>
34 wxString content = child->GetNodeContent();
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"));
45 } else if (child->GetName() == wxT("tag2"))
{
50 child = child->GetNext();
56 \wxheading{Derived from
}
58 \helpref{wxObject
}{wxobject
}
60 \wxheading{Include files
}
66 \helpref{wxXmlNode
}{wxxmlnode
},
\helpref{wxXmlProperty
}{wxxmlproperty
}
69 \latexignore{\rtfignore{\wxheading{Members
}}}
72 \membersection{wxXmlDocument::wxXmlDocument
}\label{wxxmldocumentwxxmldocument
}
74 \func{}{wxXmlDocument
}{\void}
77 \func{}{wxXmlDocument
}{\param{const wxString\&
}{filename
},
\param{const wxString\&
}{encoding = wxT("UTF-
8")
}}
79 Loads the given
{\it filename
} using the given encoding. See
\helpref{Load()
}{wxxmldocumentload
}.
81 \func{}{wxXmlDocument
}{\param{wxInputStream\&
}{stream
},
\param{const wxString\&
}{encoding = wxT("UTF-
8")
}}
83 Loads the XML
document from given stream using the given encoding. See
\helpref{Load()
}{wxxmldocumentload
}.
85 \func{}{wxXmlDocument
}{\param{const wxXmlDocument\&
}{doc
}}
89 \membersection{wxXmlDocument::
\destruct{wxXmlDocument
}}\label{wxxmldocumentdtor
}
91 \func{}{\destruct{wxXmlDocument
}}{\void}
93 Virtual destructor. Frees the
document root node.
96 \membersection{wxXmlDocument::DetachRoot
}\label{wxxmldocumentdetachroot
}
98 \func{wxXmlNode*
}{DetachRoot
}{\void}
100 Detaches the
document root node and returns it. The
document root node will be set to
\NULL
101 and thus
\helpref{IsOk
}{wxxmldocumentisok
} will return
\false after calling this function.
103 Note that the caller is reponsible for deleting the returned node in order to avoid memory leaks.
106 \membersection{wxXmlDocument::GetEncoding
}\label{wxxmldocumentgetencoding
}
108 \constfunc{wxString
}{GetEncoding
}{\void}
110 Returns encoding of in-memory representation of the
document
111 (same as passed to
\helpref{Load()
}{wxxmldocumentload
} or constructor, defaults to UTF-
8).
113 NB: this is meaningless in Unicode build where data are stored as wchar
\_t*.
116 \membersection{wxXmlDocument::GetFileEncoding
}\label{wxxmldocumentgetfileencoding
}
118 \constfunc{wxString
}{GetFileEncoding
}{\void}
120 Returns encoding of
document (may be empty).
122 Note: this is the encoding original file was saved in, *not* the
123 encoding of in-memory representation!
126 \membersection{wxXmlDocument::GetRoot
}\label{wxxmldocumentgetroot
}
128 \constfunc{wxXmlNode*
}{GetRoot
}{\void}
130 Returns the root node of the
document.
133 \membersection{wxXmlDocument::GetVersion
}\label{wxxmldocumentgetversion
}
135 \constfunc{wxString
}{GetVersion
}{\void}
137 Returns the version of
document.
138 This is the value in the
{\tt <?xml version="
1.0"?>
} header of the XML
document.
139 If the version property was not explicitely given in the header, this function
140 returns an empty string.
143 \membersection{wxXmlDocument::IsOk
}\label{wxxmldocumentisok
}
145 \constfunc{bool
}{IsOk
}{\void}
147 Returns
\true if the
document has been loaded successfully.
150 \membersection{wxXmlDocument::Load
}\label{wxxmldocumentload
}
152 \func{bool
}{Load
}{\param{const wxString\&
}{filename
},
\param{const wxString\&
}{encoding = wxT("UTF-
8")
}}
154 Parses
{\it filename
} as an xml
document and loads data. Returns
\true on success,
\false otherwise.
156 \func{bool
}{Load
}{\param{wxInputStream\&
}{stream
},
\param{const wxString\&
}{encoding = wxT("UTF-
8")
}}
158 Like above but takes the data from given input stream.
160 \membersection{wxXmlDocument::Save
}\label{wxxmldocumentsave
}
162 \constfunc{bool
}{Save
}{\param{const wxString\&
}{filename
}}
164 Saves XML tree creating a file named with given string.
166 \constfunc{bool
}{Save
}{\param{wxOutputStream\&
}{stream
}}
168 Saves XML tree in the given output stream.
170 \membersection{wxXmlDocument::SetEncoding
}\label{wxxmldocumentsetencoding
}
172 \func{void
}{SetEncoding
}{\param{const wxString\&
}{enc
}}
174 Sets the enconding of the
document.
176 \membersection{wxXmlDocument::SetFileEncoding
}\label{wxxmldocumentsetfileencoding
}
178 \func{void
}{SetFileEncoding
}{\param{const wxString\&
}{encoding
}}
180 Sets the enconding of the file which will be used to save the
document.
182 \membersection{wxXmlDocument::SetRoot
}\label{wxxmldocumentsetroot
}
184 \func{void
}{SetRoot
}{\param{wxXmlNode*
}{node
}}
186 Sets the root node of this
document. Deletes previous root node.
187 Use
\helpref{DetachRoot
}{wxxmlnodedetachroot
} and then SetRoot if you want to
188 replace the root node without deleting the old
document tree.
190 \membersection{wxXmlDocument::SetVersion
}\label{wxxmldocumentsetversion
}
192 \func{void
}{SetVersion
}{\param{const wxString\&
}{version
}}
194 Sets the version of the XML file which will be used to save the
document.
196 \membersection{wxXmlDocument::operator=
}\label{wxxmldocumentoperatorassign
}
198 \func{wxXmlDocument\& operator
}{operator=
}{\param{const wxXmlDocument\&
}{doc
}}
200 Copies the given
document.