1/****************************************************************************
2**
3** Copyright (C) 2019 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the test suite of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
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.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28
29#include "XmlParseHelper.h"
30
31QT_BEGIN_NAMESPACE
32
33namespace QPatternistSDK {
34
35bool XmlParseHelper::parse(QIODevice *input)
36{
37 QXmlStreamReader reader(input);
38
39 while (!reader.atEnd()) {
40 reader.readNext();
41 if (reader.hasError())
42 return false;
43
44 switch (reader.tokenType()) {
45 case QXmlStreamReader::StartElement:
46 if (!startElement(namespaceURI: reader.namespaceUri(), localName: reader.name(),
47 qName: reader.qualifiedName(), atts: reader.attributes())) {
48 return false;
49 }
50 break;
51 case QXmlStreamReader::EndElement:
52 if (!endElement(namespaceURI: reader.namespaceUri(), localName: reader.name(),
53 qName: reader.qualifiedName())) {
54 return false;
55 }
56 break;
57 case QXmlStreamReader::Characters:
58 if (!reader.isWhitespace() && !reader.text().toString().trimmed().isEmpty()) {
59 if (!characters(text: reader.text()))
60 return false;
61 }
62 break;
63 default:
64 break;
65 }
66 }
67
68 if (reader.isEndDocument() && !endDocument())
69 return false;
70
71 return true;
72}
73
74bool XmlParseHelper::startElement(const QStringRef &namespaceURI, const QStringRef &localName,
75 const QStringRef &qName, const QXmlStreamAttributes &atts)
76{
77 Q_UNUSED(namespaceURI)
78 Q_UNUSED(localName)
79 Q_UNUSED(qName)
80 Q_UNUSED(atts)
81 return true;
82}
83
84bool XmlParseHelper::endElement(const QStringRef &namespaceURI, const QStringRef &localName,
85 const QStringRef &qName)
86{
87 Q_UNUSED(namespaceURI)
88 Q_UNUSED(localName)
89 Q_UNUSED(qName)
90 return true;
91}
92
93bool XmlParseHelper::characters(const QStringRef &text)
94{
95 Q_UNUSED(text)
96 return true;
97}
98
99bool XmlParseHelper::endDocument()
100{
101 return true;
102}
103
104} // namespace QPatternistSDK
105
106QT_END_NAMESPACE
107

source code of qtxmlpatterns/tests/auto/xmlpatternssdk/XmlParseHelper.cpp