QDomElement(3qt)
π QDomElement β from the 3qt manual π
okay bestie, pull up a chair because today we're learning about QDomElement, aka the little diva that represents one element in the DOM tree. yes that's the NAME section, we're doing this properly, in order, no skipping π
β¨ SYNOPSIS β¨
real talk first: all the functions in this class are reentrant when Qt is built with thread support. </p>
#include <qdom.h>
Inherits QDomNode.
π Public Members π
QDomElement ()QDomElement ( const QDomElement & x )QDomElement & operator= ( const QDomElement & x )~QDomElement ()QString attribute ( const QString & name, const QString & defValue = QString::null ) constvoid setAttribute ( const QString & name, const QString & value )void setAttribute ( const QString & name, int value )void setAttribute ( const QString & name, uint value )void setAttribute ( const QString & name, long value )void setAttribute ( const QString & name, ulong value )void setAttribute ( const QString & name, double value )void removeAttribute ( const QString & name )QDomAttr attributeNode ( const QString & name )QDomAttr setAttributeNode ( const QDomAttr & newAttr )QDomAttr removeAttributeNode ( const QDomAttr & oldAttr )virtual QDomNodeList elementsByTagName ( const QString & tagname ) constbool hasAttribute ( const QString & name ) constQString attributeNS ( const QString nsURI, const QString & localName, const QString & defValue ) constvoid setAttributeNS ( const QString nsURI, const QString & qName, const QString & value )void setAttributeNS ( const QString nsURI, const QString & qName, int value )void setAttributeNS ( const QString nsURI, const QString & qName, uint value )void setAttributeNS ( const QString nsURI, const QString & qName, long value )void setAttributeNS ( const QString nsURI, const QString & qName, ulong value )void setAttributeNS ( const QString nsURI, const QString & qName, double value )void removeAttributeNS ( const QString & nsURI, const QString & localName )QDomAttr attributeNodeNS ( const QString & nsURI, const QString & localName )QDomAttr setAttributeNodeNS ( const QDomAttr & newAttr )virtual QDomNodeList elementsByTagNameNS ( const QString & nsURI, const QString & localName ) constbool hasAttributeNS ( const QString & nsURI, const QString & localName ) constQString tagName () constvoid setTagName ( const QString & name )virtual QDomNamedNodeMap attributes () constvirtual QDomNode::NodeType nodeType () constvirtual bool isElement () constQString text () const
πΈ DESCRIPTION πΈ
so. the QDomElement class represents one element in the DOM tree. that's the whole vibe. one element. main character energy, honestly.
Elements have a tagName() and zero or more attributes hanging out with them. wanna change the tag name? setTagName(). slay.
Element attributes are represented by QDomAttr objects, and you can go ask about them using the attribute() and attributeNode() functions. wanna set stuff? that's setAttribute() and setAttributeNode(). wanna yeet an attribute into the void? removeAttribute(). and because namespaces are a whole thing, there are namespace-aware equivalents to all of these, i.e. setAttributeNS(), setAttributeNodeNS() and removeAttributeNS(). iykyk π
If you want to access the text of a node use text(), e.g.
QDomElement e = //...
//...
QString s = e.text()
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.
QString text;
QDomElement element = doc.documentElement();
for( QDomNode n = element.firstChild(); !n.isNull(); n = n.nextSibling() )
{
QDomText t = n.toText();
if ( !t.isNull() )
text += t.data();
}
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. (translation: don't be reckless, check first bestie π)
You can get a list of all the decendents of an element which have a specified tag name with elementsByTagName() or elementsByTagNameNS(). π«
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.
See also XML.
π MEMBER FUNCTION DOCUMENTATION π
QDomElement::QDomElement ()
Constructs an empty element. Use the QDomDocument::createElement() function to construct elements with content. (empty element = the blank canvas era, but you gotta use QDomDocument::createElement() if you want actual content in there β¨)
QDomElement::QDomElement ( const QDomElement & x )
Constructs a copy of x.
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(). no cap, they're linked fr fr β so if you wanted a real independent twin, cloneNode() is the move.
QDomElement::~QDomElement ()
Destroys the object and frees its resources. bye bestie π¦
QString QDomElement::attribute ( const QString & name, const QString & defValue = QString::null ) const
Returns the attribute called name. If the attribute does not exist defValue is returned. (no attribute? you get the fallback, no drama π )
See also setAttribute(), attributeNode(), setAttributeNode(), and attributeNS().
QString QDomElement::attributeNS ( const QString nsURI, const QString & localName, const QString & defValue ) const
Returns the attribute with the local name localName and the namespace URI nsURI. If the attribute does not exist defValue is returned. the namespace-aware glow-up version π
See also setAttributeNS(), attributeNodeNS(), setAttributeNodeNS(), and attribute().
QDomAttr QDomElement::attributeNode ( const QString & name )
Returns the QDomAttr object that corresponds to the attribute called name. If no such attribute exists a null attribute is returned. so always check for that null, okay? π
See also setAttributeNode(), attribute(), setAttribute(), and attributeNodeNS().
QDomAttr QDomElement::attributeNodeNS ( const QString & nsURI, const QString & localName )
Returns the QDomAttr object that corresponds to the attribute with the local name localName and the namespace URI nsURI. If no such attribute exists a null attribute is returned.
See also setAttributeNode(), attribute(), and setAttribute().
QDomNamedNodeMap QDomElement::attributes () const [virtual]
Returns a QDomNamedNodeMap containing all this element's attributes. the whole squad, assembled π
See also attribute(), setAttribute(), attributeNode(), and setAttributeNode().
Reimplemented from QDomNode.
QDomNodeList QDomElement::elementsByTagName ( const QString & tagname ) const [virtual]
Returns a QDomNodeList containing all descendent elements of this element that are called tagname. The order they are in the node list is the order they are encountered in a preorder traversal of the element tree. so the order is not random, it's literally the tree-walk order, periodt.
See also elementsByTagNameNS() and QDomDocument::elementsByTagName().
QDomNodeList QDomElement::elementsByTagNameNS ( const QString & nsURI, const QString & localName ) const [virtual]
Returns a QDomNodeList containing all the descendent elements of this element with the local name localName and the namespace URI nsURI. The order they are in the node list is the order they are encountered in a preorder traversal of the element tree.
See also elementsByTagName() and QDomDocument::elementsByTagNameNS().
bool QDomElement::hasAttribute ( const QString & name ) const
Returns TRUE if this element has an attribute called name; otherwise returns FALSE. vibe check, boolean edition β¨
bool QDomElement::hasAttributeNS ( const QString & nsURI, const QString & localName ) const
Returns TRUE if this element has an attribute with the local name localName and the namespace URI nsURI; otherwise returns FALSE.
bool QDomElement::isElement () const [virtual]
Returns TRUE. that's it. that's the whole function. it's an element, confirmed, we love a confident queen π
Reimplemented from QDomNode.
QDomNode::NodeType QDomElement::nodeType () const [virtual]
Returns ElementNode. yes, this is an element node. it said what it said π
Reimplemented from QDomNode.
QDomElement & QDomElement::operator= ( const QDomElement & x )
Assigns x to this DOM element.
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(). same warning as before bestie, they are linked, do not forget π
void QDomElement::removeAttribute ( const QString & name )
Removes the attribute called name name from this element. (yes, the original really says "name name", we are keeping that, iconic typo, no notes π)
See also setAttribute(), attribute(), and removeAttributeNS().
void QDomElement::removeAttributeNS ( const QString & nsURI, const QString & localName )
Removes the attribute with the local name localName and the namespace URI nsURI from this element. namespace-aware removal, gone girl π¨
See also setAttributeNS(), attributeNS(), and removeAttribute().
QDomAttr QDomElement::removeAttributeNode ( const QDomAttr & oldAttr )
Removes the attribute oldAttr from the element and returns it. you get it back! it's not lost, it's just evicted π«Ά
See also attributeNode() and setAttributeNode().
void QDomElement::setAttribute ( const QString & name, const QString & value )
Adds an attribute called name with value value. If an attribute with the same name exists, its value is replaced by value. so it's add-or-overwrite, no duplicates allowed π«
See also attribute(), setAttributeNode(), and setAttributeNS().
void QDomElement::setAttribute ( const QString & name, int value )
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
void QDomElement::setAttribute ( const QString & name, uint value )
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
void QDomElement::setAttribute ( const QString & name, long value )
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
void QDomElement::setAttribute ( const QString & name, ulong value )
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
void QDomElement::setAttribute ( const QString & name, double value )
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
void QDomElement::setAttributeNS ( const QString nsURI, const QString & qName, const QString & value )
Adds an attribute with the qualified name qName and the namespace URI nsURI with the value value. If an attribute with the same local name and namespace URI exists, its prefix is replaced by the prefix of qName and its value is repaced by value. (yes, "repaced" β the original's typo, preserved with love πΈ)
Although qName is the qualified name, the local name is used to decide if an existing attribute's value should be replaced. read that twice bestie, it's the sneaky bit π
See also attributeNS(), setAttributeNodeNS(), and setAttribute().
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.
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.
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.
void QDomElement::setAttributeNS ( const QString nsURI, const QString & qName,
ulong value )
okay so this one's an overloaded member function, bestie π it's literally just here for convenience and behaves essentially like the above function. no new lore, just vibes.
void QDomElement::setAttributeNS ( const QString nsURI, const QString & qName,
double value )
and THIS one? also an overloaded member function, also provided for convenience, and also behaves essentially like the above function. twin sisters, same energy, zero plot twists β¨
π setAttributeNode
QDomAttr QDomElement::setAttributeNode ( const QDomAttr & newAttr )
so this one adds the attribute newAttr to this element. that's the whole job. slay.
but here's the tea π« β if the element already has another attribute rockin' the same name as newAttr, then this function replaces that attribute and hands it back to you. and if there's no such clash? you get a null attribute. no drama, no attribute, just null.
See also:attributeNode(),setAttribute(), andsetAttributeNodeNS()β the squad is all connected, iykyk π
β¨ setAttributeNodeNS
QDomAttr QDomElement::setAttributeNodeNS ( const QDomAttr & newAttr )
same deal, namespace edition π this one adds the attribute newAttr to this element.
and the replacement rule here is a lil more specific: if the element has another attribute with the same local name AND the same namespace URI as newAttr, then this function replaces that attribute and returns it. otherwise? yep, null attribute. bye.
See also:attributeNodeNS(),setAttributeNS(), andsetAttributeNode()β matching set, matching energy π«
π setTagName
void QDomElement::setTagName ( const QString & name )
sets this element's tag name to name. that's it. that's the function. short queen behavior π
See also: tagName().
πΈ tagName
QString QDomElement::tagName () const
returns the tag name of this element. so if you've got an XML element like this:
<img src="myimg.png">
then the tagname would return "img". like, obviously, it's right there in the name bestie π
See also: setTagName().
π¦ text
QString QDomElement::text () const
returns the element's text β or QString::null if there's nothing to give you π₯²
example time, because this one's actually cute:
<h1>Hello <b>Qt</b> <![CDATA[<xml is cool>]]></h1>
the function text() of the QDomElement for the <h1> tag will return "Hello Qt <xml is cool>". look at that! it pulled the text outta the nested <b> AND the CDATA and stitched it all together π§β¨
important tho β comments are ignored by this function. it only evaluatesQDomTextandQDomCDATASectionobjects. periodt.
π SEE ALSO
π COPYRIGHT
Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the license file included in the distribution for a complete license statement.
π AUTHOR
Generated automatically from the source code.
π BUGS
if you find a bug in Qt, please report it as described in http://doc.trolltech.com/bughowto.html. good bug reports help us to help you. thank you π«Ά (genuinely, they mean it, and honestly? same.)
the definitive Qt documentation is provided in HTML format β it lives at $QTDIR/doc/html and you can read it 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. (so likeβ¦ don't come for them if the man page is a lil crusty, bestie π)
if you find errors in this manual page, please report them to qt-bugs@trolltech.com. please include the name of the manual page (qdomelement.3qt) and the Qt version (3.3.8). helps them help you, fr fr.
aaaand that's the whole page, we made it to the end together π this came from the Qt 3.3.8 docs, stamped by Trolltech AS on 2 February 2007, and the man page goes by QDomElement(3qt). go forth and parse some XML, main character π
β¨π
π¦ where this page comes from
- fedora 43: qt3-devel-docs 3.3.8b-102.fc43 Β· QPL-1.0 OR GPL-2.0-only OR GPL-3.0-only
- fedora 44: qt3-devel-docs 3.3.8b-103.fc44 Β· QPL-1.0 OR GPL-2.0-only OR GPL-3.0-only
- Copyright 1992-2007 Trolltech ASA. All rights reserved. See the
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms