Qt 4.8
qxml.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtXml module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
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 Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QXML_H
43 #define QXML_H
44 
45 #include <QtCore/qtextstream.h>
46 #include <QtCore/qfile.h>
47 #include <QtCore/qstring.h>
48 #include <QtCore/qstringlist.h>
49 #include <QtCore/qlist.h>
50 #include <QtCore/qscopedpointer.h>
51 
53 
55 
56 QT_MODULE(Xml)
57 
59 class QXmlAttributes;
60 class QXmlContentHandler;
61 class QXmlDefaultHandler;
62 class QXmlDTDHandler;
63 class QXmlEntityResolver;
64 class QXmlErrorHandler;
65 class QXmlLexicalHandler;
66 class QXmlDeclHandler;
67 class QXmlInputSource;
68 class QXmlLocator;
70 class QXmlParseException;
71 
72 class QXmlReader;
73 class QXmlSimpleReader;
74 
80 class QXmlLocatorPrivate;
82 
83 
84 //
85 // SAX Namespace Support
86 //
87 
89 {
90 public:
93 
94  void setPrefix(const QString&, const QString&);
95 
96  QString prefix(const QString&) const;
97  QString uri(const QString&) const;
98  void splitName(const QString&, QString&, QString&) const;
99  void processName(const QString&, bool, QString&, QString&) const;
100  QStringList prefixes() const;
101  QStringList prefixes(const QString&) const;
102 
103  void pushContext();
104  void popContext();
105  void reset();
106 
107 private:
109 
112 };
113 
114 
115 //
116 // SAX Attributes
117 //
118 
120 {
121 public:
123  virtual ~QXmlAttributes() {}
124 
125  int index(const QString& qName) const;
126  int index(const QLatin1String& qName) const;
127  int index(const QString& uri, const QString& localPart) const;
128  int length() const;
129  int count() const;
130  QString localName(int index) const;
131  QString qName(int index) const;
132  QString uri(int index) const;
133  QString type(int index) const;
134  QString type(const QString& qName) const;
135  QString type(const QString& uri, const QString& localName) const;
136  QString value(int index) const;
137  QString value(const QString& qName) const;
138  QString value(const QLatin1String& qName) const;
139  QString value(const QString& uri, const QString& localName) const;
140 
141  void clear();
142  void append(const QString &qName, const QString &uri, const QString &localPart, const QString &value);
143 
144 private:
145  struct Attribute {
146  QString qname, uri, localname, value;
147  };
149  AttributeList attList;
150 
152 };
153 
154 //
155 // SAX Input Source
156 //
157 
159 {
160 public:
161  QXmlInputSource();
163  virtual ~QXmlInputSource();
164 
165  virtual void setData(const QString& dat);
166  virtual void setData(const QByteArray& dat);
167  virtual void fetchData();
168  virtual QString data() const;
169  virtual QChar next();
170  virtual void reset();
171 
172  static const ushort EndOfData;
173  static const ushort EndOfDocument;
174 
175 #ifdef QT3_SUPPORT
176  QT3_SUPPORT_CONSTRUCTOR QXmlInputSource(QFile& file);
177  QT3_SUPPORT_CONSTRUCTOR QXmlInputSource(QTextStream& stream);
178 #endif
179 
180 protected:
181  virtual QString fromRawData(const QByteArray &data, bool beginning = false);
182 
183 private:
184  void init();
186 };
187 
188 //
189 // SAX Exception Classes
190 //
191 
193 {
194 public:
195  explicit QXmlParseException(const QString &name = QString(), int c = -1, int l = -1,
196  const QString &p = QString(), const QString &s = QString());
199 
200  int columnNumber() const;
201  int lineNumber() const;
202  QString publicId() const;
203  QString systemId() const;
204  QString message() const;
205 
206 private:
208 };
209 
210 
211 //
212 // XML Reader
213 //
214 
216 {
217 public:
218  virtual ~QXmlReader() {}
219  virtual bool feature(const QString& name, bool *ok = 0) const = 0;
220  virtual void setFeature(const QString& name, bool value) = 0;
221  virtual bool hasFeature(const QString& name) const = 0;
222  virtual void* property(const QString& name, bool *ok = 0) const = 0;
223  virtual void setProperty(const QString& name, void* value) = 0;
224  virtual bool hasProperty(const QString& name) const = 0;
225  virtual void setEntityResolver(QXmlEntityResolver* handler) = 0;
226  virtual QXmlEntityResolver* entityResolver() const = 0;
227  virtual void setDTDHandler(QXmlDTDHandler* handler) = 0;
228  virtual QXmlDTDHandler* DTDHandler() const = 0;
229  virtual void setContentHandler(QXmlContentHandler* handler) = 0;
230  virtual QXmlContentHandler* contentHandler() const = 0;
231  virtual void setErrorHandler(QXmlErrorHandler* handler) = 0;
232  virtual QXmlErrorHandler* errorHandler() const = 0;
233  virtual void setLexicalHandler(QXmlLexicalHandler* handler) = 0;
234  virtual QXmlLexicalHandler* lexicalHandler() const = 0;
235  virtual void setDeclHandler(QXmlDeclHandler* handler) = 0;
236  virtual QXmlDeclHandler* declHandler() const = 0;
237  virtual bool parse(const QXmlInputSource& input) = 0;
238  virtual bool parse(const QXmlInputSource* input) = 0;
239 };
240 
242 {
243 public:
245  virtual ~QXmlSimpleReader();
246 
247  bool feature(const QString& name, bool *ok = 0) const;
248  void setFeature(const QString& name, bool value);
249  bool hasFeature(const QString& name) const;
250 
251  void* property(const QString& name, bool *ok = 0) const;
252  void setProperty(const QString& name, void* value);
253  bool hasProperty(const QString& name) const;
254 
255  void setEntityResolver(QXmlEntityResolver* handler);
256  QXmlEntityResolver* entityResolver() const;
257  void setDTDHandler(QXmlDTDHandler* handler);
258  QXmlDTDHandler* DTDHandler() const;
259  void setContentHandler(QXmlContentHandler* handler);
260  QXmlContentHandler* contentHandler() const;
261  void setErrorHandler(QXmlErrorHandler* handler);
262  QXmlErrorHandler* errorHandler() const;
263  void setLexicalHandler(QXmlLexicalHandler* handler);
264  QXmlLexicalHandler* lexicalHandler() const;
265  void setDeclHandler(QXmlDeclHandler* handler);
266  QXmlDeclHandler* declHandler() const;
267 
268  bool parse(const QXmlInputSource& input);
269  bool parse(const QXmlInputSource* input);
270  virtual bool parse(const QXmlInputSource* input, bool incremental);
271  virtual bool parseContinue();
272 
273 private:
277 
279 };
280 
281 //
282 // SAX Locator
283 //
284 
286 {
287 public:
288  QXmlLocator();
289  virtual ~QXmlLocator();
290 
291  virtual int columnNumber() const = 0;
292  virtual int lineNumber() const = 0;
293 // QString getPublicId() const
294 // QString getSystemId() const
295 };
296 
297 //
298 // SAX handler classes
299 //
300 
302 {
303 public:
304  virtual ~QXmlContentHandler() {}
305  virtual void setDocumentLocator(QXmlLocator* locator) = 0;
306  virtual bool startDocument() = 0;
307  virtual bool endDocument() = 0;
308  virtual bool startPrefixMapping(const QString& prefix, const QString& uri) = 0;
309  virtual bool endPrefixMapping(const QString& prefix) = 0;
310  virtual bool startElement(const QString& namespaceURI, const QString& localName, const QString& qName, const QXmlAttributes& atts) = 0;
311  virtual bool endElement(const QString& namespaceURI, const QString& localName, const QString& qName) = 0;
312  virtual bool characters(const QString& ch) = 0;
313  virtual bool ignorableWhitespace(const QString& ch) = 0;
314  virtual bool processingInstruction(const QString& target, const QString& data) = 0;
315  virtual bool skippedEntity(const QString& name) = 0;
316  virtual QString errorString() const = 0;
317 };
318 
320 {
321 public:
322  virtual ~QXmlErrorHandler() {}
323  virtual bool warning(const QXmlParseException& exception) = 0;
324  virtual bool error(const QXmlParseException& exception) = 0;
325  virtual bool fatalError(const QXmlParseException& exception) = 0;
326  virtual QString errorString() const = 0;
327 };
328 
330 {
331 public:
332  virtual ~QXmlDTDHandler() {}
333  virtual bool notationDecl(const QString& name, const QString& publicId, const QString& systemId) = 0;
334  virtual bool unparsedEntityDecl(const QString& name, const QString& publicId, const QString& systemId, const QString& notationName) = 0;
335  virtual QString errorString() const = 0;
336 };
337 
339 {
340 public:
341  virtual ~QXmlEntityResolver() {}
342  virtual bool resolveEntity(const QString& publicId, const QString& systemId, QXmlInputSource*& ret) = 0;
343  virtual QString errorString() const = 0;
344 };
345 
347 {
348 public:
349  virtual ~QXmlLexicalHandler() {}
350  virtual bool startDTD(const QString& name, const QString& publicId, const QString& systemId) = 0;
351  virtual bool endDTD() = 0;
352  virtual bool startEntity(const QString& name) = 0;
353  virtual bool endEntity(const QString& name) = 0;
354  virtual bool startCDATA() = 0;
355  virtual bool endCDATA() = 0;
356  virtual bool comment(const QString& ch) = 0;
357  virtual QString errorString() const = 0;
358 };
359 
361 {
362 public:
363  virtual ~QXmlDeclHandler() {}
364  virtual bool attributeDecl(const QString& eName, const QString& aName, const QString& type, const QString& valueDefault, const QString& value) = 0;
365  virtual bool internalEntityDecl(const QString& name, const QString& value) = 0;
366  virtual bool externalEntityDecl(const QString& name, const QString& publicId, const QString& systemId) = 0;
367  virtual QString errorString() const = 0;
368  // ### Qt 5: Conform to SAX by adding elementDecl
369 };
370 
371 
373 {
374 public:
376  virtual ~QXmlDefaultHandler() { }
377 
378  void setDocumentLocator(QXmlLocator* locator);
379  bool startDocument();
380  bool endDocument();
381  bool startPrefixMapping(const QString& prefix, const QString& uri);
382  bool endPrefixMapping(const QString& prefix);
383  bool startElement(const QString& namespaceURI, const QString& localName, const QString& qName, const QXmlAttributes& atts);
384  bool endElement(const QString& namespaceURI, const QString& localName, const QString& qName);
385  bool characters(const QString& ch);
386  bool ignorableWhitespace(const QString& ch);
387  bool processingInstruction(const QString& target, const QString& data);
388  bool skippedEntity(const QString& name);
389 
390  bool warning(const QXmlParseException& exception);
391  bool error(const QXmlParseException& exception);
392  bool fatalError(const QXmlParseException& exception);
393 
394  bool notationDecl(const QString& name, const QString& publicId, const QString& systemId);
395  bool unparsedEntityDecl(const QString& name, const QString& publicId, const QString& systemId, const QString& notationName);
396 
397  bool resolveEntity(const QString& publicId, const QString& systemId, QXmlInputSource*& ret);
398 
399  bool startDTD(const QString& name, const QString& publicId, const QString& systemId);
400  bool endDTD();
401  bool startEntity(const QString& name);
402  bool endEntity(const QString& name);
403  bool startCDATA();
404  bool endCDATA();
405  bool comment(const QString& ch);
406 
407  bool attributeDecl(const QString& eName, const QString& aName, const QString& type, const QString& valueDefault, const QString& value);
408  bool internalEntityDecl(const QString& name, const QString& value);
409  bool externalEntityDecl(const QString& name, const QString& publicId, const QString& systemId);
410 
411  QString errorString() const;
412 
413 private:
416 };
417 
418 // inlines
419 
420 inline int QXmlAttributes::count() const
421 { return length(); }
422 
424 
426 
427 #endif // QXML_H
static const ushort EndOfData
Definition: qxml.h:172
#define Q_XML_EXPORT
Definition: qglobal.h:1458
QXmlDefaultHandler()
Constructs a handler for use with subclasses of QXmlReader.
Definition: qxml.h:375
The QXmlLocator class provides the XML handler classes with information about the parsing position wi...
Definition: qxml.h:285
int type
Definition: qmetatype.cpp:239
unsigned char c[8]
Definition: qnumeric_p.h:62
The QXmlLexicalHandler class provides an interface to report the lexical content of XML data...
Definition: qxml.h:346
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
#define QT_MODULE(x)
Definition: qglobal.h:2783
virtual ~QXmlReader()
Destroys the reader.
Definition: qxml.h:218
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
#define error(msg)
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
Q_CORE_EXPORT QTextStream & reset(QTextStream &s)
static void clear(QVariant::Private *d)
Definition: qvariant.cpp:197
The QXmlNamespaceSupport class is a helper class for XML readers which want to include namespace supp...
Definition: qxml.h:88
#define Q_DISABLE_COPY(Class)
Disables the use of copy constructors and assignment operators for the given Class.
Definition: qglobal.h:2523
virtual ~QXmlErrorHandler()
Destroys the error handler.
Definition: qxml.h:322
The QString class provides a Unicode character string.
Definition: qstring.h:83
int count() const
Returns the number of attributes in the list.
Definition: qxml.h:420
The QXmlErrorHandler class provides an interface to report errors in XML data.
Definition: qxml.h:319
virtual ~QXmlEntityResolver()
Destroys the entity resolver.
Definition: qxml.h:341
The QXmlDTDHandler class provides an interface to report DTD content of XML data. ...
Definition: qxml.h:329
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
QXmlDefaultHandlerPrivate * d
Definition: qxml.h:414
Q_GUI_EXPORT QString errorString(EGLint code=eglGetError())
Definition: qegl.cpp:743
The QXmlSimpleReader class provides an implementation of a simple XML parser.
Definition: qxml.h:241
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
static FILE * stream
static bool init
static bool setData(const QByteArray &data, STGMEDIUM *pmedium)
Definition: qmime_win.cpp:141
const char * name
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
AttributeList attList
Definition: qxml.h:149
QXmlAttributes()
Constructs an empty attribute list.
Definition: qxml.h:122
static const char * data(const QByteArray &arr)
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
The QXmlContentHandler class provides an interface to report the logical content of XML data...
Definition: qxml.h:301
The QXmlDefaultHandler class provides a default implementation of all the XML handler classes...
Definition: qxml.h:372
The QXmlReader class provides an interface for XML readers (i.e.
Definition: qxml.h:215
static QChar resolveEntity(const QString &entity)
virtual ~QXmlContentHandler()
Destroys the content handler.
Definition: qxml.h:304
static bool hasFeature(const QDockWidgetPrivate *priv, QDockWidget::DockWidgetFeature feature)
Definition: qdockwidget.cpp:74
void * fetchData(QTestData *data, const char *tagName, int typeId)
Definition: qtestcase.cpp:1635
The QFile class provides an interface for reading from and writing to files.
Definition: qfile.h:65
virtual ~QXmlDefaultHandler()
Destroys the handler.
Definition: qxml.h:376
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73
unsigned short ushort
Definition: qglobal.h:995
const char * property
Definition: qwizard.cpp:138
QFactoryLoader * l
virtual ~QXmlAttributes()
Destroys the attributes object.
Definition: qxml.h:123
QXmlInputSourcePrivate * d
Definition: qxml.h:185
quint16 index
The QXmlAttributes class provides XML attributes.
Definition: qxml.h:119
#define Q_DECLARE_PRIVATE(Class)
Definition: qglobal.h:2467
The QXmlEntityResolver class provides an interface to resolve external entities contained in XML data...
Definition: qxml.h:338
The QXmlDeclHandler class provides an interface to report declaration content of XML data...
Definition: qxml.h:360
virtual ~QXmlDTDHandler()
Destroys the DTD handler.
Definition: qxml.h:332
QXmlAttributesPrivate * d
Definition: qxml.h:151
The QXmlInputSource class provides the input data for the QXmlReader subclasses.
Definition: qxml.h:158
QImageIOHandler * handler
virtual ~QXmlLexicalHandler()
Destroys the lexical handler.
Definition: qxml.h:349
#define class
QList< Attribute > AttributeList
Definition: qxml.h:148
The QIODevice class is the base interface class of all I/O devices in Qt.
Definition: qiodevice.h:66
virtual ~QXmlDeclHandler()
Destroys the declaration handler.
Definition: qxml.h:363
#define QT_END_HEADER
Definition: qglobal.h:137
static const ushort EndOfDocument
Definition: qxml.h:173
QScopedPointer< QXmlParseExceptionPrivate > d
Definition: qxml.h:207
The QXmlParseException class is used to report errors with the QXmlErrorHandler interface.
Definition: qxml.h:192
QXmlNamespaceSupportPrivate * d
Definition: qxml.h:108