今天我來翻譯一下這個qt中QDomElenment這個類。原文檔是官方的文檔!
the QDomElement class represents one element in the DOM tree.
Elements have a tagName() and zero or more attributes associated with them. The tag name can be changed with setTagName().
Element attributes are represented by QDomAttr objects that can be queried using the attribute()
and attributeNode() functions. You can set attributes with the setAttribute()
and setAttributeNode() functions. Attributes can be removed with removeAttribute().
There are namespace-aware equivalents to these functions, i.e. setAttributeNS(), setAttributeNodeNS()
and removeAttributeNS().
If you want to access the text of a node use text(), e.g.
這個類代表了元素在Dom樹中。
元素有一個標籤名,有0個或更多的屬性聯合它們。那個標籤名可以改變用 setTagName().元素屬性用QDomAttr 對象代表,查詢可以用attribute() and attributeNode()查詢屬性和返回一個QDomAttr,
The 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.
text() 這個函數操作遞迴的找到text(因為不是所有的標籤都含有文本)。假如你要找到這個節點所有的文本,iterate over the children looking for QDomText nodes, e.g.
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.
記錄我們嘗試用轉變每個節點變為文本節點,用text()而不是用firstChild().toText().data().直接作用與node的節點。因為節點可能不是文本節點元素.
To browse the elements of a dom document use firstChildElement(), lastChildElement(), nextSiblingElement() and previousSiblingElement(). For example, to iterate over all child elements called "entry" in a root element called "database", you can use:瀏覽dom文檔的用firstChildElement(),lastChildElement(),nextSiblingElement()和previousSiblingElement().舉個列子,遍曆根節點叫做“database”的子項目所有叫做“entry”,你可以用:
QDomDocument doc = // ... QDomElement root = doc.firstChildElement("database"); QDomElement elt = root.firstChildElement("entry"); for (; !elt.isNull(); elt = elt.nextSiblingElement("entry")) { // ...