The QDomNode class is the base class for all the nodes in a DOM tree. 更多...
Inherited by QDomAttr , QDomCharacterData , QDomDocument , QDomDocumentFragment , QDomDocumentType , QDomElement , QDomEntity , QDomEntityReference , QDomNotation and QDomProcessingInstruction .
The QDomNode class is the base class for all the nodes in a DOM tree.
DOM 中的很多函数返回 QDomNode。
可以找出节点的类型使用 isAttr (), isCDATASection (), isDocumentFragment (), isDocument (), isDocumentType (), isElement (), isEntityReference (), isText (), isEntity (), isNotation (), isProcessingInstruction (), isCharacterData () 和 isComment ().
可以将 QDomNode 转换为其子类之一使用 toAttr (), toCDATASection (), toDocumentFragment (), toDocument (), toDocumentType (), toElement (), toEntityReference (), toText (), toEntity (), toNotation (), toProcessingInstruction (), toCharacterData () 或 toComment (). You can convert a node to a null node with clear ().
Copies of the QDomNode class share their data using explicit sharing. This means that modifying one node will change all copies. This is especially useful in combination with functions which return a QDomNode, e.g. firstChild (). You can make an independent (deep) copy of the node with cloneNode ().
A QDomNode can be null, much like a null pointer. Creating a copy of a null node results in another null node. It is not possible to modify a null node, but it is possible to assign another, possibly non-null node to it. In this case, the copy of the null node will remain null. You can check if a QDomNode is null 通过调用 isNull (). The empty constructor of a QDomNode (or any of the derived classes) creates a null node.
插入节点采用 insertBefore (), insertAfter () 或 appendChild (). You can replace one node with another using replaceChild () and remove a node with removeChild ().
要遍历节点使用 firstChild () to get a node's first child (if any), and nextSibling () to traverse. QDomNode also provides lastChild (), previousSibling () 和 parentNode (). To find the first child node with a particular node name use namedItem ().
要找出节点是否拥有子级使用 hasChildNodes () and to get a list of all of a node's children use childNodes ().
The node's name and value (the meaning of which varies depending on its type) is returned by nodeName () 和 nodeValue () respectively. The node's type is returned by nodeType (). The node's value can be set with setNodeValue ().
节点所属文档的返回通过 ownerDocument ().
相邻 QDomText nodes can be merged into a single node with normalize ().
QDomElement nodes have attributes which can be retrieved with attributes ().
QDomElement and QDomAttr nodes can have namespaces which can be retrieved with namespaceURI (). Their local name is retrieved with localName (),和它们的前缀采用 prefix (). The prefix can be set with setPrefix ().
You can write the XML representation of the node to a text stream with save ().
The following example looks for the first element in an XML document and prints the names of all the elements that are its direct children.
QDomDocument d; d.setContent(someXML); QDomNode n = d.firstChild(); while (!n.isNull()) { if (n.isElement()) { QDomElement e = n.toElement(); cout << "Element name: " << e.tagName() << endl; break; } n = n.nextSibling(); }
有关文档对象模型的进一步信息,见 级别 1 and 级别 2 核心 . For a more general introduction of the DOM implementation see the QDomDocument 文档编制。
此枚举指定如何 QDomNode.save () determines what encoding to use when serializing.
| 常量 | 值 | 描述 |
|---|---|---|
| QDomNode.EncodingFromDocument | 1 | 编码抓取自 文档。 |
| QDomNode.EncodingFromTextStream | 2 | 编码抓取自 QTextStream . |
See also the overload of the save () function that takes an EncodingPolicy.
该枚举在 Qt 4.3 引入或被修改。
此枚举定义节点的类型:
| 常量 | 值 | 描述 |
|---|---|---|
| QDomNode.ElementNode | 1 | |
| QDomNode.AttributeNode | 2 | |
| QDomNode.TextNode | 3 | |
| QDomNode.CDATASectionNode | 4 | |
| QDomNode.EntityReferenceNode | 5 | |
| QDomNode.EntityNode | 6 | |
| QDomNode.ProcessingInstructionNode | 7 | |
| QDomNode.CommentNode | 8 | |
| QDomNode.DocumentNode | 9 | |
| QDomNode.DocumentTypeNode | 10 | |
| QDomNode.DocumentFragmentNode | 11 | |
| QDomNode.NotationNode | 12 | |
| QDomNode.BaseNode | 21 | A QDomNode 对象, i.e. not a QDomNode 子类。 |
| QDomNode.CharacterDataNode | 22 |
构造 null 节点。
构造副本为 n .
The data of the copy is shared (shallow copy): modifying one node will also change the other. If you want to make a deep copy, use cloneNode ().
追加 newChild 作为节点的最后子级。
若 newChild is the child of another node, it is reparented to this node. If newChild is a child of this node, then its position in the list of children is changed.
若 newChild 是 QDomDocumentFragment , then the children of the fragment are removed from the fragment and appended.
若 newChild 是 QDomElement 和此节点是 QDomDocument that already has an element node as a child, newChild is not added as a child and a null node is returned.
返回新的引用为 newChild 当成功时或 null 节点 当失败时。
Calling this function on a null node(created, for example, with the default constructor) does nothing and returns a null 节点 .
The DOM specification disallow inserting attribute nodes, but for historical reasons, QDom accepts them anyway.
另请参阅 insertBefore (), insertAfter (), replaceChild (),和 removeChild ().
Returns a named node map of all attributes. Attributes are only provided for QDomElement s.
Changing the attributes in the map will also change the attributes of this QDomNode .
返回所有直接子级节点的列表。
大多数情况下,会调用此函数在 QDomElement 对象。
例如,若 XML 文档看起来像这样:
<body> <h1>Heading</h1> <p>Hello <b>you</b></p> </body>
Then the list of child nodes for the "body"-element will contain the node created by the <h1> tag and the node created by the <p> tag.
The nodes in the list are not copied; so changing the nodes in the list will also change the children of this node.
另请参阅 firstChild () 和 lastChild ().
Converts the node into a null node; if it was not a null node before, its type and contents are deleted.
另请参阅 isNull ().
创建深 (非浅) 副本为 QDomNode .
若 deep is true, then the cloning is done recursively which means that all the node's children are deep copied too. If deep is false only the node itself is copied and the copy will have no child nodes.
对于创建的节点通过 QDomDocument.setContent (), this function returns the column number in the XML document where the node was parsed. Otherwise, -1 is returned.
该函数在 Qt 4.1 引入。
另请参阅 lineNumber () 和 QDomDocument.setContent ().
Returns the first child of the node. If there is no child node, a null 节点 被返回。 Changing the returned node will also change the node in the document tree.
另请参阅 lastChild () 和 childNodes ().
返回的第一子级元素具有标签名称 tagName if tagName is non-empty; otherwise returns the first child element. Returns a null element if no such child exists.
另请参阅 lastChildElement (), previousSiblingElement (), and nextSiblingElement ().
Returns true if the node has attributes; otherwise returns false.
另请参阅 attributes ().
Returns true if the node has one or more children; otherwise returns false.
插入节点 newChild 后于子级节点 refChild . refChild must be a direct child of this node. If refChild is null then newChild 被追加作为此节点的最后子级。
若 newChild is the child of another node, it is reparented to this node. If newChild is a child of this node, then its position in the list of children is changed.
若 newChild 是 QDomDocumentFragment , then the children of the fragment are removed from the fragment and inserted after refChild .
返回新的引用为 newChild 当成功时或 null 节点 当失败时。
The DOM specification disallow inserting attribute nodes, but due to historical reasons QDom accept them nevertheless.
另请参阅 insertBefore (), replaceChild (), removeChild (),和 appendChild ().
插入节点 newChild 前于子级节点 refChild . refChild must be a direct child of this node. If refChild is null then newChild 被插入作为节点的第一子级。
若 newChild is the child of another node, it is reparented to this node. If newChild is a child of this node, then its position in the list of children is changed.
若 newChild 是 QDomDocumentFragment , then the children of the fragment are removed from the fragment and inserted before refChild .
返回新的引用为 newChild 当成功时或 null 节点 当失败时。
The DOM specification disallow inserting attribute nodes, but due to historical reasons QDom accept them nevertheless.
另请参阅 insertAfter (), replaceChild (), removeChild (),和 appendChild ().
Returns true if the node is an attribute; otherwise returns false.
If this function returns true, it does not imply that this object is a QDomAttribute; you can get the QDomAttribute with toAttribute().
另请参阅 toAttr ().
Returns true if the node is a CDATA section; otherwise returns false.
If this function returns true, it does not imply that this object is a QDomCDATASection ; you can get the QDomCDATASection with toCDATASection ().
另请参阅 toCDATASection ().
Returns true if the node is a character data node; otherwise returns false.
If this function returns true, it does not imply that this object is a QDomCharacterData ; you can get the QDomCharacterData with toCharacterData ().
另请参阅 toCharacterData ().
Returns true if the node is a comment; otherwise returns false.
If this function returns true, it does not imply that this object is a QDomComment ; you can get the QDomComment with toComment ().
另请参阅 toComment ().
Returns true if the node is a document; otherwise returns false.
If this function returns true, it does not imply that this object is a QDomDocument ; you can get the QDomDocument with toDocument ().
另请参阅 toDocument ().
Returns true if the node is a document fragment; otherwise returns false.
If this function returns true, it does not imply that this object is a QDomDocumentFragment ; you can get the QDomDocumentFragment with toDocumentFragment ().
另请参阅 toDocumentFragment ().
Returns true if the node is a document type; otherwise returns false.
If this function returns true, it does not imply that this object is a QDomDocumentType ; you can get the QDomDocumentType with toDocumentType ().
另请参阅 toDocumentType ().
Returns true if the node is an element; otherwise returns false.
If this function returns true, it does not imply that this object is a QDomElement ; you can get the QDomElement with toElement ().
另请参阅 toElement ().
Returns true if the node is an entity; otherwise returns false.
If this function returns true, it does not imply that this object is a QDomEntity ; you can get the QDomEntity with toEntity ().
另请参阅 toEntity ().
Returns true if the node is an entity reference; otherwise returns false.
If this function returns true, it does not imply that this object is a QDomEntityReference ;可以获取 QDomEntityReference with toEntityReference ().
另请参阅 toEntityReference ().
Returns true if the node is a notation; otherwise returns false.
If this function returns true, it does not imply that this object is a QDomNotation ; you can get the QDomNotation with toNotation ().
另请参阅 toNotation ().
Returns true if this node is null (i.e. if it has no type or contents); otherwise returns false.
Returns true if the node is a processing instruction; otherwise returns false.
If this function returns true, it does not imply that this object is a QDomProcessingInstruction ; you can get the QProcessingInstruction with toProcessingInstruction ().
另请参阅 toProcessingInstruction ().
Returns true if the DOM implementation implements the feature feature and this feature is supported by this node in the version version ;否则返回 false。
另请参阅 QDomImplementation.hasFeature ().
Returns true if the node is a text node; otherwise returns false.
If this function returns true, it does not imply that this object is a QDomText ;可以获取 QDomText with toText ().
另请参阅 toText ().
返回节点的最后子级。若没有子级节点, null 节点 is returned. Changing the returned node will also change the node in the document tree.
另请参阅 firstChild () 和 childNodes ().
返回的最后子级元素具有标签名称 tagName if tagName is non-empty; otherwise returns the last child element. Returns a null element if no such child exists.
另请参阅 firstChildElement (), previousSiblingElement (), and nextSiblingElement ().
对于创建的节点通过 QDomDocument.setContent (), this function returns the line number in the XML document where the node was parsed. Otherwise, -1 is returned.
该函数在 Qt 4.1 引入。
另请参阅 columnNumber () 和 QDomDocument.setContent ().
If the node uses namespaces, this function returns the local name of the node; otherwise it returns an empty string.
仅节点为类型 ElementNode or AttributeNode can have namespaces. A namespace must have been specified at creation time; it is not possible to add a namespace afterwards.
QDomDocument.createAttributeNS ()
另请参阅 prefix (), namespaceURI (),和 QDomDocument.createElementNS ().
返回第一直接子级节点对于其 nodeName () 等于 name .
若不存在这种直接子级, null 节点 被返回。
另请参阅 nodeName ().
Returns the next sibling in the document tree. Changing the returned node will also change the node in the document tree.
若拥有的 XML 像这样:
<h1>Heading</h1> <p>The text...</p> <h2>Next heading</h2>
和此 QDomNode represents the <p> tag, nextSibling() will return the node representing the <h2> tag.
另请参阅 previousSibling ().
返回的下一同级元素具有标签名称 tagName if tagName is non-empty; otherwise returns any next sibling element. Returns a null element if no such sibling exists.
另请参阅 firstChildElement (), previousSiblingElement (), and lastChildElement ().
返回节点的名称。
名称的含义从属子类:
| Name | 含义 |
|---|---|
| QDomAttr | 属性名称 |
| QDomCDATASection | 字符串 "#cdata-section" |
| QDomComment | 字符串 "#comment" |
| QDomDocument | 字符串 "#document" |
| QDomDocumentFragment | 字符串 "#document-fragment" |
| QDomDocumentType | 文件类型的名称 |
| QDomElement | 标签名称 |
| QDomEntity | 实体名称 |
| QDomEntityReference | 引用实体的名称 |
| QDomNotation | 表示法名称 |
| QDomProcessingInstruction | 处理指令的目标 |
| QDomText | 字符串 "#text" |
注意: This function does not take the presence of namespaces into account when processing the names of element and attribute nodes. As a result, the returned name can contain any namespace prefix that may be present. To obtain the node name of an element or attribute, use localName (); to obtain the namespace prefix, use namespaceURI ().
另请参阅 nodeValue ().
返回节点的类型。
另请参阅 toAttr (), toCDATASection (), toDocumentFragment (), toDocument (), toDocumentType (), toElement (), toEntityReference (), toText (), toEntity (), toNotation (), toProcessingInstruction (), toCharacterData (),和 toComment ().
返回节点的值。
值的含义从属子类:
| Name | 含义 |
|---|---|
| QDomAttr | 属性值 |
| QDomCDATASection | CDATA 区间的内容 |
| QDomComment | 注释 |
| QDomProcessingInstruction | 处理指令的数据 |
| QDomText | 文本 |
All the other subclasses do not have a node value and will return an empty string.
另请参阅 setNodeValue () 和 nodeName ().
Calling normalize() on an element converts all its children into a standard form. This means that adjacent QDomText objects will be merged into a single text object ( QDomCDATASection nodes are not merged).
返回此节点所属的文档。
Returns the parent node. If this node has no parent, a null node is returned (i.e. a node for which isNull () returns true).
Returns the namespace prefix of the node or an empty string if the node has no namespace prefix.
仅节点为类型 ElementNode or AttributeNode can have namespaces. A namespace prefix must be specified at creation time. If a node was created with a namespace prefix, you can change it later with setPrefix ().
如果创建元素或属性采用 QDomDocument.createElement () or QDomDocument.createAttribute (), the prefix will be an empty string. If you use QDomDocument.createElementNS () or QDomDocument.createAttributeNS () instead, the prefix will not be an empty string; but it might be an empty string if the name does not have a prefix.
QDomDocument.createElementNS () QDomDocument.createAttributeNS ()
另请参阅 setPrefix (), localName (),和 namespaceURI ().
Returns the previous sibling in the document tree. Changing the returned node will also change the node in the document tree.
例如,若拥有的 XML 像这样:
<h1>Heading</h1> <p>The text...</p> <h2>Next heading</h2>
和此 QDomNode represents the <p> tag, previousSibling() will return the node representing the <h1> tag.
另请参阅 nextSibling ().
返回的上一同级元素具有标签名称 tagName if tagName is non-empty; otherwise returns any previous sibling element. Returns a null element if no such sibling exists.
另请参阅 firstChildElement (), nextSiblingElement (),和 lastChildElement ().
移除 oldChild from the list of children. oldChild 必须是此节点的直接子级。
返回新的引用为 oldChild 当成功时或 null 节点 当失败时。
另请参阅 insertBefore (), insertAfter (), replaceChild (),和 appendChild ().
替换 oldChild with newChild . oldChild 必须是此节点的直接子级。
若 newChild is the child of another node, it is reparented to this node. If newChild is a child of this node, then its position in the list of children is changed.
若 newChild 是 QDomDocumentFragment ,那么 oldChild is replaced by all of the children of the 片段。
返回新的引用为 oldChild 当成功时或 null 节点 an failure.
另请参阅 insertBefore (), insertAfter (), removeChild (),和 appendChild ().
Writes the XML representation of the node and all its children 到流 str 。此函数使用 indent 作为 amount of space to indent the node.
If this node is a document node, the encoding of text stream str 's encoding is set by treating a processing instruction by name "xml" as an XML declaration, if such a one exists, and otherwise defaults to UTF-8. XML declarations are not processing instructions, but this behavior exists for historical reasons. If this node is not a document node, the text stream's encoding is used.
If the document contains invalid XML characters or characters that cannot be encoded in the given encoding, the result and behavior is undefined.
若 encodingPolicy is QDomNode.EncodingFromDocument , this function behaves as save( QTextStream &str, int indent).
若 encodingPolicy is EncodingFromTextStream and this node is a document node, this function behaves as save( QTextStream &str, int indent) with the exception that the encoding specified in the text stream str 被使用。
If the document contains invalid XML characters or characters that cannot be encoded in the given encoding, the result and behavior is undefined.
该函数在 Qt 4.2 引入。
将节点值设为 v .
另请参阅 nodeValue ().
If the node has a namespace prefix, this function changes the namespace prefix of the node to pre . Otherwise this function does nothing.
仅节点为类型 ElementNode or AttributeNode can have namespaces. A namespace prefix must have be specified at creation time; it is not possible to add a namespace prefix afterwards.
QDomDocument.createElementNS () QDomDocument.createAttributeNS ()
另请参阅 prefix (), localName (),和 namespaceURI ().
转换 QDomNode 成 QDomAttr . If the node is not an attribute, the returned object will be null .
另请参阅 isAttr ().
转换 QDomNode 成 QDomCDATASection . If the node is not a CDATA section, the returned object will be null .
另请参阅 isCDATASection ().
转换 QDomNode 成 QDomCharacterData . If the node is not a character data node the returned object will be null .
另请参阅 isCharacterData ().
转换 QDomNode 成 QDomComment . If the node is not a comment the returned object will be null .
另请参阅 isComment ().
转换 QDomNode 成 QDomDocument . If the node is not a document the returned object will be null .
另请参阅 isDocument ().
转换 QDomNode 成 QDomDocumentFragment . If the node is not a document fragment the returned object will be null .
另请参阅 isDocumentFragment ().
转换 QDomNode 成 QDomDocumentType . If the node is not a document type the returned object will be null .
另请参阅 isDocumentType ().
转换 QDomNode 成 QDomElement . If the node is not an element the returned object will be null .
另请参阅 isElement ().
转换 QDomNode 成 QDomEntity . If the node is not an entity the returned object will be null .
另请参阅 isEntity ().
转换 QDomNode 成 QDomEntityReference . If the node is not an entity reference, the returned object will be null .
另请参阅 isEntityReference ().
转换 QDomNode 成 QDomNotation . If the node is not a notation the returned object will be null .
另请参阅 isNotation ().
转换 QDomNode 成 QDomProcessingInstruction 。若 the node is not a processing instruction the returned object will be null .
另请参阅 isProcessingInstruction ().
转换 QDomNode 成 QDomText . If the node is not a text, the returned object will be null .
另请参阅 isText ().