内容表

上一话题

PySide2.QtXml

下一话题

QDomCDATASection

QDomAttr

QDomAttr class represents one attribute of a QDomElement . 更多

Inheritance diagram of PySide2.QtXml.QDomAttr

概要

函数

详细描述

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

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

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

e = # some QDomElement...
#...
a = e.attributeNode("href")
print a.value()                         # prints "http://qt-project.org.com"
a.setValue("http://qt-project.org/doc")  # change the node's attribute
a2 = e.attributeNode("href")
print a2.value()                        # prints "http://qt-project.org/doc"
											

This example also shows that changing an attribute received from an element changes the attribute of the element. If you do not want to change the value of the element’s attribute you must use cloneNode() to get an independent copy of the attribute.

QDomAttr can return the name() and value() of an attribute. An attribute’s value is set with setValue() 。若 specified() returns true the value was set with setValue() . The node this attribute is attached to (if any) is returned by ownerElement() .

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

class QDomAttr

QDomAttr(x)

param x

QDomAttr

构造空属性。

PySide2.QtXml.QDomAttr. name ( )
返回类型

unicode

Returns the attribute’s name.

PySide2.QtXml.QDomAttr. ownerElement ( )
返回类型

QDomElement

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

PySide2.QtXml.QDomAttr. setValue ( arg__1 )
参数

arg__1 – unicode

Sets the attribute’s value to v .

另请参阅

value()

PySide2.QtXml.QDomAttr. specified ( )
返回类型

bool

返回 true 若有设置属性由用户采用 setValue() 。返回 false if the value hasn’t been specified or set.

另请参阅

setValue()

PySide2.QtXml.QDomAttr. value ( )
返回类型

unicode

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