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

The QDomAttr class represents one attribute of a QDomElement. More...

#include <qdom.h>

Inheritance diagram for QDomAttr:
QDomNode

Public Functions

QString name () const
 Returns the attribute's name. More...
 
QDomNode::NodeType nodeType () const
 Returns AttributeNode. More...
 
QDomAttroperator= (const QDomAttr &)
 Assigns x to this DOM attribute. More...
 
QDomElement ownerElement () const
 Returns the element node this attribute is attached to or a null node if this attribute is not attached to any element. More...
 
 QDomAttr ()
 Constructs an empty attribute. More...
 
 QDomAttr (const QDomAttr &x)
 Constructs a copy of x. More...
 
void setValue (const QString &)
 Sets the attribute's value to v. More...
 
bool specified () const
 Returns true if the attribute has been set by the user with setValue(). More...
 
QString value () const
 Returns the value of the attribute or an empty string if the attribute has not been specified. 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

 QDomAttr (QDomAttrPrivate *)
 

Friends

class QDomDocument
 
class QDomElement
 
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 QDomAttr class represents one attribute of a QDomElement.

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

For example, the following piece of XML produces an element with no children, but two attributes:

<link href="http://qt.nokia.com" color="red" />

You can access the attributes of an element with code like this:

QDomElement e = //...
//...
QDomAttr a = e.attributeNode("href");
cout << a.value() << endl; // prints "http://qt.nokia.com"
a.setValue("http://qt.nokia.com/doc"); // change the node's attribute
QDomAttr a2 = e.attributeNode("href");
cout << a2.value() << endl; // prints "http://qt.nokia.com/doc"

This example also shows that changing an attribute received from an element changes the attribute of the element. If you do not want to change the value of the element's attribute you must use cloneNode() to get an independent copy of the attribute.

QDomAttr can return the name() and value() of an attribute. An attribute's value is set with setValue(). If specified() returns true the value was set with setValue(). The node this attribute is attached to (if any) is returned by ownerElement().

For further information about the Document Object Model see http://www.w3.org/TR/DOM-Level-2-Core/. For a more general introduction of the DOM implementation see the QDomDocument documentation.

Definition at line 449 of file qdom.h.

Constructors and Destructors

◆ QDomAttr() [1/3]

QDomAttr::QDomAttr ( )

Constructs an empty attribute.

Definition at line 4384 of file qdom.cpp.

4385 {
4386 }

◆ QDomAttr() [2/3]

QDomAttr::QDomAttr ( const QDomAttr 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 4395 of file qdom.cpp.

4396  : QDomNode(x)
4397 {
4398 }
QDomNode()
Constructs a null node.
Definition: qdom.cpp:2057

◆ QDomAttr() [3/3]

QDomAttr::QDomAttr ( QDomAttrPrivate n)
private

Definition at line 4400 of file qdom.cpp.

4401  : QDomNode(n)
4402 {
4403 }
QDomNode()
Constructs a null node.
Definition: qdom.cpp:2057

Functions

◆ name()

QString QDomAttr::name ( ) const

Returns the attribute's name.

Definition at line 4420 of file qdom.cpp.

4421 {
4422  if (!impl)
4423  return QString();
4424  return impl->nodeName();
4425 }
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

◆ nodeType()

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

Returns AttributeNode.

Definition at line 466 of file qdom.h.

466 { return AttributeNode; }

◆ operator=()

QDomAttr & QDomAttr::operator= ( const QDomAttr x)

Assigns x to this DOM attribute.

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 4412 of file qdom.cpp.

4413 {
4414  return (QDomAttr&) QDomNode::operator=(x);
4415 }
QDomNode & operator=(const QDomNode &)
Assigns a copy of n to this DOM node.
Definition: qdom.cpp:2096
The QDomAttr class represents one attribute of a QDomElement.
Definition: qdom.h:449

◆ ownerElement()

QDomElement QDomAttr::ownerElement ( ) const

Returns the element node this attribute is attached to or a null node if this attribute is not attached to any element.

Definition at line 4445 of file qdom.cpp.

4446 {
4447  Q_ASSERT(impl->parent());
4448  if (!impl->parent()->isElement())
4449  return QDomElement();
4450  return QDomElement((QDomElementPrivate*)(impl->parent()));
4451 }
QDomNodePrivate * parent() const
Definition: qdom.cpp:161
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
virtual bool isElement() const
Definition: qdom.cpp:175
QDomNodePrivate * impl
Definition: qdom.h:243
friend class QDomElement
Definition: qdom.h:472

◆ setValue()

void QDomAttr::setValue ( const QString v)

Sets the attribute's value to v.

See also
value()

Definition at line 4471 of file qdom.cpp.

4472 {
4473  if (!impl)
4474  return;
4475  impl->setNodeValue(v);
4476  IMPL->m_specified = true;
4477 }
QDomNodePrivate * impl
Definition: qdom.h:243
#define IMPL
Definition: qdom.cpp:6666
virtual void setNodeValue(const QString &v)
Definition: qdom.cpp:144

◆ specified()

bool QDomAttr::specified ( ) const

Returns true if the attribute has been set by the user with setValue().

Returns false if the value hasn't been specified or set.

See also
setValue()

Definition at line 4433 of file qdom.cpp.

4434 {
4435  if (!impl)
4436  return false;
4437  return IMPL->specified();
4438 }
QDomNodePrivate * impl
Definition: qdom.h:243
#define IMPL
Definition: qdom.cpp:6666

◆ value()

QString QDomAttr::value ( ) const

Returns the value of the attribute or an empty string if the attribute has not been specified.

See also
specified() setValue()

Definition at line 4459 of file qdom.cpp.

4460 {
4461  if (!impl)
4462  return QString();
4463  return impl->nodeValue();
4464 }
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString nodeValue() const
Definition: qdom.cpp:143
QDomNodePrivate * impl
Definition: qdom.h:243

Friends and Related Functions

◆ QDomDocument

friend class QDomDocument
friend

Definition at line 471 of file qdom.h.

◆ QDomElement

friend class QDomElement
friend

Definition at line 472 of file qdom.h.

Referenced by ownerElement().

◆ QDomNode

friend class QDomNode
friend

Definition at line 473 of file qdom.h.


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