qt QDomElement類解析!

來源:互聯網
上載者:User

      今天我來翻譯一下這個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")) {     // ...


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.