qt QDomElement类解析!

      今天我来翻译一下这个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")) {
     // ...


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值