Qt qdomelement class parsing!

Source: Internet
Author: User

Today I will translate the qdomelenment class in QT. The original document is an official document!

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.

This class represents the elements in the DOM tree.
The element has a tag name and has 0 or more attributes to join them. The tag name can be changed to settagname (). The element attribute is represented by a qdomattr object. Attribute () and attributenode () can be used to query attributes and a qdomattr is returned,
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 () This function recursively finds text (because not all labels contain text ). If you want to find all the text on this node,
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.
Record: we try to convert each node into a text node, and use text () instead of firstchild (). totext (). Data (). directly act on the node. Because the node may not be a text node element.
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:
Use firstchildelement (), lastchildelement (), nextsiblingelement (), and previoussiblingelement () to browse Dom documents (). for example, to traverse all the sub-elements of the root node called "Database" called "entry", you can use:
 QDomDocument doc = // ... QDomElement root = doc.firstChildElement("database"); QDomElement elt = root.firstChildElement("entry"); for (; !elt.isNull(); elt = elt.nextSiblingElement("entry")) {     // ...


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.