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

    上一话题

    QDomNotation

    下一话题

    QDomAttr

    QDomElement

    概要

    函数

    详细描述

    PySide.QtXml.QDomElement class represents one element in the DOM tree.

    Elements have a PySide.QtXml.QDomElement.tagName() and zero or more attributes associated with them. The tag name can be changed with PySide.QtXml.QDomElement.setTagName() .

    Element attributes are represented by PySide.QtXml.QDomAttr objects that can be queried using the PySide.QtXml.QDomElement.attribute() and PySide.QtXml.QDomElement.attributeNode() functions. You can set attributes with the PySide.QtXml.QDomElement.setAttribute() and PySide.QtXml.QDomElement.setAttributeNode() functions. Attributes can be removed with PySide.QtXml.QDomElement.removeAttribute() . There are namespace-aware equivalents to these functions, i.e. PySide.QtXml.QDomElement.setAttributeNS() , PySide.QtXml.QDomElement.setAttributeNodeNS() and PySide.QtXml.QDomElement.removeAttributeNS() .

    If you want to access the text of a node use PySide.QtXml.QDomElement.text() , e.g.

    e = # some QDomElement...
    #...
    s = e.text()
    									

    PySide.QtXml.QDomElement.text() function operates recursively to find the text (since not all elements contain text). If you want to find all the text in all of a node's children, iterate over the children looking for PySide.QtXml.QDomText nodes, e.g.

    text = QString()
    element = doc.documentElement()
    n = element.firstChild()
    while True:
        if not n.isNull()
            break
        t = n.toText()
        if !t.isNull():
            text += t.data()
        n = n.nextSibling()
    									

    Note that we attempt to convert each node to a text node and use PySide.QtXml.QDomElement.text() rather than using PySide.QtXml.QDomNode.firstChild() . PySide.QtXml.QDomNode.toText() . data() or n. PySide.QtXml.QDomNode.toText() . data() directly on the node, because the node may not be a text element.

    You can get a list of all the decendents of an element which have a specified tag name with PySide.QtXml.QDomElement.elementsByTagName() or PySide.QtXml.QDomElement.elementsByTagNameNS() .

    To browse the elements of a dom document use PySide.QtXml.QDomNode.firstChildElement() , PySide.QtXml.QDomNode.lastChildElement() , PySide.QtXml.QDomNode.nextSiblingElement() and PySide.QtXml.QDomNode.previousSiblingElement() . For example, to iterate over all child elements called “entry” in a root element called “database”, you can use:

    doc = # some QDomDocument ...
    root = doc.firstChildElement("database")
    elt = root.firstChildElement("entry")
    while True:
        if not elt.isNull():
            break
        # ...
        elt = elt.nextSiblingElement("entry")
    									

    For further information about the Document Object Model see Level 1 and Level 2 Core. For a more general introduction of the DOM implementation see the PySide.QtXml.QDomDocument 文档编制。

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

    Constructs an empty element. Use the QDomDocument.createElement() function to construct elements with content.

    构造副本为 x .

    The data of the copy is shared (shallow copy): modifying one node will also change the other. If you want to make a deep copy, use PySide.QtXml.QDomNode.cloneNode() .

    PySide.QtXml.QDomElement. attribute ( name [ , defValue="" ] )
    参数:
    • name – unicode
    • defValue – unicode
    返回类型:

    unicode

    Returns the attribute called name . If the attribute does not exist defValue 被返回。

    PySide.QtXml.QDomElement. attributeNS ( nsURI , localName [ , defValue="" ] )
    参数:
    • nsURI – unicode
    • localName – unicode
    • defValue – unicode
    返回类型:

    unicode

    Returns the attribute with the local name localName and the namespace URI nsURI . If the attribute does not exist defValue 被返回。

    PySide.QtXml.QDomElement. attributeNode ( name )
    参数: name – unicode
    返回类型: PySide.QtXml.QDomAttr

    返回 PySide.QtXml.QDomAttr object that corresponds to the attribute called name . If no such attribute exists a null attribute 被返回。

    PySide.QtXml.QDomElement. attributeNodeNS ( nsURI , localName )
    参数:
    • nsURI – unicode
    • localName – unicode
    返回类型:

    PySide.QtXml.QDomAttr

    返回 PySide.QtXml.QDomAttr object that corresponds to the attribute with the local name localName and the namespace URI nsURI . If no such attribute exists a null attribute 被返回。

    PySide.QtXml.QDomElement. elementsByTagName ( tagname )
    参数: tagname – unicode
    返回类型: PySide.QtXml.QDomNodeList

    返回 PySide.QtXml.QDomNodeList containing all descendants of this element named tagname encountered during a preorder traversal of the element subtree with this element as its root. The order of the elements in the returned list is the order they are encountered during the preorder traversal.

    PySide.QtXml.QDomElement. elementsByTagNameNS ( nsURI , localName )
    参数:
    • nsURI – unicode
    • localName – unicode
    返回类型:

    PySide.QtXml.QDomNodeList

    返回 PySide.QtXml.QDomNodeList containing all descendants of this element with local name localName and namespace URI nsURI encountered during a preorder traversal of the element subtree with this element as its root. The order of the elements in the returned list is the order they are encountered during the preorder traversal.

    PySide.QtXml.QDomElement. hasAttribute ( name )
    参数: name – unicode
    返回类型: PySide.QtCore.bool

    Returns true if this element has an attribute called name ;否则返回 false。

    注意

    This function does not take the presence of namespaces into account. As a result, the specified name will be tested against fully-qualified attribute names that include any namespace prefixes that may be present.

    使用 PySide.QtXml.QDomElement.hasAttributeNS() to explicitly test for attributes with specific namespaces and names.

    PySide.QtXml.QDomElement. hasAttributeNS ( nsURI , localName )
    参数:
    • nsURI – unicode
    • localName – unicode
    返回类型:

    PySide.QtCore.bool

    Returns true if this element has an attribute with the local name localName and the namespace URI nsURI ;否则返回 false。

    PySide.QtXml.QDomElement. removeAttribute ( name )
    参数: name – unicode

    Removes the attribute called name name from this element.

    PySide.QtXml.QDomElement. removeAttributeNS ( nsURI , localName )
    参数:
    • nsURI – unicode
    • localName – unicode

    Removes the attribute with the local name localName and the namespace URI nsURI from this element.

    PySide.QtXml.QDomElement. removeAttributeNode ( oldAttr )
    参数: oldAttr PySide.QtXml.QDomAttr
    返回类型: PySide.QtXml.QDomAttr

    Removes the attribute oldAttr from the element and returns it.

    PySide.QtXml.QDomElement. setAttribute ( name , value )
    参数:
    • name – unicode
    • value PySide.QtCore.qulonglong

    这是重载函数。

    The number is formatted according to the current locale.

    PySide.QtXml.QDomElement. setAttribute ( name , value )
    参数:
    • name – unicode
    • value PySide.QtCore.uint

    这是重载函数。

    The number is formatted according to the current locale.

    PySide.QtXml.QDomElement. setAttribute ( name , value )
    参数:
    • name – unicode
    • value PySide.QtCore.int

    这是重载函数。

    The number is formatted according to the current locale.

    PySide.QtXml.QDomElement. setAttribute ( name , value )
    参数:
    • name – unicode
    • value PySide.QtCore.qlonglong

    这是重载函数。

    The number is formatted according to the current locale.

    PySide.QtXml.QDomElement. setAttribute ( name , value )
    参数:
    • name – unicode
    • value PySide.QtCore.double

    这是重载函数。

    The number is formatted according to the current locale.

    PySide.QtXml.QDomElement. setAttribute ( name , value )
    参数:
    • name – unicode
    • value – unicode

    Adds an attribute called name with value value . If an attribute with the same name exists, its value is replaced by value .

    PySide.QtXml.QDomElement. setAttribute ( name , value )
    参数:
    • name – unicode
    • value PySide.QtCore.float

    这是重载函数。

    The number is formatted according to the current locale.

    PySide.QtXml.QDomElement. setAttributeNS ( nsURI , qName , value )
    参数:
    • nsURI – unicode
    • qName – unicode
    • value PySide.QtCore.qulonglong

    这是重载函数。

    PySide.QtXml.QDomElement. setAttributeNS ( nsURI , qName , value )
    参数:
    • nsURI – unicode
    • qName – unicode
    • value PySide.QtCore.uint

    这是重载函数。

    PySide.QtXml.QDomElement. setAttributeNS ( nsURI , qName , value )
    参数:
    • nsURI – unicode
    • qName – unicode
    • value PySide.QtCore.qlonglong

    这是重载函数。

    PySide.QtXml.QDomElement. setAttributeNS ( nsURI , qName , value )
    参数:
    • nsURI – unicode
    • qName – unicode
    • value PySide.QtCore.int

    这是重载函数。

    PySide.QtXml.QDomElement. setAttributeNS ( nsURI , qName , value )
    参数:
    • nsURI – unicode
    • qName – unicode
    • value PySide.QtCore.double

    这是重载函数。

    PySide.QtXml.QDomElement. setAttributeNS ( nsURI , qName , value )
    参数:
    • nsURI – unicode
    • qName – unicode
    • value – unicode

    Adds an attribute with the qualified name qName and the namespace URI nsURI 采用值 value . If an attribute with the same local name and namespace URI exists, its prefix is replaced by the prefix of qName and its value is repaced by value .

    Although qName is the qualified name, the local name is used to decide if an existing attribute's value should be replaced.

    PySide.QtXml.QDomElement. setAttributeNode ( newAttr )
    参数: newAttr PySide.QtXml.QDomAttr
    返回类型: PySide.QtXml.QDomAttr

    Adds the attribute newAttr to this element.

    If the element has another attribute that has the same name as newAttr , this function replaces that attribute and returns it; otherwise the function returns a null attribute .

    PySide.QtXml.QDomElement. setAttributeNodeNS ( newAttr )
    参数: newAttr PySide.QtXml.QDomAttr
    返回类型: PySide.QtXml.QDomAttr

    Adds the attribute newAttr to this element.

    If the element has another attribute that has the same local name and namespace URI as newAttr , this function replaces that attribute and returns it; otherwise the function returns a null attribute .

    PySide.QtXml.QDomElement. setTagName ( name )
    参数: name – unicode

    Sets this element's tag name to name .

    PySide.QtXml.QDomElement. tagName ( )
    返回类型: unicode

    Returns the tag name of this element. For an XML element like this:

    <img src="myimg.png">
    										

    the tagname would return “img”.

    PySide.QtXml.QDomElement. text ( )
    返回类型: unicode

    Returns the element's text or an empty string.

    范例:

    <h1>Hello <b>Qt</b> <![CDATA[<xml is cool>]]></h1>
    										

    The function PySide.QtXml.QDomElement.text() of the PySide.QtXml.QDomElement <h1> tag, will return the following text:

    Hello Qt <xml is cool>
    										

    Comments are ignored by this function. It only evaluates PySide.QtXml.QDomText and PySide.QtXml.QDomCDATASection 对象。