QDomDocumentFragment Class

QDomDocumentFragment 类是由 QDomNodes 组成的树状结构,通常不是完整的QDomDocument更多

头文件: #include <QDomDocumentFragment>
CMake: find_package(Qt6 REQUIRED COMPONENTS Xml)
target_link_libraries(mytarget PRIVATE Qt6::Xml)
qmake: QT += xml
继承: QDomNode

注意:该类中的所有函数都是可重入的

公共函数

QDomDocumentFragment()
QDomDocumentFragment(const QDomDocumentFragment &documentFragment)
QDomNode::NodeType nodeType() const
QDomDocumentFragment &operator=(const QDomDocumentFragment &other)

详细说明

如果您想进行复杂的树形操作,拥有一个轻量级类来存储节点及其关系是非常有用的。QDomDocumentFragment 可存储文档的子树,但它并不一定代表格式良好的 XML 文档。

QDomDocumentFragment 也很有用,如果你想在一个列表中将多个节点分组,并将它们作为某个节点的子节点一起插入。在这种情况下,QDomDocumentFragment 可用作子节点列表的临时容器。

QDomDocumentFragment 的最重要特征是,它被QDomNode::insertAfter(),QDomNode::insertBefore(),QDomNode::replaceChild() 和QDomNode::appendChild() 以特殊方式处理:不是插入片段本身,而是插入片段的所有子节点。

成员函数文档

QDomDocumentFragment::QDomDocumentFragment()

构造一个空文档片段。

QDomDocumentFragment::QDomDocumentFragment(const QDomDocumentFragment &documentFragment)

构造documentFragment 的副本。

副本的数据是共享的(浅层副本):修改一个节点也会改变另一个节点。如果要进行深度复制,请使用cloneNode() 。

QDomNode::NodeType QDomDocumentFragment::nodeType() const

返回DocumentFragment

另请参见 isDocumentFragment() 和QDomNode::toDocumentFragment()。

QDomDocumentFragment &QDomDocumentFragment::operator=(const QDomDocumentFragment &other)

为该 DOM 文档片段指定other

副本的数据是共享的(浅层副本):修改一个节点也会改变另一个节点。如果要进行深度复制,请使用cloneNode()。

© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.