PySide.QtXml.QDomAttr class represents one attribute of a PySide.QtXml.QDomElement .
例如,以下 XML 片段产生不带子级但有 2 属性的元素:
<link href="http://qtsoftware.com" color="red" />
可以采用像这样的代码访问元素属性:
e = # some QDomElement...
#...
a = e.attributeNode("href")
print a.value() # prints "http://qtsoftware.com"
a.setValue("http://doc.trolltech.com") # change the node's attribute
a2 = e.attributeNode("href")
print a2.value() # prints "http://doc.trolltech.com"
此范例展示改变接收自元素的属性还会改变元素的属性。若不希望改变元素属性值,则必须使用 PySide.QtXml.QDomNode.cloneNode() to get an independent copy of the attribute.
PySide.QtXml.QDomAttr can return the PySide.QtXml.QDomAttr.name() and PySide.QtXml.QDomAttr.value() of an attribute. An attribute's value is set with PySide.QtXml.QDomAttr.setValue() 。若 PySide.QtXml.QDomAttr.specified() returns true the value was set with PySide.QtXml.QDomAttr.setValue() . The node this attribute is attached to (if any) is returned by PySide.QtXml.QDomAttr.ownerElement() .
有关文档对象模型的进一步信息,见 http://www.w3.org/TR/REC-DOM-Level-1/ and http://www.w3.org/TR/DOM-Level-2-Core/ 。有关 DOM 实现的更一般介绍,见 PySide.QtXml.QDomDocument 文档编制。
| 参数: | x – PySide.QtXml.QDomAttr |
|---|
构造空属性。
构造副本为 x .
拷贝数据是共享的 (浅拷贝):修改一个节点也将改变另一节点。若想要制作深度副本,使用 PySide.QtXml.QDomNode.cloneNode() .
| 返回类型: | unicode |
|---|
返回属性的名称。
| 返回类型: | PySide.QtXml.QDomElement |
|---|
返回附加此属性到的元素节点或 null node 若此属性尚未被附加到任何元素。
| 参数: | arg__1 – unicode |
|---|
将属性的值设为 v .
| 返回类型: | PySide.QtCore.bool |
|---|
Returns true if the attribute has been set by the user with PySide.QtXml.QDomAttr.setValue() . Returns false if the value hasn't been specified or set.
| 返回类型: | unicode |
|---|
返回属性的值,或空字符串若尚未指定属性。