QDomAttrclass represents one attribute of aQDomElement. 更多 …
例如,以下 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.
QDomAttrcan return thename()andvalue()of an attribute. An attribute’s value is set withsetValue()。若specified()returns true the value was set withsetValue(). The node this attribute is attached to (if any) is returned byownerElement().有关文档对象模型的进一步信息,见 http://www.w3.org/TR/REC-DOM-Level-1/ and http://www.w3.org/TR/DOM-Level-2-Core/ 。有关 DOM 实现的更一般介绍,见
QDomDocument文档编制。
PySide2.QtXml.QDomAttr.
name
(
)
¶
unicode
Returns the attribute’s name.
PySide2.QtXml.QDomAttr.
setValue
(
arg__1
)
¶
arg__1 – unicode
Sets the attribute’s value to
v
.
另请参阅
PySide2.QtXml.QDomAttr.
specified
(
)
¶
bool
返回
true
若有设置属性由用户采用
setValue()
。返回
false
if the value hasn’t been specified or set.
另请参阅
PySide2.QtXml.QDomAttr.
value
(
)
¶
unicode
返回属性的值,或空字符串若尚未指定属性。
另请参阅