1
/****************************************************************************
3
** Copyright (C) 2016 The Qt Company Ltd.
4
** Contact: https://www.qt.io/licensing/
6
** This file is part of the documentation of the Qt Toolkit.
8
** $QT_BEGIN_LICENSE:FDL$
9
** Commercial License Usage
10
** Licensees holding valid commercial Qt licenses may use this file in
11
** accordance with the commercial license agreement provided with the
12
** Software or, alternatively, in accordance with the terms contained in
13
** a written agreement between you and The Qt Company. For licensing terms
14
** and conditions see https://www.qt.io/terms-conditions. For further
15
** information use the contact form at https://www.qt.io/contact-us.
17
** GNU Free Documentation License Usage
18
** Alternatively, this file may be used under the terms of the GNU Free
19
** Documentation License version 1.3 as published by the Free Software
20
** Foundation and appearing in the file included in the packaging of
21
** this file. Please review the following information to ensure
22
** the GNU Free Documentation License version 1.3 requirements
23
** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
26
****************************************************************************/
29
\example xmlstreamlint
30
\title XML Stream Lint Example
32
\brief A commandline tool reading from an input file and writing to
33
the standard output file.
35
The XML Stream Lint example provides a simple command line utility that
36
accepts a file name as its single argument and writes it to the standard
39
The specified file is parsed using an QXmlStreamReader object and written
40
to the standard output file using an QXmlStreamWriter object. If the file
41
does not contain a well-formed XML document or the use of namespaces in
42
the document is incorrect, a description of the error is printed to
43
the standard error file and will appear in the console.
45
\section1 Basic Operation
47
The main function of the example opens the file specified by the user
48
for input (\c inputFile), and it uses QFile to access the standard output
51
Reading XML is handled by an instance of the QXmlStreamReader class, which
52
operates on the input file object; writing is handled by an instance of
53
QXmlStreamWriter operating on the output file object:
55
\snippet xmlstreamlint/main.cpp 0
57
The work of parsing and rewriting the XML is done in a while loop, and is
58
driven by input from the reader:
60
\snippet xmlstreamlint/main.cpp 1
62
If more input is available, the next token from the input file is read
63
and parsed. If an error occurred, information is written to the standard
64
error file via a stream, and the example exits by returning a non-zero
65
value from the main function.
67
\snippet xmlstreamlint/main.cpp 2
69
For valid input, the writer is fed the current token from the reader,
70
and this is written to the output file that was specified when it was
73
When there is no more input, the loop terminates, and the example can