QDomAttr 類

QDomAttr 類錶示一屬性為 QDomElement . 更多...

頭: #include <QDomAttr>
qmake: QT += xml
繼承: QDomNode

注意: 此類的所有函數 可重入 .

公共函數

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

詳細描述

例如,以下 XML 片段産生不帶子級但有 2 屬性的元素:

<link href="http://qt-project.org" color="red" />
					

可以采用像這樣的代碼訪問元素屬性:

QDomElement e = //...
//...
QDomAttr a = e.attributeNode("href");
cout << a.value() << Qt::endl;                // prints "http://qt-project.org"
a.setValue("http://qt-project.org/doc"); // change the node's attribute
QDomAttr a2 = e.attributeNode("href");
cout << a2.value() << Qt::endl;               // prints "http://qt-project.org/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 (const QDomAttr & x )

構造副本為 x .

拷貝數據是共享的 (淺拷貝):修改一節點也會改變另一節點。若想要做深拷貝,使用 cloneNode ().

QDomAttr:: QDomAttr ()

構造空屬性。

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

賦值 x 到此 DOM 屬性。

拷貝數據是共享的 (淺拷貝):修改一節點也會改變另一節點。若想要做深拷貝,使用 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

返迴 true 若有設置屬性由用戶采用 setValue ()。返迴 false 若尚未指定或設置值。

另請參閱 setValue ().

QString QDomAttr:: value () const

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

另請參閱 specified () 和 setValue ().