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")) { // ...