使用 DOM 树

DOM Level 2 是 W3C 推荐的 XML 接口,可将 XML 文档的组成映射为树形结构。DOM Level 2 的规范可在http://www.w3.org/DOM/ 上找到。

DOM 简介

DOM 为访问和更改 XML 文件的内容和结构提供了一个接口。它提供了文档的分层视图(树状视图)。因此,与QXmlStreamReader 提供的流式应用程序接口不同,在解析之后,文档的对象模型会常驻内存,从而使操作变得简单。

文档树中的所有 DOM 节点都是QDomNode 的子类。文档本身表示为QDomDocument 对象。

以下是可用的节点类及其潜在的子类:

QDomNodeListQDomNamedNodeMap 提供了两个集合类:QDomNodeList 是节点列表,而QDomNamedNodeMap 则用于处理无序的节点集(通常用于属性)。

QDomImplementation 类允许用户查询 DOM 实现的特征。

要开始使用,请参阅QDomDocument 文档。您可能还想看看 DOM书签应用程序,该程序说明了如何使用 DOM 读写 XML 书签文件 (XBEL)。

© 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.