返回介绍

QDomAttr Class

发布于 2019-10-04 14:59:44 字数 4323 浏览 1383 评论 0 收藏 0

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

#include <qdom.h>

Inherits QDomNode.

List of all member functions.

Public Members

  • QDomAttr ()
  • QDomAttr ( constQDomAttr&x )
  • QDomAttr & operator= ( constQDomAttr&x )
  • ~QDomAttr ()
  • virtual QString name () const
  • virtual bool specified () const
  • virtual QDomElement ownerElement () const
  • virtual QString value () const
  • virtual void setValue ( constQString&v )
  • virtual QDomNode::NodeType nodeType () const
  • virtual bool isAttr () const

Detailed Description

The QDomAttr class represents one attribute of a QDomElement.

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

  <link href="http://www.trolltech.com" color="red" />
  

One can use the attributes of an element with code like this:

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

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 have to 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 either set in the document or set with setValue(); otherwise the value hasn't been set. 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/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

QDomAttr::QDomAttr ()

Constructs an empty attribute.

QDomAttr::QDomAttr ( constQDomAttr&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().

QDomAttr::~QDomAttr ()

Destroys the object and frees its resources.

bool QDomAttr::isAttr () const [virtual]

Returns TRUE.

Reimplemented from QDomNode.

QString QDomAttr::name () const [virtual]

Returns the name of the attribute.

QDomNode::NodeType QDomAttr::nodeType () const [virtual]

Returns AttributeNode.

Reimplemented from QDomNode.

QDomAttr& QDomAttr::operator= ( constQDomAttr&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().

QDomElement QDomAttr::ownerElement () const [virtual]

Returns the element node, this attribute is attached to. If this attribute is not attached to any element, a null element node is returned (i.e. a node for which QDomNode::isNull() returns TRUE).

void QDomAttr::setValue ( constQString&v ) [virtual]

Sets the value of the attribute to v.

See also value().

bool QDomAttr::specified () const [virtual]

Returns TRUE if the attribute has either been expicitly specified in the XML document or was set by the user with setValue(). Returns FALSE if the value hasn't been specified or set.

See also setValue().

QString QDomAttr::value () const [virtual]

Returns the value of the attribute. Returns a null string if the attribute has not been specified.

See also specified() and setValue().

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文