Changeset 561 for trunk/src/corelib/xml/qxmlstream.cpp
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/src/corelib/xml/qxmlstream.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information ([email protected]) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation ([email protected]) 5 6 ** 6 7 ** This file is part of the QtCore module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you 37 ** @nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 53 53 #include "qxmlutils_p.h" 54 54 #include <qdebug.h> 55 #include < QFile>55 #include <> 56 56 #include <stdio.h> 57 57 #include <qtextcodec.h> … … 59 59 #include <qbuffer.h> 60 60 #ifndef QT_BOOTSTRAPPED 61 #include < QCoreApplication>61 #include <> 62 62 #else 63 63 // This specialization of Q_DECLARE_TR_FUNCTIONS is not in qcoreapplication.h, … … 130 130 131 131 /*! 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 132 147 \enum QXmlStreamReader::Error 133 148 … … 245 260 well-formed XML via a simple streaming API. 246 261 247 \mainclass 262 248 263 \ingroup xml-tools 249 264 … … 299 314 300 315 The \l{QXmlStream Bookmarks Example} illustrates how to use the 301 recursive descent technique with a subclassed stream reader to read302 a n XML bookmark file (XBEL).316 recursive descent technique 317 a. 303 318 304 319 \section1 Namespaces … … 335 350 new data with the next call to readNext(). 336 351 337 For example, if you read data from the network using QHttp, you 338 would connect its \l{QHttp::readyRead()}{readyRead()} signal to a 339 custom slot. In this slot, you read all available data with 340 \l{QHttp::readAll()}{readAll()} and pass it to the XML stream reader 341 using addData(). Then you call your custom parsing function that 342 reads the XML events from the reader. 352 For example, if your application reads data from the network using a 353 \l{QNetworkAccessManager} {network access manager}, you would issue 354 a \l{QNetworkRequest} {network request} to the manager and receive a 355 \l{QNetworkReply} {network reply} in return. Since a QNetworkReply 356 is a QIODevice, you connect its \l{QNetworkReply::readyRead()} 357 {readyRead()} signal to a custom slot, e.g. \c{slotReadyRead()} in 358 the code snippet shown in the discussion for QNetworkAccessManager. 359 In this slot, you read all available data with 360 \l{QNetworkReply::readAll()} {readAll()} and pass it to the XML 361 stream reader using addData(). Then you call your custom parsing 362 function that reads the XML events from the reader. 343 363 344 364 \section1 Performance and memory consumption … … 430 450 if (d->deleteDevice) 431 451 delete d->device; 432 delete d;433 452 } 434 453 … … 569 588 QXmlStreamReader::Invalid. 570 589 571 The exception is when error() return PrematureEndOfDocumentError.590 The exception is when error() return PrematureEndOfDocumentError. 572 591 This error is reported when the end of an otherwise well-formed 573 592 chunk of XML is reached, but the chunk doesn't represent a complete … … 618 637 } 619 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 620 689 /* 621 690 * Use the following Perl script to generate the error string index list: … … 630 699 $counter += length 1 + $_; 631 700 } 632 print " \"\\0\";\n\nstatic const int QXmlStreamReader_tokenTypeString_indices[] = {\n ";701 print " \"\\0\";\n\nstatic const t QXmlStreamReader_tokenTypeString_indices[] = {\n "; 633 702 for ($j = 0; $j < $i; ++$j) { 634 703 printf "$sizes[$j], "; … … 661 730 "DTD\0" 662 731 "EntityReference\0" 663 "ProcessingInstruction\0" 664 "\0"; 665 666 static const int QXmlStreamReader_tokenTypeString_indices[] = { 732 "ProcessingInstruction\0"; 733 734 static const short QXmlStreamReader_tokenTypeString_indices[] = { 667 735 0, 8, 16, 30, 42, 55, 66, 77, 85, 89, 105, 0 668 736 }; … … 820 888 stack_size <<= 1; 821 889 sym_stack = reinterpret_cast<Value*> (qRealloc(sym_stack, stack_size * sizeof(Value))); 890 822 891 state_stack = reinterpret_cast<int*> (qRealloc(state_stack, stack_size * sizeof(int))); 892 823 893 } 824 894 … … 2018 2088 The function concatenates text() when it reads either \l Characters 2019 2089 or EntityReference tokens, but skips ProcessingInstruction and \l 2020 Comment. In case anything else is read before reaching EndElement, 2021 the function returns what it read so far and raises an 2022 UnexpectedElementError. If the current token is not StartElement, an 2023 empty string is returned. 2024 */ 2025 QString QXmlStreamReader::readElementText() 2090 Comment. If the current token is not StartElement, an empty string is 2091 returned. 2092 2093 The \a behaviour defines what happens in case anything else is 2094 read before reaching EndElement. The function can include the text from 2095 child elements (useful for example for HTML), ignore child elements, or 2096 raise an UnexpectedElementError and return what was read so far. 2097 2098 \since 4.6 2099 */ 2100 QString QXmlStreamReader::readElementText(ReadElementTextBehaviour behaviour) 2026 2101 { 2027 2102 Q_D(QXmlStreamReader); … … 2039 2114 case Comment: 2040 2115 break; 2116 2117 2118 2119 2120 2121 2122 2123 2124 2041 2125 default: 2042 if (!d->error) 2043 d->raiseError(UnexpectedElementError, QXmlStream::tr("Expected character data.")); 2044 return result; 2126 if (d->error || behaviour == ErrorOnUnexpectedElement) { 2127 if (!d->error) 2128 d->raiseError(UnexpectedElementError, QXmlStream::tr("Expected character data.")); 2129 return result; 2130 } 2045 2131 } 2046 2132 } 2047 2133 } 2048 2134 return QString(); 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2049 2145 } 2050 2146 … … 2789 2885 simple streaming API. 2790 2886 2791 \mainclass2792 \inmodule QtXml2793 2887 \ingroup xml-tools 2794 2888 … … 2849 2943 2850 2944 The \l{QXmlStream Bookmarks Example} illustrates how to use a 2851 s ubclassed stream writer to write an XML bookmark file (XBEL) that2945 stream writer to write an XML bookmark file (XBEL) that 2852 2946 was previously read in by a QXmlStreamReader. 2853 2947 … … 3059 3153 int n = ++namespacePrefixCount; 3060 3154 forever { 3061 s = QLatin1 String("n") + QString::number(n++);3155 s = QLatin1) + QString::number(n++); 3062 3156 int j = namespaceDeclarations.size() - 2; 3063 3157 while (j >= 0 && namespaceDeclarations.at(j).prefix != s) … … 3132 3226 QXmlStreamWriter::~QXmlStreamWriter() 3133 3227 { 3134 Q_D(QXmlStreamWriter);3135 delete d;3136 3228 } 3137 3229 … … 3412 3504 Q_D(QXmlStreamWriter); 3413 3505 Q_ASSERT(!text.contains(QLatin1String("--")) && !text.endsWith(QLatin1Char('-'))); 3414 if (!d->finishStartElement( ) && d->autoFormatting)3506 if (!d->finishStartElement() && d->autoFormatting) 3415 3507 d->indent(d->tagStack.size()); 3416 3508 d->write("<!--"); 3417 3509 d->write(text); 3418 3510 d->write("-->"); 3511 3419 3512 } 3420 3513
Note:
See TracChangeset
for help on using the changeset viewer.