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 文檔編製。
構造空屬性。
構造副本為 x .
拷貝數據是共享的 (淺拷貝):修改一節點也會改變另一節點。若想要做深拷貝,使用 cloneNode ().
返迴屬性的名稱。
返迴 AttributeNode .
返迴附加此屬性到的元素節點或 null 節點 若此屬性尚未被附加到任何元素。
將屬性的值設為 v .
另請參閱 value ().
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 ().
返迴屬性的值,或空字符串若尚未指定屬性。
另請參閱 specified () 和 setValue ().
賦值 x 到此 DOM 屬性。
拷貝數據是共享的 (淺拷貝):修改一節點也會改變另一節點。若想要做深拷貝,使用 cloneNode ().