このページでは

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()
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()がtrueを返す場合、その値はsetValue()で設定されたものです。この属性が紐付けられているノード(存在する場合)は、ownerElement()によって返されます。

Document Object Model(DOM)の詳細については、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() を使用してください。

© 2026 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.