- Qt 6.8
- Qt XML
- Working with the DOM Tree
- Qt 6.8.3 Reference Documentation

XML Streaming

# Working with the DOM Tree

DOM Level 2 is a W3C Recommendation for XML interfaces that maps the constituents of an XML document to a tree structure. The specification of DOM Level 2 can be found at http://www.w3.org/DOM/.

## Introduction to DOM

DOM provides an interface to access and change the content and structure of an XML file. It makes a hierarchical view of the document (a tree view). Thus – in contrast to the streaming API provided by QXmlStreamReader – an object model of the document is resident in memory after parsing which makes manipulation easy.

All DOM nodes in the document tree are subclasses of QDomNode. The document itself is represented as a QDomDocument object.

Here are the available node classes and their potential child classes:

- QDomDocument: Possible children are
  - QDomElement (at most one)
  - QDomProcessingInstruction
  - QDomComment
  - QDomDocumentType
- QDomDocumentFragment: Possible children are
  - QDomElement
  - QDomProcessingInstruction
  - QDomComment
  - QDomText
  - QDomCDATASection
  - QDomEntityReference
- QDomDocumentType: No children
- QDomEntityReference: Possible children are
  - QDomElement
  - QDomProcessingInstruction
  - QDomComment
  - QDomText
  - QDomCDATASection
  - QDomEntityReference
- QDomElement: Possible children are
  - QDomElement
  - QDomText
  - QDomComment
  - QDomProcessingInstruction
  - QDomCDATASection
  - QDomEntityReference
- QDomAttr: Possible children are
  - QDomText
  - QDomEntityReference
- QDomProcessingInstruction: No children
- QDomComment: No children
- QDomText: No children
- QDomCDATASection: No children
- QDomEntity: Possible children are
  - QDomElement
  - QDomProcessingInstruction
  - QDomComment
  - QDomText
  - QDomCDATASection
  - QDomEntityReference
- QDomNotation: No children

With QDomNodeList and QDomNamedNodeMap two collection classes are provided: QDomNodeList is a list of nodes, and QDomNamedNodeMap is used to handle unordered sets of nodes (often used for attributes).

The QDomImplementation class allows the user to query features of the DOM implementation.

To get started please refer to the QDomDocument documentation. You might also want to take a look at the DOM Bookmarks Application, which illustrates how to read and write an XML bookmark file (XBEL) using DOM.

XML Streaming