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().
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().
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().
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().
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.
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.
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().
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>