| 1 | /****************************************************************************
|
|---|
| 2 | ** $Id: qxml.h 2 2005-11-16 15:49:26Z dmik $
|
|---|
| 3 | **
|
|---|
| 4 | ** Definition of QXmlSimpleReader and related classes.
|
|---|
| 5 | **
|
|---|
| 6 | ** Created : 000518
|
|---|
| 7 | **
|
|---|
| 8 | ** Copyright (C) 1992-2002 Trolltech AS. All rights reserved.
|
|---|
| 9 | **
|
|---|
| 10 | ** This file is part of the xml module of the Qt GUI Toolkit.
|
|---|
| 11 | **
|
|---|
| 12 | ** This file may be distributed under the terms of the Q Public License
|
|---|
| 13 | ** as defined by Trolltech AS of Norway and appearing in the file
|
|---|
| 14 | ** LICENSE.QPL included in the packaging of this file.
|
|---|
| 15 | **
|
|---|
| 16 | ** This file may be distributed and/or modified under the terms of the
|
|---|
| 17 | ** GNU General Public License version 2 as published by the Free Software
|
|---|
| 18 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 19 | ** packaging of this file.
|
|---|
| 20 | **
|
|---|
| 21 | ** Licensees holding valid Qt Enterprise Edition licenses may use this
|
|---|
| 22 | ** file in accordance with the Qt Commercial License Agreement provided
|
|---|
| 23 | ** with the Software.
|
|---|
| 24 | **
|
|---|
| 25 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
|---|
| 26 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
|---|
| 27 | **
|
|---|
| 28 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
|
|---|
| 29 | ** information about Qt Commercial License Agreements.
|
|---|
| 30 | ** See http://www.trolltech.com/qpl/ for QPL licensing information.
|
|---|
| 31 | ** See http://www.trolltech.com/gpl/ for GPL licensing information.
|
|---|
| 32 | **
|
|---|
| 33 | ** Contact info@trolltech.com if any conditions of this licensing are
|
|---|
| 34 | ** not clear to you.
|
|---|
| 35 | **
|
|---|
| 36 | **********************************************************************/
|
|---|
| 37 |
|
|---|
| 38 | #ifndef QXML_H
|
|---|
| 39 | #define QXML_H
|
|---|
| 40 |
|
|---|
| 41 | #ifndef QT_H
|
|---|
| 42 | #include "qtextstream.h"
|
|---|
| 43 | #include "qfile.h"
|
|---|
| 44 | #include "qstring.h"
|
|---|
| 45 | #include "qstringlist.h"
|
|---|
| 46 | #endif // QT_H
|
|---|
| 47 |
|
|---|
| 48 | #if !defined(QT_MODULE_XML) || defined( QT_LICENSE_PROFESSIONAL ) || defined( QT_INTERNAL_XML )
|
|---|
| 49 | #define QM_EXPORT_XML
|
|---|
| 50 | #else
|
|---|
| 51 | #define QM_EXPORT_XML Q_EXPORT
|
|---|
| 52 | #endif
|
|---|
| 53 |
|
|---|
| 54 | #ifndef QT_NO_XML
|
|---|
| 55 |
|
|---|
| 56 | class QXmlNamespaceSupport;
|
|---|
| 57 | class QXmlAttributes;
|
|---|
| 58 | class QXmlContentHandler;
|
|---|
| 59 | class QXmlDefaultHandler;
|
|---|
| 60 | class QXmlDTDHandler;
|
|---|
| 61 | class QXmlEntityResolver;
|
|---|
| 62 | class QXmlErrorHandler;
|
|---|
| 63 | class QXmlLexicalHandler;
|
|---|
| 64 | class QXmlDeclHandler;
|
|---|
| 65 | class QXmlInputSource;
|
|---|
| 66 | class QXmlLocator;
|
|---|
| 67 | class QXmlNamespaceSupport;
|
|---|
| 68 | class QXmlParseException;
|
|---|
| 69 |
|
|---|
| 70 | class QXmlReader;
|
|---|
| 71 | class QXmlSimpleReader;
|
|---|
| 72 |
|
|---|
| 73 | class QXmlSimpleReaderPrivate;
|
|---|
| 74 | class QXmlNamespaceSupportPrivate;
|
|---|
| 75 | class QXmlAttributesPrivate;
|
|---|
| 76 | class QXmlInputSourcePrivate;
|
|---|
| 77 | class QXmlParseExceptionPrivate;
|
|---|
| 78 | class QXmlLocatorPrivate;
|
|---|
| 79 | class QXmlDefaultHandlerPrivate;
|
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 | //
|
|---|
| 83 | // SAX Namespace Support
|
|---|
| 84 | //
|
|---|
| 85 |
|
|---|
| 86 | class QM_EXPORT_XML QXmlNamespaceSupport
|
|---|
| 87 | {
|
|---|
| 88 | public:
|
|---|
| 89 | QXmlNamespaceSupport();
|
|---|
| 90 | ~QXmlNamespaceSupport();
|
|---|
| 91 |
|
|---|
| 92 | void setPrefix( const QString&, const QString& );
|
|---|
| 93 |
|
|---|
| 94 | QString prefix( const QString& ) const;
|
|---|
| 95 | QString uri( const QString& ) const;
|
|---|
| 96 | void splitName( const QString&, QString&, QString& ) const;
|
|---|
| 97 | void processName( const QString&, bool, QString&, QString& ) const;
|
|---|
| 98 | QStringList prefixes() const;
|
|---|
| 99 | QStringList prefixes( const QString& ) const;
|
|---|
| 100 |
|
|---|
| 101 | void pushContext();
|
|---|
| 102 | void popContext();
|
|---|
| 103 | void reset();
|
|---|
| 104 |
|
|---|
| 105 | private:
|
|---|
| 106 | QXmlNamespaceSupportPrivate *d;
|
|---|
| 107 | };
|
|---|
| 108 |
|
|---|
| 109 |
|
|---|
| 110 | //
|
|---|
| 111 | // SAX Attributes
|
|---|
| 112 | //
|
|---|
| 113 |
|
|---|
| 114 | class QM_EXPORT_XML QXmlAttributes
|
|---|
| 115 | {
|
|---|
| 116 | public:
|
|---|
| 117 | QXmlAttributes() {}
|
|---|
| 118 | virtual ~QXmlAttributes() {}
|
|---|
| 119 |
|
|---|
| 120 | int index( const QString& qName ) const;
|
|---|
| 121 | int index( const QString& uri, const QString& localPart ) const;
|
|---|
| 122 | int length() const;
|
|---|
| 123 | int count() const;
|
|---|
| 124 | QString localName( int index ) const;
|
|---|
| 125 | QString qName( int index ) const;
|
|---|
| 126 | QString uri( int index ) const;
|
|---|
| 127 | QString type( int index ) const;
|
|---|
| 128 | QString type( const QString& qName ) const;
|
|---|
| 129 | QString type( const QString& uri, const QString& localName ) const;
|
|---|
| 130 | QString value( int index ) const;
|
|---|
| 131 | QString value( const QString& qName ) const;
|
|---|
| 132 | QString value( const QString& uri, const QString& localName ) const;
|
|---|
| 133 |
|
|---|
| 134 | void clear();
|
|---|
| 135 | void append( const QString &qName, const QString &uri, const QString &localPart, const QString &value );
|
|---|
| 136 |
|
|---|
| 137 | private:
|
|---|
| 138 | QStringList qnameList;
|
|---|
| 139 | QStringList uriList;
|
|---|
| 140 | QStringList localnameList;
|
|---|
| 141 | QStringList valueList;
|
|---|
| 142 |
|
|---|
| 143 | QXmlAttributesPrivate *d;
|
|---|
| 144 | };
|
|---|
| 145 |
|
|---|
| 146 | //
|
|---|
| 147 | // SAX Input Source
|
|---|
| 148 | //
|
|---|
| 149 |
|
|---|
| 150 | class QM_EXPORT_XML QXmlInputSource
|
|---|
| 151 | {
|
|---|
| 152 | public:
|
|---|
| 153 | QXmlInputSource();
|
|---|
| 154 | QXmlInputSource( QIODevice *dev );
|
|---|
| 155 | QXmlInputSource( QFile& file ); // obsolete
|
|---|
| 156 | QXmlInputSource( QTextStream& stream ); // obsolete
|
|---|
| 157 | virtual ~QXmlInputSource();
|
|---|
| 158 |
|
|---|
| 159 | virtual void setData( const QString& dat );
|
|---|
| 160 | virtual void setData( const QByteArray& dat );
|
|---|
| 161 | virtual void fetchData();
|
|---|
| 162 | virtual QString data();
|
|---|
| 163 | virtual QChar next();
|
|---|
| 164 | virtual void reset();
|
|---|
| 165 |
|
|---|
| 166 | static const QChar EndOfData;
|
|---|
| 167 | static const QChar EndOfDocument;
|
|---|
| 168 |
|
|---|
| 169 | protected:
|
|---|
| 170 | virtual QString fromRawData( const QByteArray &data, bool beginning = FALSE );
|
|---|
| 171 |
|
|---|
| 172 | private:
|
|---|
| 173 | void init();
|
|---|
| 174 |
|
|---|
| 175 | QIODevice *inputDevice;
|
|---|
| 176 | QTextStream *inputStream;
|
|---|
| 177 |
|
|---|
| 178 | QString str;
|
|---|
| 179 | const QChar *unicode;
|
|---|
| 180 | int pos;
|
|---|
| 181 | int length;
|
|---|
| 182 | bool nextReturnedEndOfData;
|
|---|
| 183 | QTextDecoder *encMapper;
|
|---|
| 184 |
|
|---|
| 185 | QXmlInputSourcePrivate *d;
|
|---|
| 186 | };
|
|---|
| 187 |
|
|---|
| 188 | //
|
|---|
| 189 | // SAX Exception Classes
|
|---|
| 190 | //
|
|---|
| 191 |
|
|---|
| 192 | class QM_EXPORT_XML QXmlParseException
|
|---|
| 193 | {
|
|---|
| 194 | public:
|
|---|
| 195 | QXmlParseException( const QString& name="", int c=-1, int l=-1, const QString& p="", const QString& s="" )
|
|---|
| 196 | : msg( name ), column( c ), line( l ), pub( p ), sys( s )
|
|---|
| 197 | { }
|
|---|
| 198 |
|
|---|
| 199 | int columnNumber() const;
|
|---|
| 200 | int lineNumber() const;
|
|---|
| 201 | QString publicId() const;
|
|---|
| 202 | QString systemId() const;
|
|---|
| 203 | QString message() const;
|
|---|
| 204 |
|
|---|
| 205 | private:
|
|---|
| 206 | QString msg;
|
|---|
| 207 | int column;
|
|---|
| 208 | int line;
|
|---|
| 209 | QString pub;
|
|---|
| 210 | QString sys;
|
|---|
| 211 |
|
|---|
| 212 | QXmlParseExceptionPrivate *d;
|
|---|
| 213 | };
|
|---|
| 214 |
|
|---|
| 215 |
|
|---|
| 216 | //
|
|---|
| 217 | // XML Reader
|
|---|
| 218 | //
|
|---|
| 219 |
|
|---|
| 220 | class QM_EXPORT_XML QXmlReader
|
|---|
| 221 | {
|
|---|
| 222 | public:
|
|---|
| 223 | virtual bool feature( const QString& name, bool *ok = 0 ) const = 0;
|
|---|
| 224 | virtual void setFeature( const QString& name, bool value ) = 0;
|
|---|
| 225 | virtual bool hasFeature( const QString& name ) const = 0;
|
|---|
| 226 | virtual void* property( const QString& name, bool *ok = 0 ) const = 0;
|
|---|
| 227 | virtual void setProperty( const QString& name, void* value ) = 0;
|
|---|
| 228 | virtual bool hasProperty( const QString& name ) const = 0;
|
|---|
| 229 | virtual void setEntityResolver( QXmlEntityResolver* handler ) = 0;
|
|---|
| 230 | virtual QXmlEntityResolver* entityResolver() const = 0;
|
|---|
| 231 | virtual void setDTDHandler( QXmlDTDHandler* handler ) = 0;
|
|---|
| 232 | virtual QXmlDTDHandler* DTDHandler() const = 0;
|
|---|
| 233 | virtual void setContentHandler( QXmlContentHandler* handler ) = 0;
|
|---|
| 234 | virtual QXmlContentHandler* contentHandler() const = 0;
|
|---|
| 235 | virtual void setErrorHandler( QXmlErrorHandler* handler ) = 0;
|
|---|
| 236 | virtual QXmlErrorHandler* errorHandler() const = 0;
|
|---|
| 237 | virtual void setLexicalHandler( QXmlLexicalHandler* handler ) = 0;
|
|---|
| 238 | virtual QXmlLexicalHandler* lexicalHandler() const = 0;
|
|---|
| 239 | virtual void setDeclHandler( QXmlDeclHandler* handler ) = 0;
|
|---|
| 240 | virtual QXmlDeclHandler* declHandler() const = 0;
|
|---|
| 241 | virtual bool parse( const QXmlInputSource& input ) = 0;
|
|---|
| 242 | virtual bool parse( const QXmlInputSource* input ) = 0;
|
|---|
| 243 | };
|
|---|
| 244 |
|
|---|
| 245 | class QM_EXPORT_XML QXmlSimpleReader : public QXmlReader
|
|---|
| 246 | {
|
|---|
| 247 | public:
|
|---|
| 248 | QXmlSimpleReader();
|
|---|
| 249 | virtual ~QXmlSimpleReader();
|
|---|
| 250 |
|
|---|
| 251 | bool feature( const QString& name, bool *ok = 0 ) const;
|
|---|
| 252 | void setFeature( const QString& name, bool value );
|
|---|
| 253 | bool hasFeature( const QString& name ) const;
|
|---|
| 254 |
|
|---|
| 255 | void* property( const QString& name, bool *ok = 0 ) const;
|
|---|
| 256 | void setProperty( const QString& name, void* value );
|
|---|
| 257 | bool hasProperty( const QString& name ) const;
|
|---|
| 258 |
|
|---|
| 259 | void setEntityResolver( QXmlEntityResolver* handler );
|
|---|
| 260 | QXmlEntityResolver* entityResolver() const;
|
|---|
| 261 | void setDTDHandler( QXmlDTDHandler* handler );
|
|---|
| 262 | QXmlDTDHandler* DTDHandler() const;
|
|---|
| 263 | void setContentHandler( QXmlContentHandler* handler );
|
|---|
| 264 | QXmlContentHandler* contentHandler() const;
|
|---|
| 265 | void setErrorHandler( QXmlErrorHandler* handler );
|
|---|
| 266 | QXmlErrorHandler* errorHandler() const;
|
|---|
| 267 | void setLexicalHandler( QXmlLexicalHandler* handler );
|
|---|
| 268 | QXmlLexicalHandler* lexicalHandler() const;
|
|---|
| 269 | void setDeclHandler( QXmlDeclHandler* handler );
|
|---|
| 270 | QXmlDeclHandler* declHandler() const;
|
|---|
| 271 |
|
|---|
| 272 | bool parse( const QXmlInputSource& input );
|
|---|
| 273 | bool parse( const QXmlInputSource* input );
|
|---|
| 274 | virtual bool parse( const QXmlInputSource* input, bool incremental );
|
|---|
| 275 | virtual bool parseContinue();
|
|---|
| 276 |
|
|---|
| 277 | private:
|
|---|
| 278 | // variables
|
|---|
| 279 | QXmlContentHandler *contentHnd;
|
|---|
| 280 | QXmlErrorHandler *errorHnd;
|
|---|
| 281 | QXmlDTDHandler *dtdHnd;
|
|---|
| 282 | QXmlEntityResolver *entityRes;
|
|---|
| 283 | QXmlLexicalHandler *lexicalHnd;
|
|---|
| 284 | QXmlDeclHandler *declHnd;
|
|---|
| 285 |
|
|---|
| 286 | QXmlInputSource *inputSource;
|
|---|
| 287 |
|
|---|
| 288 | QChar c; // the character at reading position
|
|---|
| 289 | int lineNr; // number of line
|
|---|
| 290 | int columnNr; // position in line
|
|---|
| 291 |
|
|---|
| 292 | int namePos;
|
|---|
| 293 | QChar nameArray[256]; // only used for names
|
|---|
| 294 | QString nameValue; // only used for names
|
|---|
| 295 | int refPos;
|
|---|
| 296 | QChar refArray[256]; // only used for references
|
|---|
| 297 | QString refValue; // only used for references
|
|---|
| 298 | int stringPos;
|
|---|
| 299 | QChar stringArray[256]; // used for any other strings that are parsed
|
|---|
| 300 | QString stringValue; // used for any other strings that are parsed
|
|---|
| 301 |
|
|---|
| 302 | QXmlSimpleReaderPrivate* d;
|
|---|
| 303 |
|
|---|
| 304 | // inlines
|
|---|
| 305 | bool is_S( const QChar& );
|
|---|
| 306 | bool is_NameBeginning( const QChar& );
|
|---|
| 307 | bool is_NameChar( const QChar& );
|
|---|
| 308 |
|
|---|
| 309 | QString& string();
|
|---|
| 310 | void stringClear();
|
|---|
| 311 | void stringAddC();
|
|---|
| 312 | void stringAddC(const QChar&);
|
|---|
| 313 | QString& name();
|
|---|
| 314 | void nameClear();
|
|---|
| 315 | void nameAddC();
|
|---|
| 316 | void nameAddC(const QChar&);
|
|---|
| 317 | QString& ref();
|
|---|
| 318 | void refClear();
|
|---|
| 319 | void refAddC();
|
|---|
| 320 | void refAddC(const QChar&);
|
|---|
| 321 |
|
|---|
| 322 | // used by parseReference() and parsePEReference()
|
|---|
| 323 | enum EntityRecognitionContext { InContent, InAttributeValue, InEntityValue, InDTD };
|
|---|
| 324 |
|
|---|
| 325 | // private functions
|
|---|
| 326 | bool eat_ws();
|
|---|
| 327 | bool next_eat_ws();
|
|---|
| 328 |
|
|---|
| 329 | void next();
|
|---|
| 330 | bool atEnd();
|
|---|
| 331 |
|
|---|
| 332 | void init( const QXmlInputSource* i );
|
|---|
| 333 | void initData();
|
|---|
| 334 |
|
|---|
| 335 | bool entityExist( const QString& ) const;
|
|---|
| 336 |
|
|---|
| 337 | bool parseBeginOrContinue( int state, bool incremental );
|
|---|
| 338 |
|
|---|
| 339 | bool parseProlog();
|
|---|
| 340 | bool parseElement();
|
|---|
| 341 | bool processElementEmptyTag();
|
|---|
| 342 | bool processElementETagBegin2();
|
|---|
| 343 | bool processElementAttribute();
|
|---|
| 344 | bool parseMisc();
|
|---|
| 345 | bool parseContent();
|
|---|
| 346 |
|
|---|
| 347 | bool parsePI();
|
|---|
| 348 | bool parseDoctype();
|
|---|
| 349 | bool parseComment();
|
|---|
| 350 |
|
|---|
| 351 | bool parseName();
|
|---|
| 352 | bool parseNmtoken();
|
|---|
| 353 | bool parseAttribute();
|
|---|
| 354 | bool parseReference();
|
|---|
| 355 | bool processReference();
|
|---|
| 356 |
|
|---|
| 357 | bool parseExternalID();
|
|---|
| 358 | bool parsePEReference();
|
|---|
| 359 | bool parseMarkupdecl();
|
|---|
| 360 | bool parseAttlistDecl();
|
|---|
| 361 | bool parseAttType();
|
|---|
| 362 | bool parseAttValue();
|
|---|
| 363 | bool parseElementDecl();
|
|---|
| 364 | bool parseNotationDecl();
|
|---|
| 365 | bool parseChoiceSeq();
|
|---|
| 366 | bool parseEntityDecl();
|
|---|
| 367 | bool parseEntityValue();
|
|---|
| 368 |
|
|---|
| 369 | bool parseString();
|
|---|
| 370 |
|
|---|
| 371 | bool insertXmlRef( const QString&, const QString&, bool );
|
|---|
| 372 |
|
|---|
| 373 | bool reportEndEntities();
|
|---|
| 374 | void reportParseError( const QString& error );
|
|---|
| 375 |
|
|---|
| 376 | typedef bool (QXmlSimpleReader::*ParseFunction) ();
|
|---|
| 377 | void unexpectedEof( ParseFunction where, int state );
|
|---|
| 378 | void parseFailed( ParseFunction where, int state );
|
|---|
| 379 | void pushParseState( ParseFunction function, int state );
|
|---|
| 380 |
|
|---|
| 381 | friend class QXmlSimpleReaderPrivate;
|
|---|
| 382 | friend class QXmlSimpleReaderLocator;
|
|---|
| 383 | };
|
|---|
| 384 |
|
|---|
| 385 | //
|
|---|
| 386 | // SAX Locator
|
|---|
| 387 | //
|
|---|
| 388 |
|
|---|
| 389 | class QM_EXPORT_XML QXmlLocator
|
|---|
| 390 | {
|
|---|
| 391 | public:
|
|---|
| 392 | QXmlLocator();
|
|---|
| 393 | virtual ~QXmlLocator();
|
|---|
| 394 |
|
|---|
| 395 | virtual int columnNumber() = 0;
|
|---|
| 396 | virtual int lineNumber() = 0;
|
|---|
| 397 | // QString getPublicId()
|
|---|
| 398 | // QString getSystemId()
|
|---|
| 399 | };
|
|---|
| 400 |
|
|---|
| 401 | //
|
|---|
| 402 | // SAX handler classes
|
|---|
| 403 | //
|
|---|
| 404 |
|
|---|
| 405 | class QM_EXPORT_XML QXmlContentHandler
|
|---|
| 406 | {
|
|---|
| 407 | public:
|
|---|
| 408 | virtual void setDocumentLocator( QXmlLocator* locator ) = 0;
|
|---|
| 409 | virtual bool startDocument() = 0;
|
|---|
| 410 | virtual bool endDocument() = 0;
|
|---|
| 411 | virtual bool startPrefixMapping( const QString& prefix, const QString& uri ) = 0;
|
|---|
| 412 | virtual bool endPrefixMapping( const QString& prefix ) = 0;
|
|---|
| 413 | virtual bool startElement( const QString& namespaceURI, const QString& localName, const QString& qName, const QXmlAttributes& atts ) = 0;
|
|---|
| 414 | virtual bool endElement( const QString& namespaceURI, const QString& localName, const QString& qName ) = 0;
|
|---|
| 415 | virtual bool characters( const QString& ch ) = 0;
|
|---|
| 416 | virtual bool ignorableWhitespace( const QString& ch ) = 0;
|
|---|
| 417 | virtual bool processingInstruction( const QString& target, const QString& data ) = 0;
|
|---|
| 418 | virtual bool skippedEntity( const QString& name ) = 0;
|
|---|
| 419 | virtual QString errorString() = 0;
|
|---|
| 420 | };
|
|---|
| 421 |
|
|---|
| 422 | class QM_EXPORT_XML QXmlErrorHandler
|
|---|
| 423 | {
|
|---|
| 424 | public:
|
|---|
| 425 | virtual bool warning( const QXmlParseException& exception ) = 0;
|
|---|
| 426 | virtual bool error( const QXmlParseException& exception ) = 0;
|
|---|
| 427 | virtual bool fatalError( const QXmlParseException& exception ) = 0;
|
|---|
| 428 | virtual QString errorString() = 0;
|
|---|
| 429 | };
|
|---|
| 430 |
|
|---|
| 431 | class QM_EXPORT_XML QXmlDTDHandler
|
|---|
| 432 | {
|
|---|
| 433 | public:
|
|---|
| 434 | virtual bool notationDecl( const QString& name, const QString& publicId, const QString& systemId ) = 0;
|
|---|
| 435 | virtual bool unparsedEntityDecl( const QString& name, const QString& publicId, const QString& systemId, const QString& notationName ) = 0;
|
|---|
| 436 | virtual QString errorString() = 0;
|
|---|
| 437 | };
|
|---|
| 438 |
|
|---|
| 439 | class QM_EXPORT_XML QXmlEntityResolver
|
|---|
| 440 | {
|
|---|
| 441 | public:
|
|---|
| 442 | virtual bool resolveEntity( const QString& publicId, const QString& systemId, QXmlInputSource*& ret ) = 0;
|
|---|
| 443 | virtual QString errorString() = 0;
|
|---|
| 444 | };
|
|---|
| 445 |
|
|---|
| 446 | class QM_EXPORT_XML QXmlLexicalHandler
|
|---|
| 447 | {
|
|---|
| 448 | public:
|
|---|
| 449 | virtual bool startDTD( const QString& name, const QString& publicId, const QString& systemId ) = 0;
|
|---|
| 450 | virtual bool endDTD() = 0;
|
|---|
| 451 | virtual bool startEntity( const QString& name ) = 0;
|
|---|
| 452 | virtual bool endEntity( const QString& name ) = 0;
|
|---|
| 453 | virtual bool startCDATA() = 0;
|
|---|
| 454 | virtual bool endCDATA() = 0;
|
|---|
| 455 | virtual bool comment( const QString& ch ) = 0;
|
|---|
| 456 | virtual QString errorString() = 0;
|
|---|
| 457 | };
|
|---|
| 458 |
|
|---|
| 459 | class QM_EXPORT_XML QXmlDeclHandler
|
|---|
| 460 | {
|
|---|
| 461 | public:
|
|---|
| 462 | virtual bool attributeDecl( const QString& eName, const QString& aName, const QString& type, const QString& valueDefault, const QString& value ) = 0;
|
|---|
| 463 | virtual bool internalEntityDecl( const QString& name, const QString& value ) = 0;
|
|---|
| 464 | virtual bool externalEntityDecl( const QString& name, const QString& publicId, const QString& systemId ) = 0;
|
|---|
| 465 | virtual QString errorString() = 0;
|
|---|
| 466 | };
|
|---|
| 467 |
|
|---|
| 468 |
|
|---|
| 469 | class QM_EXPORT_XML QXmlDefaultHandler : public QXmlContentHandler, public QXmlErrorHandler, public QXmlDTDHandler, public QXmlEntityResolver, public QXmlLexicalHandler, public QXmlDeclHandler
|
|---|
| 470 | {
|
|---|
| 471 | public:
|
|---|
| 472 | QXmlDefaultHandler() { }
|
|---|
| 473 | virtual ~QXmlDefaultHandler() { }
|
|---|
| 474 |
|
|---|
| 475 | void setDocumentLocator( QXmlLocator* locator );
|
|---|
| 476 | bool startDocument();
|
|---|
| 477 | bool endDocument();
|
|---|
| 478 | bool startPrefixMapping( const QString& prefix, const QString& uri );
|
|---|
| 479 | bool endPrefixMapping( const QString& prefix );
|
|---|
| 480 | bool startElement( const QString& namespaceURI, const QString& localName, const QString& qName, const QXmlAttributes& atts );
|
|---|
| 481 | bool endElement( const QString& namespaceURI, const QString& localName, const QString& qName );
|
|---|
| 482 | bool characters( const QString& ch );
|
|---|
| 483 | bool ignorableWhitespace( const QString& ch );
|
|---|
| 484 | bool processingInstruction( const QString& target, const QString& data );
|
|---|
| 485 | bool skippedEntity( const QString& name );
|
|---|
| 486 |
|
|---|
| 487 | bool warning( const QXmlParseException& exception );
|
|---|
| 488 | bool error( const QXmlParseException& exception );
|
|---|
| 489 | bool fatalError( const QXmlParseException& exception );
|
|---|
| 490 |
|
|---|
| 491 | bool notationDecl( const QString& name, const QString& publicId, const QString& systemId );
|
|---|
| 492 | bool unparsedEntityDecl( const QString& name, const QString& publicId, const QString& systemId, const QString& notationName );
|
|---|
| 493 |
|
|---|
| 494 | bool resolveEntity( const QString& publicId, const QString& systemId, QXmlInputSource*& ret );
|
|---|
| 495 |
|
|---|
| 496 | bool startDTD( const QString& name, const QString& publicId, const QString& systemId );
|
|---|
| 497 | bool endDTD();
|
|---|
| 498 | bool startEntity( const QString& name );
|
|---|
| 499 | bool endEntity( const QString& name );
|
|---|
| 500 | bool startCDATA();
|
|---|
| 501 | bool endCDATA();
|
|---|
| 502 | bool comment( const QString& ch );
|
|---|
| 503 |
|
|---|
| 504 | bool attributeDecl( const QString& eName, const QString& aName, const QString& type, const QString& valueDefault, const QString& value );
|
|---|
| 505 | bool internalEntityDecl( const QString& name, const QString& value );
|
|---|
| 506 | bool externalEntityDecl( const QString& name, const QString& publicId, const QString& systemId );
|
|---|
| 507 |
|
|---|
| 508 | QString errorString();
|
|---|
| 509 |
|
|---|
| 510 | private:
|
|---|
| 511 | QXmlDefaultHandlerPrivate *d;
|
|---|
| 512 | };
|
|---|
| 513 |
|
|---|
| 514 |
|
|---|
| 515 | //
|
|---|
| 516 | // inlines
|
|---|
| 517 | //
|
|---|
| 518 |
|
|---|
| 519 | inline bool QXmlSimpleReader::is_S(const QChar& ch)
|
|---|
| 520 | {
|
|---|
| 521 | return ch==' ' || ch=='\t' || ch=='\n' || ch=='\r';
|
|---|
| 522 | }
|
|---|
| 523 | inline bool QXmlSimpleReader::is_NameBeginning( const QChar& ch )
|
|---|
| 524 | {
|
|---|
| 525 | return ch=='_' || ch==':' ||
|
|---|
| 526 | ch.isLetter() || // ### Category Lm is not allowed
|
|---|
| 527 | ch.category()==QChar::Number_Letter;
|
|---|
| 528 | }
|
|---|
| 529 | inline bool QXmlSimpleReader::is_NameChar( const QChar& ch )
|
|---|
| 530 | {
|
|---|
| 531 | return ch=='.' || ch=='-' || ch=='_' || ch==':' ||
|
|---|
| 532 | ch.isLetterOrNumber() || // ### Category No is not allowed
|
|---|
| 533 | ch.isMark();
|
|---|
| 534 | }
|
|---|
| 535 |
|
|---|
| 536 | inline bool QXmlSimpleReader::atEnd()
|
|---|
| 537 | { return (c.unicode()|0x0001) == 0xffff; }
|
|---|
| 538 |
|
|---|
| 539 | inline void QXmlSimpleReader::stringClear()
|
|---|
| 540 | { stringValue = QString::null; stringPos = 0; }
|
|---|
| 541 | inline void QXmlSimpleReader::nameClear()
|
|---|
| 542 | { nameValue = QString::null; namePos = 0; }
|
|---|
| 543 | inline void QXmlSimpleReader::refClear()
|
|---|
| 544 | { refValue = QString::null; refPos = 0; }
|
|---|
| 545 |
|
|---|
| 546 | inline int QXmlAttributes::count() const
|
|---|
| 547 | { return length(); }
|
|---|
| 548 |
|
|---|
| 549 | #endif //QT_NO_XML
|
|---|
| 550 |
|
|---|
| 551 | #endif
|
|---|