Qt 4.8
Public Functions | Private Functions | Friends | List of all members
QDomElement Class Reference

The QDomElement class represents one element in the DOM tree. More...

#include <qdom.h>

Inheritance diagram for QDomElement:
QDomNode

Public Functions

QString attribute (const QString &name, const QString &defValue=QString()) const
 Returns the attribute called name. More...
 
QDomAttr attributeNode (const QString &name)
 Returns the QDomAttr object that corresponds to the attribute called name. More...
 
QDomAttr 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. More...
 
QString attributeNS (const QString nsURI, const QString &localName, const QString &defValue=QString()) const
 Returns the attribute with the local name localName and the namespace URI nsURI. More...
 
QDomNamedNodeMap attributes () const
 Returns a QDomNamedNodeMap containing all this element's attributes. More...
 
QDomNodeList elementsByTagName (const QString &tagname) const
 Returns a QDomNodeList containing all descendants of this element named tagname encountered during a preorder traversal of the element subtree with this element as its root. More...
 
QDomNodeList elementsByTagNameNS (const QString &nsURI, const QString &localName) const
 Returns a QDomNodeList containing all descendants of this element with local name localName and namespace URI nsURI encountered during a preorder traversal of the element subtree with this element as its root. More...
 
bool hasAttribute (const QString &name) const
 Returns true if this element has an attribute called name; otherwise returns false. More...
 
bool 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. More...
 
QDomNode::NodeType nodeType () const
 Returns ElementNode. More...
 
QDomElementoperator= (const QDomElement &)
 Assigns x to this DOM element. More...
 
 QDomElement ()
 Constructs an empty element. More...
 
 QDomElement (const QDomElement &x)
 Constructs a copy of x. More...
 
void removeAttribute (const QString &name)
 Removes the attribute called name name from this element. More...
 
QDomAttr removeAttributeNode (const QDomAttr &oldAttr)
 Removes the attribute oldAttr from the element and returns it. More...
 
void removeAttributeNS (const QString &nsURI, const QString &localName)
 Removes the attribute with the local name localName and the namespace URI nsURI from this element. More...
 
void setAttribute (const QString &name, const QString &value)
 Adds an attribute called name with value value. More...
 
void setAttribute (const QString &name, qlonglong value)
 The number is formatted according to the current locale. More...
 
void setAttribute (const QString &name, qulonglong value)
 The number is formatted according to the current locale. More...
 
void setAttribute (const QString &name, int value)
 The number is formatted according to the current locale. More...
 
void setAttribute (const QString &name, uint value)
 The number is formatted according to the current locale. More...
 
void setAttribute (const QString &name, float value)
 The number is formatted according to the current locale. More...
 
void setAttribute (const QString &name, double value)
 The number is formatted according to the current locale. More...
 
QDomAttr setAttributeNode (const QDomAttr &newAttr)
 Adds the attribute newAttr to this element. More...
 
QDomAttr setAttributeNodeNS (const QDomAttr &newAttr)
 Adds the attribute newAttr to this element. More...
 
void 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. More...
 
void setAttributeNS (const QString nsURI, const QString &qName, int value)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
void setAttributeNS (const QString nsURI, const QString &qName, uint value)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
void setAttributeNS (const QString nsURI, const QString &qName, qlonglong value)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
void setAttributeNS (const QString nsURI, const QString &qName, qulonglong value)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
void setAttributeNS (const QString nsURI, const QString &qName, double value)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
void setTagName (const QString &name)
 Sets this element's tag name to name. More...
 
QString tagName () const
 Returns the tag name of this element. More...
 
QString text () const
 Returns the element's text or an empty string. More...
 
- Public Functions inherited from QDomNode
QDomNode appendChild (const QDomNode &newChild)
 Appends newChild as the node's last child. More...
 
QDomNamedNodeMap attributes () const
 Returns a named node map of all attributes. More...
 
QDomNodeList childNodes () const
 Returns a list of all direct child nodes. More...
 
