1// Copyright (C) 2019 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
4#include "xmlparser.h"
5
6QT_BEGIN_NAMESPACE
7
8bool XmlParser::parse()
9{
10 while (!reader.atEnd()) {
11 reader.readNext();
12 if (reader.hasError()) {
13 fatalError(line: reader.lineNumber(), column: reader.columnNumber(), message: reader.errorString());
14 return false;
15 }
16
17 switch (reader.tokenType()) {
18 case QXmlStreamReader::StartElement:
19 if (!startElement(namespaceURI: reader.namespaceUri(), localName: reader.name(), qName: reader.qualifiedName(),
20 atts: reader.attributes())) {
21 return false;
22 }
23 break;
24 case QXmlStreamReader::EndElement:
25 if (!endElement(namespaceURI: reader.namespaceUri(), localName: reader.name(), qName: reader.qualifiedName())) {
26 return false;
27 }
28 break;
29 case QXmlStreamReader::Characters:
30 if (reportWhitespaceOnlyData
31 || (!reader.isWhitespace() && !reader.text().toString().trimmed().isEmpty())) {
32 if (!characters(text: reader.text()))
33 return false;
34 }
35 break;
36 default:
37 break;
38 }
39 }
40 if (reader.isEndDocument() && !endDocument())
41 return false;
42
43 return true;
44}
45
46bool XmlParser::startElement(QStringView namespaceURI, QStringView localName,
47 QStringView qName, const QXmlStreamAttributes &atts)
48{
49 Q_UNUSED(namespaceURI);
50 Q_UNUSED(localName);
51 Q_UNUSED(qName);
52 Q_UNUSED(atts);
53 return true;
54}
55
56bool XmlParser::endElement(QStringView namespaceURI, QStringView localName,
57 QStringView qName)
58{
59 Q_UNUSED(namespaceURI);
60 Q_UNUSED(localName);
61 Q_UNUSED(qName);
62 return true;
63}
64
65bool XmlParser::characters(QStringView text)
66{
67 Q_UNUSED(text);
68 return true;
69}
70
71bool XmlParser::fatalError(qint64 line, qint64 column, const QString &message)
72{
73 Q_UNUSED(line);
74 Q_UNUSED(column);
75 Q_UNUSED(message);
76 return true;
77}
78
79bool XmlParser::endDocument()
80{
81 return true;
82}
83
84QT_END_NAMESPACE
85

source code of qttools/src/linguist/shared/xmlparser.cpp