1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the documentation of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:FDL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in a
|
---|
14 | ** written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Free Documentation License
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Free
|
---|
18 | ** Documentation License version 1.3 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file included in the packaging of this
|
---|
20 | ** file.
|
---|
21 | **
|
---|
22 | ** If you have questions regarding the use of this file, please contact
|
---|
23 | ** Nokia at [email protected].
|
---|
24 | ** $QT_END_LICENSE$
|
---|
25 | **
|
---|
26 | ****************************************************************************/
|
---|
27 |
|
---|
28 | /*!
|
---|
29 | \example xml/xmlstreamlint
|
---|
30 | \title XML Stream Lint Example
|
---|
31 |
|
---|
32 | The XML Stream Lint example provides a simple command line utility that
|
---|
33 | accepts a file name as its single argument and writes it to the standard
|
---|
34 | output file.
|
---|
35 |
|
---|
36 | The specified file is parsed using an QXmlStreamReader object and written
|
---|
37 | to the standard output file using an QXmlStreamWriter object. If the file
|
---|
38 | does not contain a well-formed XML document or the use of namespaces in
|
---|
39 | the document is incorrect, a description of the error is printed to
|
---|
40 | the standard error file and will appear in the console.
|
---|
41 |
|
---|
42 | \section1 Basic Operation
|
---|
43 |
|
---|
44 | The main function of the example opens the file specified by the user
|
---|
45 | for input (\c inputFile), and it uses QFile to access the standard output
|
---|
46 | file.
|
---|
47 |
|
---|
48 | Reading XML is handled by an instance of the QXmlStreamReader class, which
|
---|
49 | operates on the input file object; writing is handled by an instance of
|
---|
50 | QXmlStreamWriter operating on the output file object:
|
---|
51 |
|
---|
52 | \snippet examples/xml/xmlstreamlint/main.cpp 0
|
---|
53 |
|
---|
54 | The work of parsing and rewriting the XML is done in a while loop, and is
|
---|
55 | driven by input from the reader:
|
---|
56 |
|
---|
57 | \snippet examples/xml/xmlstreamlint/main.cpp 1
|
---|
58 |
|
---|
59 | If more input is available, the next token from the input file is read
|
---|
60 | and parsed. If an error occurred, information is written to the standard
|
---|
61 | error file via a stream, and the example exits by returning a non-zero
|
---|
62 | value from the main function.
|
---|
63 |
|
---|
64 | \snippet examples/xml/xmlstreamlint/main.cpp 2
|
---|
65 |
|
---|
66 | For valid input, the writer is fed the current token from the reader,
|
---|
67 | and this is written to the output file that was specified when it was
|
---|
68 | constructed.
|
---|
69 |
|
---|
70 | When there is no more input, the loop terminates, and the example can
|
---|
71 | exit successfully.
|
---|
72 | */
|
---|