QDomElement 类表示一个 DOM 树元素。 更多...
继承 QDomNode .
The QDomElement class represents one element in the DOM tree.
元素拥有 tagName () and zero or more attributes associated with them. The tag name can be changed with setTagName ().
元素属性的表示通过 QDomAttr 对象,可以查询使用 attribute () 和 attributeNode () functions. You can set attributes with the setAttribute () 和 setAttributeNode () functions. Attributes can be removed with removeAttribute (). There are namespace-aware equivalents to these functions, i.e. setAttributeNS (), setAttributeNodeNS () 和 removeAttributeNS ().
若想要访问节点文本,使用 text (),如
QDomElement e = //... //... QString s = e.text()
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 QDomText nodes, e.g.
QString text; QDomElement element = doc.documentElement(); for(QDomNode n = element.firstChild(); !n.isNull(); n = n.nextSibling()) { QDomText t = n.toText(); if (!t.isNull()) text += t.data(); }
Note that we attempt to convert each node to a text node and use text () rather than using firstChild (). toText ().data() or n. 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 elementsByTagName () 或 elementsByTagNameNS ().
To browse the elements of a dom document use firstChildElement (), lastChildElement (), nextSiblingElement () 和 previousSiblingElement (). For example, to iterate over all child elements called "entry" in a root element called "database", you can use:
QDomDocument doc = // ... QDomElement root = doc.firstChildElement("database"); QDomElement elt = root.firstChildElement("entry"); for (; !elt.isNull(); elt = elt.nextSiblingElement("entry")) { // ... }
有关文档对象模型的进一步信息,见 级别 1 and 级别 2 核心 . For a more general introduction of the DOM implementation see the QDomDocument 文档编制。
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 cloneNode ().
返回的属性称为 name . If the attribute does not exist defValue 被返回。
另请参阅 setAttribute (), attributeNode (), setAttributeNode (),和 attributeNS ().
返回 QDomAttr object that corresponds to the attribute called name . If no such attribute exists a null attribute 被返回。
另请参阅 setAttributeNode (), attribute (), setAttribute (),和 attributeNodeNS ().
返回 QDomAttr object that corresponds to the attribute with the local name localName 和名称空间 URI nsURI 。若不存在这种属性 null 属性 被返回。
另请参阅 setAttributeNodeNS (), setAttributeNode (), attribute (),和 setAttribute ().
返回的属性具有本地名称 localName and the namespace URI nsURI 。若属性不存在 defValue 被返回。
另请参阅 setAttributeNS (), attributeNodeNS (), setAttributeNodeNS (),和 attribute ().
返回 QDomNamedNodeMap 包含此元素的所有属性。
另请参阅 attribute (), setAttribute (), attributeNode (),和 setAttributeNode ().
返回 QDomNodeList 包含此元素的所有后代名为 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.
另请参阅 elementsByTagNameNS () and QDomDocument.elementsByTagName ().
返回 QDomNodeList 包含此元素的所有后代具有本地名称 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.
另请参阅 elementsByTagName () 和 QDomDocument.elementsByTagNameNS ().
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.
使用 hasAttributeNS () 到 explicitly test for attributes with specific namespaces and names.
Returns true if this element has an attribute with the local name localName 和名称空间 URI nsURI ;否则 returns false.
返回 ElementNode .
移除的属性名为 name 从此 元素。
另请参阅 setAttribute (), attribute (),和 removeAttributeNS ().
移除属性 oldAttr from the element and returns it.
另请参阅 attributeNode () 和 setAttributeNode ().
移除属性具有本地名称 localName and the namespace URI nsURI 从此元素。
另请参阅 setAttributeNS (), attributeNS (),和 removeAttribute ().
添加的属性称为 name 采用值 value 。若 an attribute with the same name exists, its value is replaced by value .
另请参阅 attribute (), setAttributeNode (),和 setAttributeNS ().
这是重载函数。
The number is formatted according to the current locale.
这是重载函数。
The number is formatted according to the current locale.
这是重载函数。
The number is formatted according to the current locale.
这是重载函数。
The number is formatted according to the current locale.
添加属性 newAttr 到此元素。
若拥有另一属性的元素拥有相同名称如 newAttr , this function replaces that attribute and returns it; otherwise the function returns a null 属性 .
另请参阅 attributeNode (), setAttribute (),和 setAttributeNodeNS ().
添加属性 newAttr 到此元素。
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 属性 .
另请参阅 attributeNodeNS (), setAttributeNS (),和 setAttributeNode ().
Adds an attribute with the qualified name qName 和 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 .
尽管 qName is the qualified name, the local name is used to decide if an existing attribute's value should be replaced.
另请参阅 attributeNS (), setAttributeNodeNS (),和 setAttribute ().
这是重载函数。
这是重载函数。
这是重载函数。
这是重载函数。
将此元素的标签名称设为 name .
另请参阅 tagName ().
Returns the tag name of this element. For an XML element like this:
<img src="myimg.png">
tagname 将返回 img。
另请参阅 setTagName ().
返回元素的文本或空字符串。
范例:
<h1>Hello <b>Qt</b> <![CDATA[<xml is cool>]]></h1>
函数 text() 的 QDomElement 为 <h1> tag, will return the following text:
Hello Qt <xml is cool>
此函数忽略注释。它只评估 QDomText and QDomCDATASection 对象。