QDomAttr 类

The QDomAttr 类表示一属性为 QDomElement . 更多...

头: #include <QDomAttr>
继承: QDomNode

注意: 此类的所有函数 可重入 .

公共函数

QDomAttr ()
QDomAttr (const QDomAttr & x )
QString name () const
QDomNode::NodeType nodeType () const
QDomElement ownerElement () const
void setValue (const QString & v )
bool specified () const
QString value () const
QDomAttr & operator= (const QDomAttr & x )

详细描述

The QDomAttr 类表示一属性为 QDomElement .

例如,以下 XML 片段产生不带子级但有 2 属性的元素:

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

可以采用像这样的代码访问元素属性:

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"
					

此范例展示改变接收自元素的属性还会改变元素的属性。若不希望改变元素属性值,则必须使用 cloneNode () 以获取属性的独立副本。

QDomAttr 可以返回 name () 和 value () 为属性。属性值的设置采用 setValue ()。若 specified () 返回 true,有设置值采用 setValue ()。附加此属性的节点 (若有的话) 的返回通过 ownerElement ().

有关文档对象模型的进一步信息,见 http://www.w3.org/TR/REC-DOM-Level-1/ and http://www.w3.org/TR/DOM-Level-2-Core/ 。有关 DOM 实现的更一般介绍,见 QDomDocument 文档编制。

成员函数文档编制

QDomAttr:: QDomAttr ()

构造空属性。

QDomAttr:: QDomAttr (const QDomAttr & x )

构造副本为 x .

拷贝数据是共享的 (浅拷贝):修改一节点也会改变另一节点。若想要做深拷贝,使用 cloneNode ().

QString QDomAttr:: name () const

返回属性的名称。

QDomNode::NodeType QDomAttr:: nodeType () const

返回 AttributeNode .

QDomElement QDomAttr:: ownerElement () const

返回附加此属性到的元素节点或 null 节点 若此属性尚未被附加到任何元素。

void QDomAttr:: setValue (const QString & v )

将属性的值设为 v .

另请参阅 value ().

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.

另请参阅 setValue ().

QString QDomAttr:: value () const

返回属性的值,或空字符串若尚未指定属性。

另请参阅 specified () 和 setValue ().

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

赋值 x 到此 DOM 属性。

拷贝数据是共享的 (浅拷贝):修改一节点也会改变另一节点。若想要做深拷贝,使用 cloneNode ().