QDomAttr Class
QDomAttrクラスは、QDomElement の1つの属性を表します。
ヘッダ | #include <QDomAttr> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Xml) target_link_libraries(mytarget PRIVATE Qt6::Xml) |
qmake: | QT += xml |
継承: | QDomNode |
- 継承メンバを含む全メンバのリスト
- QDomAttrはXMLクラスの一部です。
注意:このクラスの関数はすべてリエントラントです。
パブリック関数
QDomAttr() | |
QDomAttr(const QDomAttr &attr) | |
QString | name() const |
QDomNode::NodeType | nodeType() const |
QDomElement | ownerElement() const |
void | setValue(const QString &value) |
bool | specified() const |
QString | value() const |
QDomAttr & | operator=(const QDomAttr &other) |
詳細説明
例えば、次のようなXMLは、子要素を持たず、2つの属性を持つ要素を生成します:
<link href="http://qt-project.org" color="red" />
このようなコードで要素の属性にアクセスできます:
QDomElement e; //... QDomAttr a = e.attributeNode("href"); cout << qPrintable(a.value()) << '\n'; // prints "http://qt-project.org" a.setValue("http://qt-project.org/doc"); // change the node's attribute QDomAttr a2 = e.attributeNode("href"); cout << qPrintable(a2.value()) << '\n'; // prints "http://qt-project.org/doc"
この例では、要素から受け取った属性を変更すると、その要素の属性も変更されることを示しています。要素の属性の値を変更したくない場合は、cloneNode ()を使用して属性の独立したコピーを取得する必要があります。
QDomAttrは属性のname ()とvalue ()を返すことができます。属性の値はsetValue() で設定します。specified() が真を返す場合、値はsetValue() で設定されます。この属性がアタッチされているノード(もしあれば)は、ownerElement ()で返されます。
ドキュメント・オブジェクト・モデルの詳細については、http://www.w3.org/TR/REC-DOM-Level-1/とhttp://www.w3.org/TR/DOM-Level-2-Core/ を参照してください。DOM実装のより一般的な紹介については、QDomDocument ドキュメントを参照してください。
メンバ関数のドキュメント
QDomAttr::QDomAttr()
空の属性を構築します。
QDomAttr::QDomAttr(const QDomAttr &attr)
attr のコピーを構築する。
コピーのデータは共有されます(シャローコピー):一方のノードを変更すると、もう一方のノードも変更されます。深いコピーを作成したい場合は、cloneNode() を使用します。
QString QDomAttr::name() const
属性の名前を返します。
QDomNode::NodeType QDomAttr::nodeType() const
AttributeNode を返す。
QDomElement QDomAttr::ownerElement() const
この属性がアタッチされている要素ノード、またはこの属性がどの要素にもアタッチされていない場合はnull node を返します。
void QDomAttr::setValue(const QString &value)
属性の値をvalue に設定します。
value()も参照 。
bool QDomAttr::specified() const
属性がsetValue() でユーザーによって設定されている場合はtrue
を返す。値が指定または設定されていない場合はfalse
を返します。
setValue()も参照 。
QString QDomAttr::value() const
属性の値、または属性が指定されていない場合は空文字列を返します。
specified() およびsetValue()も参照 。
QDomAttr &QDomAttr::operator=(const QDomAttr &other)
この DOM 属性にother を割り当てます。
コピーのデータは共有されます(浅いコピー):一方のノードを変更すると、もう一方のノードも変更されます。ディープ・コピーを作成したい場合は、cloneNode() を使用してください。
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.