15.3.  XML, Tree Structures, and DOM

[ fromfile: xml-dom.xml id: xml-dom ]

The Document Object Model (DOM) is a higher-level interface for operating on XML documents. Working with and navigating through DOM documents is straightforward (especially if you are familiar with QObject children).

Figure 15.3.  QDom UML Model

QDom UML Model

The main classes in DOM are shown in Figure 15.3. The function setContent() parses the file, after which the QDomDocument contains a structured tree consisting of QDomNode objects. Each QDomNode could be an instance of QDomElement, QDomAttr, or QDomText. Every QDomNode has a parent except the root, which is a QDomDocument. Every node is reachable from the parent. DOM is another application of the Composite pattern.

[Note]Note

The QDom classes are wrappers around private implementation classes. They contain no data except a pointer. This makes it possible to pass around QDomNodes by value to other functions that can change the addressed objects (by adding attributes or children or by changing attributes). This gives QDom a more Java-like interface.