void clear ()
 Converts the node into a null node; if it was not a null node before, its type and contents are deleted. More...
 
QDomNode cloneNode (bool deep=true) const
 Creates a deep (not shallow) copy of the QDomNode. More...
 
int columnNumber () const
 For nodes created by QDomDocument::setContent(), this function returns the column number in the XML document where the node was parsed. More...
 
QDomNode firstChild () const
 Returns the first child of the node. More...
 
QDomElement firstChildElement (const QString &tagName=QString()) const
 Returns the first child element with tag name tagName if tagName is non-empty; otherwise returns the first child element. More...
 
bool hasAttributes () const
 Returns true if the node has attributes; otherwise returns false. More...
 
bool hasChildNodes () const
 Returns true if the node has one or more children; otherwise returns false. More...
 
QDomNode insertAfter (const QDomNode &newChild, const QDomNode &refChild)
 Inserts the node newChild after the child node refChild. More...
 
QDomNode insertBefore (const QDomNode &newChild, const QDomNode &refChild)
 Inserts the node newChild before the child node refChild. More...
 
bool isAttr () const
 Returns true if the node is an attribute; otherwise returns false. More...
 
bool isCDATASection () const
 Returns true if the node is a CDATA section; otherwise returns false. More...
 
bool isCharacterData () const
 Returns true if the node is a character data node; otherwise returns false. More...
 
bool isComment () const
 Returns true if the node is a comment; otherwise returns false. More...
 
bool isDocument () const
 Returns true if the node is a document; otherwise returns false. More...
 
bool isDocumentFragment () const
 Returns true if the node is a document fragment; otherwise returns false. More...
 
bool isDocumentType () const
 Returns true if the node is a document type; otherwise returns false. More...
 
bool isElement () const
 Returns true if the node is an element; otherwise returns false. More...
 
bool isEntity () const
 Returns true if the node is an entity; otherwise returns false. More...
 
bool isEntityReference () const
 Returns true if the node is an entity reference; otherwise returns false. More...
 
bool isNotation () const
 Returns true if the node is a notation; otherwise returns false. More...
 
