summaryrefslogtreecommitdiffstats
path: root/doc/man/man3/qdomelement.3qt
blob: a6d546dae96522f468fcaccd2799f5a439885fe4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
'\" t
.TH QDomElement 3qt "2 February 2007" "Trolltech AS" \" -*- nroff -*-
.\" Copyright 1992-2007 Trolltech ASA.  All rights reserved.  See the
.\" license file included in the distribution for a complete license
.\" statement.
.\"
.ad l
.nh
.SH NAME
QDomElement \- Represents one element in the DOM tree
.SH SYNOPSIS
All the functions in this class are reentrant when Qt is built with thread support.</p>
.PP
\fC#include <qdom.h>\fR
.PP
Inherits QDomNode.
.PP
.SS "Public Members"
.in +1c
.ti -1c
.BI "\fBQDomElement\fR ()"
.br
.ti -1c
.BI "\fBQDomElement\fR ( const QDomElement & x )"
.br
.ti -1c
.BI "QDomElement & \fBoperator=\fR ( const QDomElement & x )"
.br
.ti -1c
.BI "\fB~QDomElement\fR ()"
.br
.ti -1c
.BI "QString \fBattribute\fR ( const QString & name, const QString & defValue = QString::null ) const"
.br
.ti -1c
.BI "void \fBsetAttribute\fR ( const QString & name, const QString & value )"
.br
.ti -1c
.BI "void \fBsetAttribute\fR ( const QString & name, int value )"
.br
.ti -1c
.BI "void \fBsetAttribute\fR ( const QString & name, uint value )"
.br
.ti -1c
.BI "void \fBsetAttribute\fR ( const QString & name, long value )"
.br
.ti -1c
.BI "void \fBsetAttribute\fR ( const QString & name, ulong value )"
.br
.ti -1c
.BI "void \fBsetAttribute\fR ( const QString & name, double value )"
.br
.ti -1c
.BI "void \fBremoveAttribute\fR ( const QString & name )"
.br
.ti -1c
.BI "QDomAttr \fBattributeNode\fR ( const QString & name )"
.br
.ti -1c
.BI "QDomAttr \fBsetAttributeNode\fR ( const QDomAttr & newAttr )"
.br
.ti -1c
.BI "QDomAttr \fBremoveAttributeNode\fR ( const QDomAttr & oldAttr )"
.br
.ti -1c
.BI "virtual QDomNodeList \fBelementsByTagName\fR ( const QString & tagname ) const"
.br
.ti -1c
.BI "bool \fBhasAttribute\fR ( const QString & name ) const"
.br
.ti -1c
.BI "QString \fBattributeNS\fR ( const QString nsURI, const QString & localName, const QString & defValue ) const"
.br
.ti -1c
.BI "void \fBsetAttributeNS\fR ( const QString nsURI, const QString & qName, const QString & value )"
.br
.ti -1c
.BI "void \fBsetAttributeNS\fR ( const QString nsURI, const QString & qName, int value )"
.br
.ti -1c
.BI "void \fBsetAttributeNS\fR ( const QString nsURI, const QString & qName, uint value )"
.br
.ti -1c
.BI "void \fBsetAttributeNS\fR ( const QString nsURI, const QString & qName, long value )"
.br
.ti -1c
.BI "void \fBsetAttributeNS\fR ( const QString nsURI, const QString & qName, ulong value )"
.br
.ti -1c
.BI "void \fBsetAttributeNS\fR ( const QString nsURI, const QString & qName, double value )"
.br
.ti -1c
.BI "void \fBremoveAttributeNS\fR ( const QString & nsURI, const QString & localName )"
.br
.ti -1c
.BI "QDomAttr \fBattributeNodeNS\fR ( const QString & nsURI, const QString & localName )"
.br
.ti -1c
.BI "QDomAttr \fBsetAttributeNodeNS\fR ( const QDomAttr & newAttr )"
.br
.ti -1c
.BI "virtual QDomNodeList \fBelementsByTagNameNS\fR ( const QString & nsURI, const QString & localName ) const"
.br
.ti -1c
.BI "bool \fBhasAttributeNS\fR ( const QString & nsURI, const QString & localName ) const"
.br
.ti -1c
.BI "QString \fBtagName\fR () const"
.br
.ti -1c
.BI "void \fBsetTagName\fR ( const QString & name )"
.br
.ti -1c
.BI "virtual QDomNamedNodeMap \fBattributes\fR () const"
.br
.ti -1c
.BI "virtual QDomNode::NodeType \fBnodeType\fR () const"
.br
.ti -1c
.BI "virtual bool \fBisElement\fR () const"
.br
.ti -1c
.BI "QString \fBtext\fR () const"
.br
.in -1c
.SH DESCRIPTION
The QDomElement class represents one element in the DOM tree.
.PP
Elements have a tagName() and zero or more attributes associated with them. The tag name can be changed with setTagName().
.PP
Element attributes are represented by QDomAttr objects that can be queried using the attribute() and attributeNode() functions. You can set attributes with the setAttribute() and setAttributeNode() functions. Attributes can be removed with removeAttribute(). There are namespace-aware equivalents to these functions, i.e. setAttributeNS(), setAttributeNodeNS() and removeAttributeNS().
.PP
If you want to access the text of a node use text(), e.g.
.PP
.nf
.br
    QDomElement e = //...
.br
    //...
.br
    QString s = e.text()
.br
.fi
The text() function operates recursively to find the text (since not all elements contain text). If you want to find all the text in all of a node's children, iterate over the children looking for QDomText nodes, e.g.
.PP
.nf
.br
    QString text;
.br
    QDomElement element = doc.documentElement();
.br
    for( QDomNode n = element.firstChild(); !n.isNull(); n = n.nextSibling() )
.br
    {
.br
        QDomText t = n.toText();
.br
        if ( !t.isNull() )
.br
            text += t.data();
.br
    }
.br
.fi
Note that we attempt to convert each node to a text node and use text() rather than using firstChild().toText().data() or n.toText().data() directly on the node, because the node may not be a text element.
.PP
You can get a list of all the decendents of an element which have a specified tag name with elementsByTagName() or elementsByTagNameNS().
.PP
For further information about the Document Object Model see http://www.w3.org/TR/REC-DOM-Level-1/ and http://www.w3.org/TR/DOM-Level-2-Core/. For a more general introduction of the DOM implementation see the QDomDocument documentation.
.PP
See also XML.
.SH MEMBER FUNCTION DOCUMENTATION
.SH "QDomElement::QDomElement ()"
Constructs an empty element. Use the QDomDocument::createElement() function to construct elements with content.
.SH "QDomElement::QDomElement ( const QDomElement & x )"
Constructs a copy of \fIx\fR.
.PP
The data of the copy is shared (shallow copy): modifying one node will also change the other. If you want to make a deep copy, use cloneNode().
.SH "QDomElement::~QDomElement ()"
Destroys the object and frees its resources.
.SH "QString QDomElement::attribute ( const QString & name, const QString & defValue = QString::null ) const"
Returns the attribute called \fIname\fR. If the attribute does not exist \fIdefValue\fR is returned.
.PP
See also setAttribute(), attributeNode(), setAttributeNode(), and attributeNS().
.SH "QString QDomElement::attributeNS ( const QString nsURI, const QString & localName, const QString & defValue ) const"
Returns the attribute with the local name \fIlocalName\fR and the namespace URI \fInsURI\fR. If the attribute does not exist \fIdefValue\fR is returned.
.PP
See also setAttributeNS(), attributeNodeNS(), setAttributeNodeNS(), and attribute().
.SH "QDomAttr QDomElement::attributeNode ( const QString & name )"
Returns the QDomAttr object that corresponds to the attribute called \fIname\fR. If no such attribute exists a null attribute is returned.
.PP
See also setAttributeNode(), attribute(), setAttribute(), and attributeNodeNS().
.SH "QDomAttr QDomElement::attributeNodeNS ( const QString & nsURI, const QString & localName )"
Returns the QDomAttr object that corresponds to the attribute with the local name \fIlocalName\fR and the namespace URI \fInsURI\fR. If no such attribute exists a null attribute is returned.
.PP
See also setAttributeNode(), attribute(), and setAttribute().
.SH "QDomNamedNodeMap QDomElement::attributes () const\fC [virtual]\fR"
Returns a QDomNamedNodeMap containing all this element's attributes.
.PP
See also attribute(), setAttribute(), attributeNode(), and setAttributeNode().
.PP
Reimplemented from QDomNode.
.SH "QDomNodeList QDomElement::elementsByTagName ( const QString & tagname ) const\fC [virtual]\fR"
Returns a QDomNodeList containing all descendent elements of this element that are called \fItagname\fR. The order they are in the node list is the order they are encountered in a preorder traversal of the element tree.
.PP
See also elementsByTagNameNS() and QDomDocument::elementsByTagName().
.SH "QDomNodeList QDomElement::elementsByTagNameNS ( const QString & nsURI, const QString & localName ) const\fC [virtual]\fR"
Returns a QDomNodeList containing all the descendent elements of this element with the local name \fIlocalName\fR and the namespace URI \fInsURI\fR. The order they are in the node list is the order they are encountered in a preorder traversal of the element tree.
.PP
See also elementsByTagName() and QDomDocument::elementsByTagNameNS().
.SH "bool QDomElement::hasAttribute ( const QString & name ) const"
Returns TRUE if this element has an attribute called \fIname\fR; otherwise returns FALSE.
.SH "bool QDomElement::hasAttributeNS ( const QString & nsURI, const QString & localName ) const"
Returns TRUE if this element has an attribute with the local name \fIlocalName\fR and the namespace URI \fInsURI\fR; otherwise returns FALSE.
.SH "bool QDomElement::isElement () const\fC [virtual]\fR"
Returns TRUE.
.PP
Reimplemented from QDomNode.
.SH "QDomNode::NodeType QDomElement::nodeType () const\fC [virtual]\fR"
Returns ElementNode.
.PP
Reimplemented from QDomNode.
.SH "QDomElement & QDomElement::operator= ( const QDomElement & x )"
Assigns \fIx\fR to this DOM element.
.PP
The data of the copy is shared (shallow copy): modifying one node will also change the other. If you want to make a deep copy, use cloneNode().
.SH "void QDomElement::removeAttribute ( const QString & name )"
Removes the attribute called name \fIname\fR from this element.
.PP
See also setAttribute(), attribute(), and removeAttributeNS().
.SH "void QDomElement::removeAttributeNS ( const QString & nsURI, const QString & localName )"
Removes the attribute with the local name \fIlocalName\fR and the namespace URI \fInsURI\fR from this element.
.PP
See also setAttributeNS(), attributeNS(), and removeAttribute().
.SH "QDomAttr QDomElement::removeAttributeNode ( const QDomAttr & oldAttr )"
Removes the attribute \fIoldAttr\fR from the element and returns it.
.PP
See also attributeNode() and setAttributeNode().
.SH "void QDomElement::setAttribute ( const QString & name, const QString & value )"
Adds an attribute called \fIname\fR with value \fIvalue\fR. If an attribute with the same name exists, its value is replaced by \fIvalue\fR.
.PP
See also attribute(), setAttributeNode(), and setAttributeNS().
.SH "void QDomElement::setAttribute ( const QString & name, int value )"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.SH "void QDomElement::setAttribute ( const QString & name, uint value )"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.SH "void QDomElement::setAttribute ( const QString & name, long value )"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.SH "void QDomElement::setAttribute ( const QString & name, ulong value )"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.SH "void QDomElement::setAttribute ( const QString & name, double value )"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.SH "void QDomElement::setAttributeNS ( const QString nsURI, const QString & qName, const QString & value )"
Adds an attribute with the qualified name \fIqName\fR and the namespace URI \fInsURI\fR with the value \fIvalue\fR. If an attribute with the same local name and namespace URI exists, its prefix is replaced by the prefix of \fIqName\fR and its value is repaced by \fIvalue\fR.
.PP
Although \fIqName\fR is the qualified name, the local name is used to decide if an existing attribute's value should be replaced.
.PP
See also attributeNS(), setAttributeNodeNS(), and setAttribute().
.SH "void QDomElement::setAttributeNS ( const QString nsURI, const QString & qName, int value )"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.SH "void QDomElement::setAttributeNS ( const QString nsURI, const QString & qName, uint value )"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.SH "void QDomElement::setAttributeNS ( const QString nsURI, const QString & qName, long value )"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.SH "void QDomElement::setAttributeNS ( const QString nsURI, const QString & qName, ulong value )"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.SH "void QDomElement::setAttributeNS ( const QString nsURI, const QString & qName, double value )"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.SH "QDomAttr QDomElement::setAttributeNode ( const QDomAttr & newAttr )"
Adds the attribute \fInewAttr\fR to this element.
.PP
If the element has another attribute that has the same name as \fInewAttr\fR, this function replaces that attribute and returns it; otherwise the function returns a null attribute.
.PP
See also attributeNode(), setAttribute(), and setAttributeNodeNS().
.SH "QDomAttr QDomElement::setAttributeNodeNS ( const QDomAttr & newAttr )"
Adds the attribute \fInewAttr\fR to this element.
.PP
If the element has another attribute that has the same local name and namespace URI as \fInewAttr\fR, this function replaces that attribute and returns it; otherwise the function returns a null attribute.
.PP
See also attributeNodeNS(), setAttributeNS(), and setAttributeNode().
.SH "void QDomElement::setTagName ( const QString & name )"
Sets this element's tag name to \fIname\fR.
.PP
See also tagName().
.SH "QString QDomElement::tagName () const"
Returns the tag name of this element. For an XML element like this:
.PP
.nf
.br
    <img src="myimg.png">
.br
.fi
the tagname would return "img".
.PP
See also setTagName().
.SH "QString QDomElement::text () const"
Returns the element's text or QString::null.
.PP
Example:
.PP
.nf
.br
    <h1>Hello <b>Qt</b> <![CDATA[<xml is cool>]]></h1>
.br
.fi
.PP
The function text() of the QDomElement for the <h1> tag, will return "Hello Qt <xml is cool>".
.PP
Comments are ignored by this function. It only evaluates QDomText
and QDomCDATASection objects.

.SH "SEE ALSO"
.BR http://doc.trolltech.com/qdomelement.html
.BR http://www.trolltech.com/faq/tech.html
.SH COPYRIGHT
Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com.  See the
license file included in the distribution for a complete license
statement.
.SH AUTHOR
Generated automatically from the source code.
.SH BUGS
If you find a bug in Qt, please report it as described in
.BR http://doc.trolltech.com/bughowto.html .
Good bug reports help us to help you. Thank you.
.P
The definitive Qt documentation is provided in HTML format; it is
located at $QTDIR/doc/html and can be read using Qt Assistant or with
a web browser. This man page is provided as a convenience for those
users who prefer man pages, although this format is not officially
supported by Trolltech. 
.P
If you find errors in this manual page, please report them to
.BR qt-bugs@trolltech.com .
Please include the name of the manual page (qdomelement.3qt) and the Qt
version (3.3.8).