- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Directories
- Examples

- File List
- File Members

# qxml.h

Go to the documentation of this file.

    00001 /****************************************************************************
    00002 **
    00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
    00004 ** All rights reserved.
    00005 ** Contact: Nokia Corporation (qt-info@nokia.com)
    00006 **
    00007 ** This file is part of the QtXml module of the Qt Toolkit.
    00008 **
    00009 ** $QT_BEGIN_LICENSE:LGPL$
    00010 ** Commercial Usage
    00011 ** Licensees holding valid Qt Commercial licenses may use this file in
    00012 ** accordance with the Qt Commercial License Agreement provided with the
    00013 ** Software or, alternatively, in accordance with the terms contained in
    00014 ** a written agreement between you and Nokia.
    00015 **
    00016 ** GNU Lesser General Public License Usage
    00017 ** Alternatively, this file may be used under the terms of the GNU Lesser
    00018 ** General Public License version 2.1 as published by the Free Software
    00019 ** Foundation and appearing in the file LICENSE.LGPL included in the
    00020 ** packaging of this file.  Please review the following information to
    00021 ** ensure the GNU Lesser General Public License version 2.1 requirements
    00022 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    00023 **
    00024 ** In addition, as a special exception, Nokia gives you certain additional
    00025 ** rights.  These rights are described in the Nokia Qt LGPL Exception
    00026 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this module.
    00027 **
    00028 ** GNU General Public License Usage
    00029 ** Alternatively, this file may be used under the terms of the GNU
    00030 ** General Public License version 3.0 as published by the Free Software
    00031 ** Foundation and appearing in the file LICENSE.GPL included in the
    00032 ** packaging of this file.  Please review the following information to
    00033 ** ensure the GNU General Public License version 3.0 requirements will be
    00034 ** met: http://www.gnu.org/copyleft/gpl.html.
    00035 **
    00036 ** If you have questions regarding the use of this file, please contact
    00037 ** Nokia at qt-info@nokia.com.
    00038 ** $QT_END_LICENSE$
    00039 **
    00040 ****************************************************************************/
    00041
    00042 #ifndef QXML_H
    00043 #define QXML_H
    00044
    00045 #include <QtCore/qtextstream.h>
    00046 #include <QtCore/qfile.h>
    00047 #include <QtCore/qstring.h>
    00048 #include <QtCore/qstringlist.h>
    00049 #include <QtCore/qlist.h>
    00050 #include <QtCore/qscopedpointer.h>
    00051
    00052 QT_BEGIN_HEADER
    00053
    00054 QT_BEGIN_NAMESPACE
    00055
    00056 QT_MODULE(Xml)
    00057
    00058 class QXmlNamespaceSupport;
    00059 class QXmlAttributes;
    00060 class QXmlContentHandler;
    00061 class QXmlDefaultHandler;
    00062 class QXmlDTDHandler;
    00063 class QXmlEntityResolver;
    00064 class QXmlErrorHandler;
    00065 class QXmlLexicalHandler;
    00066 class QXmlDeclHandler;
    00067 class QXmlInputSource;
    00068 class QXmlLocator;
    00069 class QXmlNamespaceSupport;
    00070 class QXmlParseException;
    00071
    00072 class QXmlReader;
    00073 class QXmlSimpleReader;
    00074
    00075 class QXmlSimpleReaderPrivate;
    00076 class QXmlNamespaceSupportPrivate;
    00077 class QXmlAttributesPrivate;
    00078 class QXmlInputSourcePrivate;
    00079 class QXmlParseExceptionPrivate;
    00080 class QXmlLocatorPrivate;
    00081 class QXmlDefaultHandlerPrivate;
    00082
    00083
    00084 //
    00085 // SAX Namespace Support
    00086 //
    00087
    00088 class Q_XML_EXPORT QXmlNamespaceSupport
    00089 {
    00090 public:
    00091     QXmlNamespaceSupport();
    00092     ~QXmlNamespaceSupport();
    00093
    00094     void setPrefix(const QString&, const QString&);
    00095
    00096     QString prefix(const QString&) const;
    00097     QString uri(const QString&) const;
    00098     void splitName(const QString&, QString&, QString&) const;
    00099     void processName(const QString&, bool, QString&, QString&) const;
    00100     QStringList prefixes() const;
    00101     QStringList prefixes(const QString&) const;
    00102
    00103     void pushContext();
    00104     void popContext();
    00105     void reset();
    00106
    00107 private:
    00108     QXmlNamespaceSupportPrivate *d;
    00109
    00110     friend class QXmlSimpleReaderPrivate;
    00111     Q_DISABLE_COPY(QXmlNamespaceSupport)
    00112 };
    00113
    00114
    00115 //
    00116 // SAX Attributes
    00117 //
    00118
    00119 class Q_XML_EXPORT QXmlAttributes
    00120 {
    00121 public:
    00122     QXmlAttributes() {}
    00123     virtual ~QXmlAttributes() {}
    00124
    00125     int index(const QString& qName) const;
    00126     int index(const QLatin1String& qName) const;
    00127     int index(const QString& uri, const QString& localPart) const;
    00128     int length() const;
    00129     int count() const;
    00130     QString localName(int index) const;
    00131     QString qName(int index) const;
    00132     QString uri(int index) const;
    00133     QString type(int index) const;
    00134     QString type(const QString& qName) const;
    00135     QString type(const QString& uri, const QString& localName) const;
    00136     QString value(int index) const;
    00137     QString value(const QString& qName) const;
    00138     QString value(const QLatin1String& qName) const;
    00139     QString value(const QString& uri, const QString& localName) const;
    00140
    00141     void clear();
    00142     void append(const QString &qName, const QString &uri, const QString &localPart, const QString &value);
    00143
    00144 private:
    00145     struct Attribute {
    00146         QString qname, uri, localname, value;
    00147     };
    00148     typedef QList<Attribute> AttributeList;
    00149     AttributeList attList;
    00150
    00151     QXmlAttributesPrivate *d;
    00152 };
    00153
    00154 //
    00155 // SAX Input Source
    00156 //
    00157
    00158 class Q_XML_EXPORT QXmlInputSource
    00159 {
    00160 public:
    00161     QXmlInputSource();
    00162     QXmlInputSource(QIODevice *dev);
    00163     virtual ~QXmlInputSource();
    00164
    00165     virtual void setData(const QString& dat);
    00166     virtual void setData(const QByteArray& dat);
    00167     virtual void fetchData();
    00168     virtual QString data() const;
    00169     virtual QChar next();
    00170     virtual void reset();
    00171
    00172     static const ushort EndOfData;
    00173     static const ushort EndOfDocument;
    00174
    00175 #ifdef QT3_SUPPORT
    00176     QT3_SUPPORT_CONSTRUCTOR QXmlInputSource(QFile& file);
    00177     QT3_SUPPORT_CONSTRUCTOR QXmlInputSource(QTextStream& stream);
    00178 #endif
    00179
    00180 protected:
    00181     virtual QString fromRawData(const QByteArray &data, bool beginning = false);
    00182
    00183 private:
    00184     void init();
    00185     QXmlInputSourcePrivate *d;
    00186 };
    00187
    00188 //
    00189 // SAX Exception Classes
    00190 //
    00191
    00192 class Q_XML_EXPORT QXmlParseException
    00193 {
    00194 public:
    00195     explicit QXmlParseException(const QString &name = QString(), int c = -1, int l = -1,
    00196                                 const QString &p = QString(), const QString &s = QString());
    00197     QXmlParseException(const QXmlParseException &other);
    00198     ~QXmlParseException();
    00199
    00200     int columnNumber() const;
    00201     int lineNumber() const;
    00202     QString publicId() const;
    00203     QString systemId() const;
    00204     QString message() const;
    00205
    00206 private:
    00207     QScopedPointer<QXmlParseExceptionPrivate> d;
    00208 };
    00209
    00210
    00211 //
    00212 // XML Reader
    00213 //
    00214
    00215 class Q_XML_EXPORT QXmlReader
    00216 {
    00217 public:
    00218     virtual ~QXmlReader() {}
    00219     virtual bool feature(const QString& name, bool *ok = 0) const = 0;
    00220     virtual void setFeature(const QString& name, bool value) = 0;
    00221     virtual bool hasFeature(const QString& name) const = 0;
    00222     virtual void* property(const QString& name, bool *ok = 0) const = 0;
    00223     virtual void setProperty(const QString& name, void* value) = 0;
    00224     virtual bool hasProperty(const QString& name) const = 0;
    00225     virtual void setEntityResolver(QXmlEntityResolver* handler) = 0;
    00226     virtual QXmlEntityResolver* entityResolver() const = 0;
    00227     virtual void setDTDHandler(QXmlDTDHandler* handler) = 0;
    00228     virtual QXmlDTDHandler* DTDHandler() const = 0;
    00229     virtual void setContentHandler(QXmlContentHandler* handler) = 0;
    00230     virtual QXmlContentHandler* contentHandler() const = 0;
    00231     virtual void setErrorHandler(QXmlErrorHandler* handler) = 0;
    00232     virtual QXmlErrorHandler* errorHandler() const = 0;
    00233     virtual void setLexicalHandler(QXmlLexicalHandler* handler) = 0;
    00234     virtual QXmlLexicalHandler* lexicalHandler() const = 0;
    00235     virtual void setDeclHandler(QXmlDeclHandler* handler) = 0;
    00236     virtual QXmlDeclHandler* declHandler() const = 0;
    00237     virtual bool parse(const QXmlInputSource& input) = 0;
    00238     virtual bool parse(const QXmlInputSource* input) = 0;
    00239 };
    00240
    00241 class Q_XML_EXPORT QXmlSimpleReader : public QXmlReader
    00242 {
    00243 public:
    00244     QXmlSimpleReader();
    00245     virtual ~QXmlSimpleReader();
    00246
    00247     bool feature(const QString& name, bool *ok = 0) const;
    00248     void setFeature(const QString& name, bool value);
    00249     bool hasFeature(const QString& name) const;
    00250
    00251     void* property(const QString& name, bool *ok = 0) const;
    00252     void setProperty(const QString& name, void* value);
    00253     bool hasProperty(const QString& name) const;
    00254
    00255     void setEntityResolver(QXmlEntityResolver* handler);
    00256     QXmlEntityResolver* entityResolver() const;
    00257     void setDTDHandler(QXmlDTDHandler* handler);
    00258     QXmlDTDHandler* DTDHandler() const;
    00259     void setContentHandler(QXmlContentHandler* handler);
    00260     QXmlContentHandler* contentHandler() const;
    00261     void setErrorHandler(QXmlErrorHandler* handler);
    00262     QXmlErrorHandler* errorHandler() const;
    00263     void setLexicalHandler(QXmlLexicalHandler* handler);
    00264     QXmlLexicalHandler* lexicalHandler() const;
    00265     void setDeclHandler(QXmlDeclHandler* handler);
    00266     QXmlDeclHandler* declHandler() const;
    00267
    00268     bool parse(const QXmlInputSource& input);
    00269     bool parse(const QXmlInputSource* input);
    00270     virtual bool parse(const QXmlInputSource* input, bool incremental);
    00271     virtual bool parseContinue();
    00272
    00273 private:
    00274     Q_DISABLE_COPY(QXmlSimpleReader)
    00275     Q_DECLARE_PRIVATE(QXmlSimpleReader)
    00276     QScopedPointer<QXmlSimpleReaderPrivate> d_ptr;
    00277
    00278     friend class QXmlSimpleReaderLocator;
    00279 };
    00280
    00281 //
    00282 // SAX Locator
    00283 //
    00284
    00285 class Q_XML_EXPORT QXmlLocator
    00286 {
    00287 public:
    00288     QXmlLocator();
    00289     virtual ~QXmlLocator();
    00290
    00291     virtual int columnNumber() const = 0;
    00292     virtual int lineNumber() const = 0;
    00293 //    QString getPublicId() const
    00294 //    QString getSystemId() const
    00295 };
    00296
    00297 //
    00298 // SAX handler classes
    00299 //
    00300
    00301 class Q_XML_EXPORT QXmlContentHandler
    00302 {
    00303 public:
    00304     virtual ~QXmlContentHandler() {}
    00305     virtual void setDocumentLocator(QXmlLocator* locator) = 0;
    00306     virtual bool startDocument() = 0;
    00307     virtual bool endDocument() = 0;
    00308     virtual bool startPrefixMapping(const QString& prefix, const QString& uri) = 0;
    00309     virtual bool endPrefixMapping(const QString& prefix) = 0;
    00310     virtual bool startElement(const QString& namespaceURI, const QString& localName, const QString& qName, const QXmlAttributes& atts) = 0;
    00311     virtual bool endElement(const QString& namespaceURI, const QString& localName, const QString& qName) = 0;
    00312     virtual bool characters(const QString& ch) = 0;
    00313     virtual bool ignorableWhitespace(const QString& ch) = 0;
    00314     virtual bool processingInstruction(const QString& target, const QString& data) = 0;
    00315     virtual bool skippedEntity(const QString& name) = 0;
    00316     virtual QString errorString() const = 0;
    00317 };
    00318
    00319 class Q_XML_EXPORT QXmlErrorHandler
    00320 {
    00321 public:
    00322     virtual ~QXmlErrorHandler() {}
    00323     virtual bool warning(const QXmlParseException& exception) = 0;
    00324     virtual bool error(const QXmlParseException& exception) = 0;
    00325     virtual bool fatalError(const QXmlParseException& exception) = 0;
    00326     virtual QString errorString() const = 0;
    00327 };
    00328
    00329 class Q_XML_EXPORT QXmlDTDHandler
    00330 {
    00331 public:
    00332     virtual ~QXmlDTDHandler() {}
    00333     virtual bool notationDecl(const QString& name, const QString& publicId, const QString& systemId) = 0;
    00334     virtual bool unparsedEntityDecl(const QString& name, const QString& publicId, const QString& systemId, const QString& notationName) = 0;
    00335     virtual QString errorString() const = 0;
    00336 };
    00337
    00338 class Q_XML_EXPORT QXmlEntityResolver
    00339 {
    00340 public:
    00341     virtual ~QXmlEntityResolver() {}
    00342     virtual bool resolveEntity(const QString& publicId, const QString& systemId, QXmlInputSource*& ret) = 0;
    00343     virtual QString errorString() const = 0;
    00344 };
    00345
    00346 class Q_XML_EXPORT QXmlLexicalHandler
    00347 {
    00348 public:
    00349     virtual ~QXmlLexicalHandler() {}
    00350     virtual bool startDTD(const QString& name, const QString& publicId, const QString& systemId) = 0;
    00351     virtual bool endDTD() = 0;
    00352     virtual bool startEntity(const QString& name) = 0;
    00353     virtual bool endEntity(const QString& name) = 0;
    00354     virtual bool startCDATA() = 0;
    00355     virtual bool endCDATA() = 0;
    00356     virtual bool comment(const QString& ch) = 0;
    00357     virtual QString errorString() const = 0;
    00358 };
    00359
    00360 class Q_XML_EXPORT QXmlDeclHandler
    00361 {
    00362 public:
    00363     virtual ~QXmlDeclHandler() {}
    00364     virtual bool attributeDecl(const QString& eName, const QString& aName, const QString& type, const QString& valueDefault, const QString& value) = 0;
    00365     virtual bool internalEntityDecl(const QString& name, const QString& value) = 0;
    00366     virtual bool externalEntityDecl(const QString& name, const QString& publicId, const QString& systemId) = 0;
    00367     virtual QString errorString() const = 0;
    00368     // ### Qt 5: Conform to SAX by adding elementDecl
    00369 };
    00370
    00371
    00372 class Q_XML_EXPORT QXmlDefaultHandler : public QXmlContentHandler, public QXmlErrorHandler, public QXmlDTDHandler, public QXmlEntityResolver, public QXmlLexicalHandler, public QXmlDeclHandler
    00373 {
    00374 public:
    00375     QXmlDefaultHandler() { }
    00376     virtual ~QXmlDefaultHandler() { }
    00377
    00378     void setDocumentLocator(QXmlLocator* locator);
    00379     bool startDocument();
    00380     bool endDocument();
    00381     bool startPrefixMapping(const QString& prefix, const QString& uri);
    00382     bool endPrefixMapping(const QString& prefix);
    00383     bool startElement(const QString& namespaceURI, const QString& localName, const QString& qName, const QXmlAttributes& atts);
    00384     bool endElement(const QString& namespaceURI, const QString& localName, const QString& qName);
    00385     bool characters(const QString& ch);
    00386     bool ignorableWhitespace(const QString& ch);
    00387     bool processingInstruction(const QString& target, const QString& data);
    00388     bool skippedEntity(const QString& name);
    00389
    00390     bool warning(const QXmlParseException& exception);
    00391     bool error(const QXmlParseException& exception);
    00392     bool fatalError(const QXmlParseException& exception);
    00393
    00394     bool notationDecl(const QString& name, const QString& publicId, const QString& systemId);
    00395     bool unparsedEntityDecl(const QString& name, const QString& publicId, const QString& systemId, const QString& notationName);
    00396
    00397     bool resolveEntity(const QString& publicId, const QString& systemId, QXmlInputSource*& ret);
    00398
    00399     bool startDTD(const QString& name, const QString& publicId, const QString& systemId);
    00400     bool endDTD();
    00401     bool startEntity(const QString& name);
    00402     bool endEntity(const QString& name);
    00403     bool startCDATA();
    00404     bool endCDATA();
    00405     bool comment(const QString& ch);
    00406
    00407     bool attributeDecl(const QString& eName, const QString& aName, const QString& type, const QString& valueDefault, const QString& value);
    00408     bool internalEntityDecl(const QString& name, const QString& value);
    00409     bool externalEntityDecl(const QString& name, const QString& publicId, const QString& systemId);
    00410
    00411     QString errorString() const;
    00412
    00413 private:
    00414     QXmlDefaultHandlerPrivate *d;
    00415     Q_DISABLE_COPY(QXmlDefaultHandler)
    00416 };
    00417
    00418 // inlines
    00419
    00420 inline int QXmlAttributes::count() const
    00421 { return length(); }
    00422
    00423 QT_END_NAMESPACE
    00424
    00425 QT_END_HEADER
    00426
    00427 #endif // QXML_H