bool isNull () const
 Returns true if this node is null (i.e. More...
 
bool isProcessingInstruction () const
 Returns true if the node is a processing instruction; otherwise returns false. More...
 
bool isSupported (const QString &feature, const QString &version) const
 Returns true if the DOM implementation implements the feature feature and this feature is supported by this node in the version version; otherwise returns false. More...
 
bool isText () const
 Returns true if the node is a text node; otherwise returns false. More...
 
QDomNode lastChild () const
 Returns the last child of the node. More...
 
QDomElement lastChildElement (const QString &tagName=QString()) const
 Returns the last child element with tag name tagName if tagName is non-empty; otherwise returns the last child element. More...
 
int lineNumber () const
 For nodes created by QDomDocument::setContent(), this function returns the line number in the XML document where the node was parsed. More...
 
QString localName () const
 If the node uses namespaces, this function returns the local name of the node; otherwise it returns an empty string. More...
 
QDomNode namedItem (const QString &name) const
 Returns the first direct child node for which nodeName() equals name. More...
 
QString namespaceURI () const
 Returns the namespace URI of this node or an empty string if the node has no namespace URI. More...
 
QDomNode nextSibling () const
 Returns the next sibling in the document tree. More...
 
QDomElement nextSiblingElement (const QString &taName=QString()) const
 Returns the next sibling element with tag name tagName if tagName is non-empty; otherwise returns any next sibling element. More...
 
QString nodeName () const
 Returns the name of the node. More...
 
NodeType nodeType () const
 Returns the type of the node. More...
 
QString nodeValue () const
 Returns the value of the node. More...
 
void normalize ()
 Calling normalize() on an element converts all its children into a standard form. More...
 
bool operator!= (const QDomNode &) const
 Returns true if n and this DOM node are not equal; otherwise returns false. More...
 
QDomNodeoperator= (const QDomNode &)
 Assigns a copy of n to this DOM node. More...
 
bool operator== (const QDomNode &) const
 Returns true if n and this DOM node are equal; otherwise returns false. More...
 
QDomDocument ownerDocument () const
 Returns the document to which this node belongs. More...
 
QDomNode parentNode () const
 Returns the parent node. More...
 
QString prefix () const
 Returns the namespace prefix of the node or an empty string if the node has no namespace prefix. More...
 
QDomNode previousSibling () const
 Returns the previous sibling in the document tree. More...
 
QDomElement previousSiblingElement (const QString &tagName=QString()) const
 Returns the previous sibilng element with tag name tagName if tagName is non-empty; otherwise returns any previous sibling element. More...
 
 QDomNode ()
 Constructs a null node. More...
 
 QDomNode (const QDomNode &)
 Constructs a copy of n. More...
 
QDomNode removeChild (const QDomNode &oldChild)
 Removes oldChild from the list of children. More...
 
QDomNode replaceChild (const QDomNode &newChild, const QDomNode &oldChild)
 Replaces oldChild with newChild. More...
 
void save (QTextStream &, int) const
 Writes the XML representation of the node and all its children to the stream str. More...
 
void save (QTextStream &, int, EncodingPolicy) const
 If encodingPolicy is QDomNode::EncodingFromDocument, this function behaves as save(QTextStream &str, int indent). More...
 
void setNodeValue (const QString &)
 Sets the node's value to v. More...
 
void setPrefix (const QString &pre)
 If the node has a namespace prefix, this function changes the namespace prefix of the node to pre. More...
 
QDomAttr toAttr () const
 Converts a QDomNode into a QDomAttr. More...
 
QDomCDATASection toCDATASection () const
 Converts a QDomNode into a QDomCDATASection. More...
 
QDomCharacterData toCharacterData () const
 Converts a QDomNode into a QDomCharacterData. More...
 
QDomComment toComment () const
 Converts a QDomNode into a QDomComment. More...
 
QDomDocument toDocument () const
 Converts a QDomNode into a QDomDocument. More...
 
QDomDocumentFragment toDocumentFragment () const
 Converts a QDomNode into a QDomDocumentFragment. More...
 
QDomDocumentType toDocumentType () const
 Converts a QDomNode into a QDomDocumentType. More...
 
QDomElement toElement () const
 Converts a QDomNode into a QDomElement. More...
 
QDomEntity toEntity () const
 Converts a QDomNode into a QDomEntity. More...
 
QDomEntityReference toEntityReference () const
 Converts a QDomNode into a QDomEntityReference. More...
 
QDomNotation toNotation () const
 Converts a QDomNode into a QDomNotation. More...
 
QDomProcessingInstruction toProcessingInstruction () const
 Converts a QDomNode into a QDomProcessingInstruction. More...
 
QDomText toText () const
 Converts a QDomNode into a QDomText. More...
 
 ~QDomNode ()
 Destroys the object and frees its resources. More...
 

Private Functions

 QDomElement (QDomElementPrivate *)
 

Friends

class QDomAttr
 
class QDomDocument
 
class QDomNode
 

Additional Inherited Members

- Public Types inherited from QDomNode
enum  EncodingPolicy { EncodingFromDocument = 1, EncodingFromTextStream = 2 }
 This enum specifies how QDomNode::save() determines what encoding to use when serializing. More...
 
enum  NodeType {
  ElementNode = 1, AttributeNode = 2, TextNode = 3, CDATASectionNode = 4,
  EntityReferenceNode = 5, EntityNode = 6, ProcessingInstructionNode = 7, CommentNode = 8,
  DocumentNode = 9, DocumentTypeNode = 10, DocumentFragmentNode = 11, NotationNode = 12,
  BaseNode = 21, CharacterDataNode = 22
}
 This enum defines the type of the node: More...
 
- Protected Functions inherited from QDomNode
 QDomNode (QDomNodePrivate *)
 Constructs a new node for the data n. More...
 
- Protected Variables inherited from QDomNode
QDomNodePrivateimpl
 

Detailed Description

The QDomElement class represents one element in the DOM tree.

Note
This class or function is reentrant.
Attention
Module: QtXml

Elements have a tagName() and zero or more attributes associated with them. The tag name can be changed with setTagName().

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

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.

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.

You can get a list of all the decendents of an element which have a specified tag name with elementsByTagName() or elementsByTagNameNS().

To browse the elements of a dom document use firstChildElement(), lastChildElement(), nextSiblingElement() and previousSiblingElement(). For example, to iterate over all child elements called "entry" in a root element called "database", you can use:

QDomDocument doc = // ...
QDomElement root = doc.firstChildElement("database");
QDomElement elt = root.firstChildElement("entry");
for (; !elt.isNull(); elt = elt.nextSiblingElement("entry")) {
// ...
}

For further information about the Document Object Model see Level 1 and Level 2 Core. For a more general introduction of the DOM implementation see the QDomDocument documentation.

Definition at line 476 of file qdom.h.

Constructors and Destructors

◆ QDomElement() [1/3]

QDomElement::QDomElement ( )

Constructs an empty element.

Use the QDomDocument::createElement() function to construct elements with content.

Definition at line 4808 of file qdom.cpp.

4809  : QDomNode()
4810 {
4811 }
QDomNode()
Constructs a null node.
Definition: qdom.cpp:2057

◆ QDomElement() [2/3]

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

Definition at line 4820 of file qdom.cpp.

4821  : QDomNode(x)
4822 {
4823 }
QDomNode()
Constructs a null node.
Definition: qdom.cpp:2057

◆ QDomElement() [3/3]

QDomElement::QDomElement ( QDomElementPrivate n)
private

Definition at line 4825 of file qdom.cpp.

4826  : QDomNode(n)
4827 {
4828 }
QDomNode()
Constructs a null node.
Definition: qdom.cpp:2057

Functions

◆ attribute()

QString QDomElement::attribute ( const QString name,
const QString defValue = QString() 
) const

Returns the attribute called name.

If the attribute does not exist defValue is returned.

See also
setAttribute() attributeNode() setAttributeNode() attributeNS()

Definition at line 4897 of file qdom.cpp.

Referenced by QDBusXmlParser::interfaces(), QDBusXmlParser::object(), QDBusXmlParser::objectTree(), parseAnnotations(), and parseArgs().

4898 {
4899  if (!impl)
4900  return defValue;
4901  return IMPL->attribute(name, defValue);
4902 }
QDomNodePrivate * impl
Definition: qdom.h:243
#define IMPL
Definition: qdom.cpp:6666

◆ attributeNode()

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.

See also
setAttributeNode() attribute() setAttribute() attributeNodeNS()

Definition at line 5030 of file qdom.cpp.

5031 {
5032  if (!impl)
5033  return QDomAttr();
5034  return QDomAttr(IMPL->attributeNode(name));
5035 }
friend class QDomAttr
Definition: qdom.h:531
QDomNodePrivate * impl
Definition: qdom.h:243
#define IMPL
Definition: qdom.cpp:6666

◆ 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() setAttribute()

Definition at line 5203 of file qdom.cpp.

5204 {
5205  if (!impl)
5206  return QDomAttr();
5207  return QDomAttr(IMPL->attributeNodeNS(nsURI, localName));
5208 }
friend class QDomAttr
Definition: qdom.h:531
QDomNodePrivate * impl
Definition: qdom.h:243
#define IMPL
Definition: qdom.cpp:6666

◆ attributeNS()

QString QDomElement::attributeNS ( const QString  nsURI,
const QString localName,
const QString defValue = QString() 
) const

Returns the attribute with the local name localName and the namespace URI nsURI.

If the attribute does not exist defValue is returned.

See also
setAttributeNS() attributeNodeNS() setAttributeNodeNS() attribute()

Definition at line 5106 of file qdom.cpp.

5107 {
5108  if (!impl)
5109  return defValue;
5110  return IMPL->attributeNS(nsURI, localName, defValue);
5111 }
QDomNodePrivate * impl
Definition: qdom.h:243
#define IMPL
Definition: qdom.cpp:6666

◆ attributes()

QDomNamedNodeMap QDomElement::attributes ( ) const

Returns a QDomNamedNodeMap containing all this element's attributes.

See also
attribute() setAttribute() attributeNode() setAttributeNode()

Definition at line 4884 of file qdom.cpp.

4885 {
4886  if (!impl)
4887  return QDomNamedNodeMap();
4888  return QDomNamedNodeMap(IMPL->attributes());
4889 }
friend class QDomNamedNodeMap
Definition: qdom.h:250
QDomNodePrivate * impl
Definition: qdom.h:243
#define IMPL
Definition: qdom.cpp:6666

◆ elementsByTagName()

QDomNodeList QDomElement::elementsByTagName ( const QString tagname) const

Returns a QDomNodeList containing all descendants of this element named tagname encountered during a preorder traversal of the element subtree with this element as its root.

The order of the elements in the returned list is the order they are encountered during the preorder traversal.

See also
elementsByTagNameNS() QDomDocument::elementsByTagName()

Definition at line 5075 of file qdom.cpp.

Referenced by QDBusXmlParser::interfaces(), QDBusXmlParser::object(), QDBusXmlParser::objectTree(), parseAnnotations(), and parseArgs().

5076 {
5077  return QDomNodeList(new QDomNodeListPrivate(impl, tagname));
5078 }
friend class QDomNodeList
Definition: qdom.h:249
QDomNodePrivate * impl
Definition: qdom.h:243

◆ elementsByTagNameNS()

QDomNodeList QDomElement::elementsByTagNameNS ( const QString nsURI,
const QString localName 
) const

Returns a QDomNodeList containing all descendants of this element with local name localName and namespace URI nsURI encountered during a preorder traversal of the element subtree with this element as its root.

The order of the elements in the returned list is the order they are encountered during the preorder traversal.

See also
elementsByTagName() QDomDocument::elementsByTagNameNS()

Definition at line 5236 of file qdom.cpp.

5237 {
5238  return QDomNodeList(new QDomNodeListPrivate(impl, nsURI, localName));
5239 }
friend class QDomNodeList
Definition: qdom.h:249
QDomNodePrivate * impl
Definition: qdom.h:243

◆ hasAttribute()

bool QDomElement::hasAttribute ( const QString name) const

Returns true if this element has an attribute called name; otherwise returns false.

Note: This function does not take the presence of namespaces into account. As a result, the specified name will be tested against fully-qualified attribute names that include any namespace prefixes that may be present.

Use hasAttributeNS() to explicitly test for attributes with specific namespaces and names.

Definition at line 5092 of file qdom.cpp.

Referenced by parseArgs().

5093 {
5094  if (!impl)
5095  return false;
5096  return IMPL->hasAttribute(name);
5097 }
QDomNodePrivate * impl
Definition: qdom.h:243
#define IMPL
Definition: qdom.cpp:6666

◆ hasAttributeNS()

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.

Definition at line 5246 of file qdom.cpp.

5247 {
5248  if (!impl)
5249  return false;
5250  return IMPL->hasAttributeNS(nsURI, localName);
5251 }
QDomNodePrivate * impl
Definition: qdom.h:243
#define IMPL
Definition: qdom.cpp:6666

◆ nodeType()

QDomNode::NodeType QDomElement::nodeType ( ) const
inline

Returns ElementNode.

Definition at line 522 of file qdom.h.

522 { return ElementNode; }

◆ operator=()

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

Definition at line 4837 of file qdom.cpp.

4838 {
4839  return (QDomElement&) QDomNode::operator=(x);
4840 }
QDomNode & operator=(const QDomNode &)
Assigns a copy of n to this DOM node.
Definition: qdom.cpp:2096
The QDomElement class represents one element in the DOM tree.
Definition: qdom.h:476

◆ removeAttribute()

void QDomElement::removeAttribute ( const QString name)

Removes the attribute called name name from this element.

See also
setAttribute() attribute() removeAttributeNS()

Definition at line 5016 of file qdom.cpp.

5017 {
5018  if (!impl)
5019  return;
5020  IMPL->removeAttribute(name);
5021 }
QDomNodePrivate * impl
Definition: qdom.h:243
#define IMPL
Definition: qdom.cpp:6666

◆ removeAttributeNode()

QDomAttr QDomElement::removeAttributeNode ( const QDomAttr oldAttr)

Removes the attribute oldAttr from the element and returns it.

See also
attributeNode() setAttributeNode()

Definition at line 5059 of file qdom.cpp.

5060 {
5061  if (!impl)
5062  return QDomAttr(); // ### should this return oldAttr?
5063  return QDomAttr(IMPL->removeAttributeNode(((QDomAttrPrivate*)oldAttr.impl)));
5064 }
friend class QDomAttr
Definition: qdom.h:531
QDomNodePrivate * impl
Definition: qdom.h:243
#define IMPL
Definition: qdom.cpp:6666

◆ 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.

See also
setAttributeNS() attributeNS() removeAttribute()

Definition at line 5186 of file qdom.cpp.

5187 {
5188  if (!impl)
5189  return;
5190  QDomNodePrivate *n = IMPL->attributeNodeNS(nsURI, localName);
5191  if (!n)
5192  return;
5193  IMPL->removeAttribute(n->nodeName());
5194 }
QDomNodePrivate * impl
Definition: qdom.h:243
#define IMPL
Definition: qdom.cpp:6666
QString nodeName() const
Definition: qdom.cpp:142

◆ setAttribute() [1/7]

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.

See also
attribute() setAttributeNode() setAttributeNS()

Definition at line 4911 of file qdom.cpp.

4912 {
4913  if (!impl)
4914  return;
4915  IMPL->setAttribute(name, value);
4916 }
QDomNodePrivate * impl
Definition: qdom.h:243
#define IMPL
Definition: qdom.cpp:6666

◆ setAttribute() [2/7]

void QDomElement::setAttribute ( const QString name,
qlonglong  value 
)

The number is formatted according to the current locale.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 4946 of file qdom.cpp.

4947 {
4948  if (!impl)
4949  return;
4950  QString x;
4951  x.setNum(value);
4952  IMPL->setAttribute(name, x);
4953 }
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString & setNum(short, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.h:729
QDomNodePrivate * impl
Definition: qdom.h:243
#define IMPL
Definition: qdom.cpp:6666

◆ setAttribute() [3/7]

void QDomElement::setAttribute ( const QString name,
qulonglong  value 
)

The number is formatted according to the current locale.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 4963 of file qdom.cpp.

4964 {
4965  if (!impl)
4966  return;
4967  QString x;
4968  x.setNum(value);
4969  IMPL->setAttribute(name, x);
4970 }
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString & setNum(short, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.h:729
QDomNodePrivate * impl
Definition: qdom.h:243
#define IMPL
Definition: qdom.cpp:6666

◆ setAttribute() [4/7]

void QDomElement::setAttribute ( const QString name,
int  value 
)
inline

The number is formatted according to the current locale.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 488 of file qdom.h.

489  { setAttribute(name, qlonglong(value)); }
void setAttribute(const QString &name, const QString &value)
Adds an attribute called name with value value.
Definition: qdom.cpp:4911
qint64 qlonglong
Definition: qglobal.h:951

◆ setAttribute() [5/7]

void QDomElement::setAttribute ( const QString name,
uint  value 
)
inline

The number is formatted according to the current locale.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 490 of file qdom.h.

491  { setAttribute(name, qulonglong(value)); }
quint64 qulonglong
Definition: qglobal.h:952
void setAttribute(const QString &name, const QString &value)
Adds an attribute called name with value value.
Definition: qdom.cpp:4911

◆ setAttribute() [6/7]

void QDomElement::setAttribute ( const QString name,
float  value 
)

The number is formatted according to the current locale.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 4980 of file qdom.cpp.

4981 {
4982  if (!impl)
4983  return;
4984  QString x;
4985  x.setNum(value);
4986  IMPL->setAttribute(name, x);
4987 }
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString & setNum(short, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.h:729
QDomNodePrivate * impl
Definition: qdom.h:243
#define IMPL
Definition: qdom.cpp:6666

◆ setAttribute() [7/7]

void QDomElement::setAttribute ( const QString name,
double  value 
)

The number is formatted according to the current locale.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 4997 of file qdom.cpp.

4998 {
4999  if (!impl)
5000  return;
5001  QString x;
5002  char buf[256];
5003  int count = qsnprintf(buf, sizeof(buf), "%.16g", value);
5004  if (count > 0)
5005  x = QString::fromLatin1(buf, count);
5006  else
5007  x.setNum(value); // Fallback
5008  IMPL->setAttribute(name, x);
5009 }
Q_CORE_EXPORT int qsnprintf(char *str, size_t n, const char *fmt,...)
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString & setNum(short, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.h:729
QDomNodePrivate * impl
Definition: qdom.h:243
#define IMPL
Definition: qdom.cpp:6666
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188

◆ setAttributeNode()

QDomAttr QDomElement::setAttributeNode ( const QDomAttr newAttr)

Adds the attribute newAttr to this element.

If the element has another attribute that has the same name as newAttr, this function replaces that attribute and returns it; otherwise the function returns a null attribute.

See also
attributeNode() setAttribute() setAttributeNodeNS()

Definition at line 5047 of file qdom.cpp.

5048 {
5049  if (!impl)
5050  return QDomAttr();
5051  return QDomAttr(IMPL->setAttributeNode(((QDomAttrPrivate*)newAttr.impl)));
5052 }
friend class QDomAttr
Definition: qdom.h:531
QDomNodePrivate * impl
Definition: qdom.h:243
#define IMPL
Definition: qdom.cpp:6666

◆ setAttributeNodeNS()

QDomAttr QDomElement::setAttributeNodeNS ( const QDomAttr newAttr)

Adds the attribute newAttr to this element.

If the element has another attribute that has the same local name and namespace URI as newAttr, this function replaces that attribute and returns it; otherwise the function returns a null attribute.

See also
attributeNodeNS() setAttributeNS() setAttributeNode()

Definition at line 5220 of file qdom.cpp.

5221 {
5222  if (!impl)
5223  return QDomAttr();
5224  return QDomAttr(IMPL->setAttributeNodeNS(((QDomAttrPrivate*)newAttr.impl)));
5225 }
friend class QDomAttr
Definition: qdom.h:531
QDomNodePrivate * impl
Definition: qdom.h:243
#define IMPL
Definition: qdom.cpp:6666

◆ setAttributeNS() [1/6]

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.

Although qName is the qualified name, the local name is used to decide if an existing attribute's value should be replaced.

See also
attributeNS() setAttributeNodeNS() setAttribute()

Definition at line 5125 of file qdom.cpp.

5126 {
5127  if (!impl)
5128  return;
5129  IMPL->setAttributeNS(nsURI, qName, value);
5130 }
QDomNodePrivate * impl
Definition: qdom.h:243
#define IMPL
Definition: qdom.cpp:6666

◆ setAttributeNS() [2/6]

void QDomElement::setAttributeNS ( const QString  nsURI,
const QString qName,
int  value 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 503 of file qdom.h.

504  { setAttributeNS(nsURI, qName, qlonglong(value)); }
void 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...
Definition: qdom.cpp:5125
qint64 qlonglong
Definition: qglobal.h:951

◆ setAttributeNS() [3/6]

void QDomElement::setAttributeNS ( const QString  nsURI,
const QString qName,
uint  value 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 505 of file qdom.h.

506  { setAttributeNS(nsURI, qName, qulonglong(value)); }
void 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...
Definition: qdom.cpp:5125
quint64 qulonglong
Definition: qglobal.h:952

◆ setAttributeNS() [4/6]

void QDomElement::setAttributeNS ( const QString  nsURI,
const QString qName,
qlonglong  value 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 5147 of file qdom.cpp.

5148 {
5149  if (!impl)
5150  return;
5151  QString x;
5152  x.setNum(value);
5153  IMPL->setAttributeNS(nsURI, qName, x);
5154 }
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString & setNum(short, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.h:729
QDomNodePrivate * impl
Definition: qdom.h:243
#define IMPL
Definition: qdom.cpp:6666

◆ setAttributeNS() [5/6]

void QDomElement::setAttributeNS ( const QString  nsURI,
const QString qName,
qulonglong  value 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 5159 of file qdom.cpp.

5160 {
5161  if (!impl)
5162  return;
5163  QString x;
5164  x.setNum(value);
5165  IMPL->setAttributeNS(nsURI, qName, x);
5166 }
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString & setNum(short, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.h:729
QDomNodePrivate * impl
Definition: qdom.h:243
#define IMPL
Definition: qdom.cpp:6666

◆ setAttributeNS() [6/6]

void QDomElement::setAttributeNS ( const QString  nsURI,
const QString qName,
double  value 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 5171 of file qdom.cpp.

5172 {
5173  if (!impl)
5174  return;
5175  QString x;
5176  x.setNum(value);
5177  IMPL->setAttributeNS(nsURI, qName, x);
5178 }
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString & setNum(short, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.h:729
QDomNodePrivate * impl
Definition: qdom.h:243
#define IMPL
Definition: qdom.cpp:6666

◆ setTagName()

void QDomElement::setTagName ( const QString name)

Sets this element's tag name to name.

See also
tagName()

Definition at line 4856 of file qdom.cpp.

4857 {
4858  if (impl)
4859  impl->name = name;
4860 }
QString name
Definition: qdom.cpp:198
const char * name
QDomNodePrivate * impl
Definition: qdom.h:243

◆ tagName()

QString QDomElement::tagName ( ) const

Returns the tag name of this element.

For an XML element like this:

<img src="myimg.png">

the tagname would return "img".

See also
setTagName()

Definition at line 4871 of file qdom.cpp.

Referenced by QDomNode::firstChildElement(), QDomNode::lastChildElement(), QDomNode::nextSiblingElement(), and QDomNode::previousSiblingElement().

4872 {
4873  if (!impl)
4874  return QString();
4875  return impl->nodeName();
4876 }
The QString class provides a Unicode character string.
Definition: qstring.h:83
QDomNodePrivate * impl
Definition: qdom.h:243
QString nodeName() const
Definition: qdom.cpp:142

◆ text()

QString QDomElement::text ( ) const

Returns the element's text or an empty string.

Example:

<h1>Hello <b>Qt</b> <![CDATA[<xml is cool>]]></h1>

The function text() of the QDomElement for the

tag, will return the following text: doc/src/snippets/code/src_xml_dom_qdom.cpp 14 Comments are ignored by this function. It only evaluates QDomText and QDomCDATASection objects.

Definition at line 5267 of file qdom.cpp.

5268 {
5269  if (!impl)
5270  return QString();
5271  return IMPL->text();
5272 }
The QString class provides a Unicode character string.
Definition: qstring.h:83
QDomNodePrivate * impl
Definition: qdom.h:243
#define IMPL
Definition: qdom.cpp:6666

Friends and Related Functions

◆ QDomAttr

friend class QDomAttr
friend

Definition at line 531 of file qdom.h.

◆ QDomDocument

friend class QDomDocument
friend

Definition at line 529 of file qdom.h.

◆ QDomNode

friend class QDomNode
friend

Definition at line 530 of file qdom.h.


The documentation for this class was generated from the following files: