1
/***************************************************************************
2
File : XmlStreamReader.h
4
Description : XML stream parser that supports errors as well as warnings
5
--------------------------------------------------------------------
6
Copyright : (C) 2008-2009 Tilman Benkert (thzs*gmx.net)
7
(replace * with @ in the email addresses)
9
***************************************************************************/
11
/***************************************************************************
13
* This program is free software; you can redistribute it and/or modify *
14
* it under the terms of the GNU General Public License as published by *
15
* the Free Software Foundation; either version 2 of the License, or *
16
* (at your option) any later version. *
18
* This program is distributed in the hope that it will be useful, *
19
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
20
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
21
* GNU General Public License for more details. *
23
* You should have received a copy of the GNU General Public License *
24
* along with this program; if not, write to the Free Software *
25
* Foundation, Inc., 51 Franklin Street, Fifth Floor, *
26
* Boston, MA 02110-1301 USA *
28
***************************************************************************/
29
#ifndef XML_STREAM_READER_H
30
#define XML_STREAM_READER_H
32
#include <QXmlStreamReader>
34
#include <QStringList>
35
#include "lib/macros.h"
37
//! XML stream parser that supports errors as well as warnings
39
* This class also adds line and column numbers to the error message.
41
class XmlStreamReader : public QXmlStreamReader
45
XmlStreamReader(QIODevice * device);
46
XmlStreamReader(const QByteArray & data);
47
XmlStreamReader(const QString & data);
48
XmlStreamReader(const char * data);
50
QStringList warningStrings() const;
51
bool hasWarnings() const;
52
void raiseWarning(const QString & message = QString());
53
void raiseError(const QString & message = QString());
54
CLASS_ACCESSOR(QString, d_error_prefix, errorPrefix, ErrorPrefix);
55
CLASS_ACCESSOR(QString, d_error_postfix, errorPostfix, ErrorPostfix);
56
CLASS_ACCESSOR(QString, d_warning_prefix, warningPrefix, WarningPrefix);
57
CLASS_ACCESSOR(QString, d_warning_postfix, warningPostfix, WarningPostfix);
59
//! Go to the next start or end element tag
61
* If the end of the document is reached, an error is raised.
63
* \return false if end of document reached, otherwise true
66
//! Go to the end element tag of the current element
68
* If the end of the document is reached, an error is raised.
70
* \return false if end of document reached, otherwise true
72
bool skipToEndElement();
74
//! Read an XML attribute and convert it to int
76
* \param name attribute name
77
* \param ok pointer to report back whether the attribute value could be determined (may be NULL)
78
* \return the attriute value if found and converted, otherwise zero (in this case *ok is false)
80
int readAttributeInt(const QString & name, bool * ok);
83
QStringList d_warnings;
84
QString d_error_prefix;
85
QString d_error_postfix;
86
QString d_warning_prefix;
87
QString d_warning_postfix;
92
#endif // XML_STREAM_READER_H