• PySide 模块
  • PySide.QtXml
  • 内容表

    上一话题

    QDomElement

    下一话题

    QDomCharacterData

    QDomAttr

    概要

    函数

    详细描述

    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 文档编制。

    class PySide.QtXml. QDomAttr
    class PySide.QtXml. QDomAttr ( x )
    参数: x PySide.QtXml.QDomAttr

    构造空属性。

    构造副本为 x .

    拷贝数据是共享的 (浅拷贝):修改一个节点也将改变另一节点。若想要制作深度副本,使用 PySide.QtXml.QDomNode.cloneNode() .

    PySide.QtXml.QDomAttr. name ( )
    返回类型: unicode

    返回属性的名称。

    PySide.QtXml.QDomAttr. ownerElement ( )
    返回类型: PySide.QtXml.QDomElement

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

    PySide.QtXml.QDomAttr. setValue ( arg__1 )
    参数: arg__1 – unicode

    将属性的值设为 v .

    PySide.QtXml.QDomAttr. specified ( )
    返回类型: 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.

    PySide.QtXml.QDomAttr. value ( )
    返回类型: unicode

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