Qt 5.10 Book Examples
chapter40
XmlDOMRead
main.cpp
Go to the documentation of this file.
1
// ======================================================================
2
// main.cpp
3
// ======================================================================
4
// This file is a part of the book
5
// "Qt 5.10 Professional programming with C++"
6
// http://qt-book.com
7
// ======================================================================
8
// Copyright (c) 2017 by Max Schlee
9
// ======================================================================
10
11
#include <QtXml>
12
13
// ----------------------------------------------------------------------
14
void
traverseNode
(
const
QDomNode& node)
15
{
16
QDomNode domNode = node.firstChild();
17
while
(!domNode.isNull()) {
18
if
(domNode.isElement()) {
19
QDomElement domElement = domNode.toElement();
20
if
(!domElement.isNull()) {
21
if
(domElement.tagName() ==
"contact"
) {
22
qDebug() <<
"Attr: "
23
<< domElement.attribute(
"number"
,
""
);
24
}
25
else
{
26
qDebug() <<
"TagName: "
<< domElement.tagName()
27
<<
"\tText: "
<< domElement.text();
28
}
29
}
30
}
31
traverseNode
(domNode);
32
domNode = domNode.nextSibling();
33
}
34
}
35
36
// ----------------------------------------------------------------------
37
int
main
()
38
{
39
QDomDocument domDoc;
40
QFile file(
"addressbook.xml"
);
41
42
if
(file.open(QIODevice::ReadOnly)) {
43
if
(domDoc.setContent(&file)) {
44
QDomElement domElement= domDoc.documentElement();
45
traverseNode
(domElement);
46
}
47
file.close();
48
}
49
50
return
0;
51
}
main
int main(int argc, char **argv)
Definition:
main.cpp:15
traverseNode
void traverseNode(const QDomNode &node)
Definition:
main.cpp:14
Generated by
1.8.14