Qt 4.8
qxmlstream.cpp
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 QtCore 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 #include "QtCore/qxmlstream.h"
43 
44 #if defined(QT_BUILD_XML_LIB) && defined(Q_OS_MAC64)
45 // No need to define this in the 64-bit Mac libraries.
46 // Since Qt 4.4 and previous weren't supported in 64-bit, there are
47 // no QXmlStream* symbols to keep compatibility with
48 # define QT_NO_XMLSTREAM
49 #endif
50 
51 #ifndef QT_NO_XMLSTREAM
52 
53 #include "qxmlutils_p.h"
54 #include <qdebug.h>
55 #include <qfile.h>
56 #include <stdio.h>
57 #include <qtextcodec.h>
58 #include <qstack.h>
59 #include <qbuffer.h>
60 #ifndef QT_BOOTSTRAPPED
61 #include <qcoreapplication.h>
62 #else
63 // This specialization of Q_DECLARE_TR_FUNCTIONS is not in qcoreapplication.h,
64 // because that header depends on QObject being available, which is not the
65 // case for most bootstrapped applications.
66 #define Q_DECLARE_TR_FUNCTIONS(context) \
67 public: \
68  static inline QString tr(const char *sourceText, const char *comment = 0) \
69  { Q_UNUSED(comment); return QString::fromLatin1(sourceText); } \
70  static inline QString trUtf8(const char *sourceText, const char *comment = 0) \
71  { Q_UNUSED(comment); return QString::fromLatin1(sourceText); } \
72  static inline QString tr(const char *sourceText, const char*, int) \
73  { return QString::fromLatin1(sourceText); } \
74  static inline QString trUtf8(const char *sourceText, const char*, int) \
75  { return QString::fromLatin1(sourceText); } \
76 private:
77 #endif
79 
80 #include "qxmlstream_p.h"
81 
196 {
197 }
198 
203 QString QXmlStreamEntityResolver::resolveEntity(const QString& /*publicId*/, const QString& /*systemId*/)
204 {
205  return QString();
206 }
207 
208 
218 {
219  return QString();
220 }
221 
222 #ifndef QT_NO_XMLSTREAMREADER
223 
225 {
226  if (entityResolver)
227  return entityResolver->resolveUndeclaredEntity(name);
228  return QString();
229 }
230 
231 
232 
249 {
251  d->entityResolver = resolver;
252 }
253 
265 {
266  Q_D(const QXmlStreamReader);
267  return d->entityResolver;
268 }
269 
270 
271 
407  : d_ptr(new QXmlStreamReaderPrivate(this))
408 {
409 }
410 
416  : d_ptr(new QXmlStreamReaderPrivate(this))
417 {
418  setDevice(device);
419 }
420 
427  : d_ptr(new QXmlStreamReaderPrivate(this))
428 {
430  d->dataBuffer = data;
431 }
432 
439  : d_ptr(new QXmlStreamReaderPrivate(this))
440 {
442 #ifdef QT_NO_TEXTCODEC
443  d->dataBuffer = data.toLatin1();
444 #else
445  d->dataBuffer = d->codec->fromUnicode(data);
446  d->decoder = d->codec->makeDecoder();
447 #endif
448  d->lockEncoding = true;
449 
450 }
451 
458  : d_ptr(new QXmlStreamReaderPrivate(this))
459 {
461  d->dataBuffer = QByteArray(data);
462 }
463 
468 {
470  if (d->deleteDevice)
471  delete d->device;
472 }
473 
490 {
492  if (d->deleteDevice) {
493  delete d->device;
494  d->deleteDevice = false;
495  }
496  d->device = device;
497  d->init();
498 
499 }
500 
508 {
509  Q_D(const QXmlStreamReader);
510  return d->device;
511 }
512 
513 
521 {
523  if (d->device) {
524  qWarning("QXmlStreamReader: addData() with device()");
525  return;
526  }
527  d->dataBuffer += data;
528 }
529 
537 {
539  d->lockEncoding = true;
540 #ifdef QT_NO_TEXTCODEC
541  addData(data.toLatin1());
542 #else
543  addData(d->codec->fromUnicode(data));
544 #endif
545 }
546 
554 {
555  addData(QByteArray(data));
556 }
557 
565 {
567  d->init();
568  if (d->device) {
569  if (d->deleteDevice)
570  delete d->device;
571  d->device = 0;
572  }
573 }
574 
591 {
592  Q_D(const QXmlStreamReader);
593  if (d->atEnd
594  && ((d->type == QXmlStreamReader::Invalid && d->error == PrematureEndOfDocumentError)
595  || (d->type == QXmlStreamReader::EndDocument))) {
596  if (d->device)
597  return d->device->atEnd();
598  else
599  return !d->dataBuffer.size();
600  }
601  return (d->atEnd || d->type == QXmlStreamReader::Invalid);
602 }
603 
604 
624 {
626  if (d->type != Invalid) {
627  if (!d->hasCheckedStartDocument)
628  if (!d->checkStartDocument())
629  return d->type; // synthetic StartDocument or error
630  d->parse();
631  if (d->atEnd && d->type != EndDocument && d->type != Invalid)
632  d->raiseError(PrematureEndOfDocumentError);
633  else if (!d->atEnd && d->type == EndDocument)
634  d->raiseWellFormedError(QXmlStream::tr("Extra content at end of document."));
635  } else if (d->error == PrematureEndOfDocumentError) {
636  // resume error
637  d->type = NoToken;
638  d->atEnd = false;
639  d->token = -1;
640  return readNext();
641  }
642  return d->type;
643 }
644 
645 
657 {
658  Q_D(const QXmlStreamReader);
659  return d->type;
660 }
661 
685 {
686  while (readNext() != Invalid) {
687  if (isEndElement())
688  return false;
689  else if (isStartElement())
690  return true;
691  }
692  return false;
693 }
694 
707 {
708  int depth = 1;
709  while (depth && readNext() != Invalid) {
710  if (isEndElement())
711  --depth;
712  else if (isStartElement())
713  ++depth;
714  }
715 }
716 
717 /*
718  * Use the following Perl script to generate the error string index list:
719 ===== PERL SCRIPT ====
720 print "static const char QXmlStreamReader_tokenTypeString_string[] =\n";
721 $counter = 0;
722 $i = 0;
723 while (<STDIN>) {
724  chomp;
725  print " \"$_\\0\"\n";
726  $sizes[$i++] = $counter;
727  $counter += length 1 + $_;
728 }
729 print " \"\\0\";\n\nstatic const short QXmlStreamReader_tokenTypeString_indices[] = {\n ";
730 for ($j = 0; $j < $i; ++$j) {
731  printf "$sizes[$j], ";
732 }
733 print "0\n};\n";
734 ===== PERL SCRIPT ====
735 
736  * The input data is as follows (copied from qxmlstream.h):
737 NoToken
738 Invalid
739 StartDocument
740 EndDocument
741 StartElement
742 EndElement
743 Characters
744 Comment
745 DTD
746 EntityReference
747 ProcessingInstruction
748 */
750  "NoToken\0"
751  "Invalid\0"
752  "StartDocument\0"
753  "EndDocument\0"
754  "StartElement\0"
755  "EndElement\0"
756  "Characters\0"
757  "Comment\0"
758  "DTD\0"
759  "EntityReference\0"
760  "ProcessingInstruction\0";
761 
763  0, 8, 16, 30, 42, 55, 66, 77, 85, 89, 105, 0
764 };
765 
766 
783 {
785  d->namespaceProcessing = enable;
786 }
787 
789 {
790  Q_D(const QXmlStreamReader);
791  return d->namespaceProcessing;
792 }
793 
799 {
800  Q_D(const QXmlStreamReader);
803 }
804 
805 #endif // QT_NO_XMLSTREAMREADER
806 
808 {
809  tagStack.reserve(16);
810  tagStackStringStorage.reserve(32);
811  tagStackStringStorageSize = 0;
812  NamespaceDeclaration &namespaceDeclaration = namespaceDeclarations.push();
813  namespaceDeclaration.prefix = addToStringStorage(QLatin1String("xml"));
814  namespaceDeclaration.namespaceUri = addToStringStorage(QLatin1String("http://www.w3.org/XML/1998/namespace"));
815 }
816 
817 #ifndef QT_NO_XMLSTREAMREADER
818 
820  :q_ptr(q)
821 {
822  device = 0;
823  deleteDevice = false;
824 #ifndef QT_NO_TEXTCODEC
825  decoder = 0;
826 #endif
827  stack_size = 64;
828  sym_stack = 0;
829  state_stack = 0;
830  reallocateStack();
831  entityResolver = 0;
832  init();
838 }
839 
841 {
842  tos = 0;
843  scanDtd = false;
844  token = -1;
845  token_char = 0;
846  isEmptyElement = false;
847  isWhitespace = true;
848  isCDATA = false;
849  standalone = false;
850  tos = 0;
851  resumeReduction = 0;
852  state_stack[tos++] = 0;
853  state_stack[tos] = 0;
854  putStack.clear();
855  putStack.reserve(32);
856  textBuffer.clear();
857  textBuffer.reserve(256);
858  tagStack.clear();
859  tagsDone = false;
860  attributes.clear();
861  attributes.reserve(16);
863  readBufferPos = 0;
864  nbytesread = 0;
865 #ifndef QT_NO_TEXTCODEC
866  codec = QTextCodec::codecForMib(106); // utf8
867  delete decoder;
868  decoder = 0;
869 #endif
870  attributeStack.clear();
871  attributeStack.reserve(16);
872  entityParser = 0;
873  hasCheckedStartDocument = false;
874  normalizeLiterals = false;
875  hasSeenTag = false;
876  atEnd = false;
877  inParseEntity = false;
880  hasExternalDtdSubset = false;
881  lockEncoding = false;
882  namespaceProcessing = true;
884  dataBuffer.clear();
885  readBuffer.clear();
886 
889 }
890 
891 /*
892  Well-formed requires that we verify entity values. We do this with a
893  standard parser.
894  */
896 {
898 
899  if (value.isEmpty())
900  return;
901 
902 
903  if (!entityParser)
905  else
906  entityParser->init();
907  entityParser->inParseEntity = true;
908  entityParser->readBuffer = value;
911  entityParser->parse();
913  raiseWellFormedError(QXmlStream::tr("Invalid entity value."));
914 
915 }
916 
918 {
919  stack_size <<= 1;
920  sym_stack = reinterpret_cast<Value*> (qRealloc(sym_stack, stack_size * sizeof(Value)));
922  state_stack = reinterpret_cast<int*> (qRealloc(state_stack, stack_size * sizeof(int)));
924 }
925 
926 
928 {
929 #ifndef QT_NO_TEXTCODEC
930  delete decoder;
931 #endif
932  qFree(sym_stack);
934  delete entityParser;
935 }
936 
937 
939 {
940  uint peekc = peekChar();
941  if (peekc == '\n') {
942  if (putStack.size())
943  putStack.pop();
944  else
945  ++readBufferPos;
946  return peekc;
947  }
948  if (peekc == 0) {
949  putChar('\r');
950  return 0;
951  }
952  return '\n';
953 }
954 
960 {
961  uint c;
962  if (putStack.size()) {
963  c = atEnd ? 0 : putStack.pop();
964  } else {
965  if (readBufferPos < readBuffer.size())
967  else
968  c = getChar_helper();
969  }
970 
971  return c;
972 }
973 
975 {
976  uint c;
977  if (putStack.size()) {
978  c = putStack.top();
979  } else if (readBufferPos < readBuffer.size()) {
981  } else {
982  if ((c = getChar_helper()))
983  --readBufferPos;
984  }
985 
986  return c;
987 }
988 
1004 bool QXmlStreamReaderPrivate::scanUntil(const char *str, short tokenToInject)
1005 {
1006  int pos = textBuffer.size();
1007  int oldLineNumber = lineNumber;
1008 
1009  while (uint c = getChar()) {
1010  /* First, we do the validation & normalization. */
1011  switch (c) {
1012  case '\r':
1013  if ((c = filterCarriageReturn()) == 0)
1014  break;
1015  // fall through
1016  case '\n':
1017  ++lineNumber;
1019  // fall through
1020  case '\t':
1021  textBuffer += QChar(c);
1022  continue;
1023  default:
1024  if(c < 0x20 || (c > 0xFFFD && c < 0x10000) || c > 0x10FFFF ) {
1025  raiseWellFormedError(QXmlStream::tr("Invalid XML character."));
1026  lineNumber = oldLineNumber;
1027  return false;
1028  }
1029  textBuffer += QChar(c);
1030  }
1031 
1032 
1033  /* Second, attempt to lookup str. */
1034  if (c == uint(*str)) {
1035  if (!*(str + 1)) {
1036  if (tokenToInject >= 0)
1037  injectToken(tokenToInject);
1038  return true;
1039  } else {
1040  if (scanString(str + 1, tokenToInject, false))
1041  return true;
1042  }
1043  }
1044  }
1045  putString(textBuffer, pos);
1046  textBuffer.resize(pos);
1047  lineNumber = oldLineNumber;
1048  return false;
1049 }
1050 
1051 bool QXmlStreamReaderPrivate::scanString(const char *str, short tokenToInject, bool requireSpace)
1052 {
1053  int n = 0;
1054  while (str[n]) {
1055  ushort c = getChar();
1056  if (c != ushort(str[n])) {
1057  if (c)
1058  putChar(c);
1059  while (n--) {
1060  putChar(ushort(str[n]));
1061  }
1062  return false;
1063  }
1064  ++n;
1065  }
1066  for (int i = 0; i < n; ++i)
1067  textBuffer += QChar(ushort(str[i]));
1068  if (requireSpace) {
1069  int s = fastScanSpace();
1070  if (!s || atEnd) {
1071  int pos = textBuffer.size() - n - s;
1072  putString(textBuffer, pos);
1073  textBuffer.resize(pos);
1074  return false;
1075  }
1076  }
1077  if (tokenToInject >= 0)
1078  injectToken(tokenToInject);
1079  return true;
1080 }
1081 
1083 {
1084  switch (peekChar()) {
1085  case '[':
1086  return scanString(spell[CDATA_START], CDATA_START, false);
1087  case 'D':
1088  return scanString(spell[DOCTYPE], DOCTYPE);
1089  case 'A':
1090  return scanString(spell[ATTLIST], ATTLIST);
1091  case 'N':
1092  return scanString(spell[NOTATION], NOTATION);
1093  case 'E':
1094  if (scanString(spell[ELEMENT], ELEMENT))
1095  return true;
1096  return scanString(spell[ENTITY], ENTITY);
1097 
1098  default:
1099  ;
1100  };
1101  return false;
1102 }
1103 
1105 {
1106  switch (peekChar()) {
1107  case 'S':
1108  return scanString(spell[SYSTEM], SYSTEM);
1109  case 'P':
1110  return scanString(spell[PUBLIC], PUBLIC);
1111  default:
1112  ;
1113  }
1114  return false;
1115 }
1116 
1118 {
1119  if (fastScanSpace()) {
1120  if (scanString(spell[NDATA], NDATA))
1121  return true;
1122  putChar(' ');
1123  }
1124  return false;
1125 }
1126 
1128 {
1129  switch (peekChar()) {
1130  case 'R':
1131  return scanString(spell[REQUIRED], REQUIRED, false);
1132  case 'I':
1133  return scanString(spell[IMPLIED], IMPLIED, false);
1134  case 'F':
1135  return scanString(spell[FIXED], FIXED, false);
1136  default:
1137  ;
1138  }
1139  return false;
1140 }
1141 
1143 {
1144  switch (peekChar()) {
1145  case 'C':
1146  return scanString(spell[CDATA], CDATA);
1147  case 'I':
1148  if (scanString(spell[ID], ID))
1149  return true;
1150  if (scanString(spell[IDREF], IDREF))
1151  return true;
1152  return scanString(spell[IDREFS], IDREFS);
1153  case 'E':
1154  if (scanString(spell[ENTITY], ENTITY))
1155  return true;
1156  return scanString(spell[ENTITIES], ENTITIES);
1157  case 'N':
1158  if (scanString(spell[NOTATION], NOTATION))
1159  return true;
1160  if (scanString(spell[NMTOKEN], NMTOKEN))
1161  return true;
1162  return scanString(spell[NMTOKENS], NMTOKENS);
1163  default:
1164  ;
1165  }
1166  return false;
1167 }
1168 
1182 {
1183  int n = 0;
1184  uint c;
1185  while ((c = getChar())) {
1186  switch (ushort(c)) {
1187  case 0xfffe:
1188  case 0xffff:
1189  case 0:
1190  /* The putChar() call is necessary so the parser re-gets
1191  * the character from the input source, when raising an error. */
1192  putChar(c);
1193  return n;
1194  case '\r':
1195  if (filterCarriageReturn() == 0)
1196  return n;
1197  // fall through
1198  case '\n':
1199  ++lineNumber;
1201  // fall through
1202  case ' ':
1203  case '\t':
1204  if (normalizeLiterals)
1205  textBuffer += QLatin1Char(' ');
1206  else
1207  textBuffer += QChar(c);
1208  ++n;
1209  break;
1210  case '&':
1211  case '<':
1212  case '\"':
1213  case '\'':
1214  if (!(c & 0xff0000)) {
1215  putChar(c);
1216  return n;
1217  }
1218  // fall through
1219  default:
1220  textBuffer += QChar(c);
1221  ++n;
1222  }
1223  }
1224  return n;
1225 }
1226 
1228 {
1229  int n = 0;
1230  ushort c;
1231  while ((c = getChar())) {
1232  switch (c) {
1233  case '\r':
1234  if ((c = filterCarriageReturn()) == 0)
1235  return n;
1236  // fall through
1237  case '\n':
1238  ++lineNumber;
1240  // fall through
1241  case ' ':
1242  case '\t':
1243  textBuffer += QChar(c);
1244  ++n;
1245  break;
1246  default:
1247  putChar(c);
1248  return n;
1249  }
1250  }
1251  return n;
1252 }
1253 
1264 {
1265  int n = 0;
1266  uint c;
1267  while ((c = getChar())) {
1268  switch (ushort(c)) {
1269  case 0xfffe:
1270  case 0xffff:
1271  case 0:
1272  putChar(c);
1273  return n;
1274  case ']': {
1275  isWhitespace = false;
1276  int pos = textBuffer.size();
1277  textBuffer += QChar(ushort(c));
1278  ++n;
1279  while ((c = getChar()) == ']') {
1280  textBuffer += QChar(ushort(c));
1281  ++n;
1282  }
1283  if (c == 0) {
1284  putString(textBuffer, pos);
1285  textBuffer.resize(pos);
1286  } else if (c == '>' && textBuffer.at(textBuffer.size()-2) == QLatin1Char(']')) {
1287  raiseWellFormedError(QXmlStream::tr("Sequence ']]>' not allowed in content."));
1288  } else {
1289  putChar(c);
1290  break;
1291  }
1292  return n;
1293  } break;
1294  case '\r':
1295  if ((c = filterCarriageReturn()) == 0)
1296  return n;
1297  // fall through
1298  case '\n':
1299  ++lineNumber;
1301  // fall through
1302  case ' ':
1303  case '\t':
1304  textBuffer += QChar(ushort(c));
1305  ++n;
1306  break;
1307  case '&':
1308  case '<':
1309  if (!(c & 0xff0000)) {
1310  putChar(c);
1311  return n;
1312  }
1313  // fall through
1314  default:
1315  if (c < 0x20) {
1316  putChar(c);
1317  return n;
1318  }
1319  isWhitespace = false;
1320  textBuffer += QChar(ushort(c));
1321  ++n;
1322  }
1323  }
1324  return n;
1325 }
1326 
1328 {
1329  int n = 0;
1330  ushort c;
1331  while ((c = getChar())) {
1332  switch (c) {
1333  case '\n':
1334  case ' ':
1335  case '\t':
1336  case '\r':
1337  case '&':
1338  case '#':
1339  case '\'':
1340  case '\"':
1341  case '<':
1342  case '>':
1343  case '[':
1344  case ']':
1345  case '=':
1346  case '%':
1347  case '/':
1348  case ';':
1349  case '?':
1350  case '!':
1351  case '^':
1352  case '|':
1353  case ',':
1354  case '(':
1355  case ')':
1356  case '+':
1357  case '*':
1358  putChar(c);
1359  if (prefix && *prefix == n+1) {
1360  *prefix = 0;
1361  putChar(':');
1362  --n;
1363  }
1364  return n;
1365  case ':':
1366  if (prefix) {
1367  if (*prefix == 0) {
1368  *prefix = n+2;
1369  } else { // only one colon allowed according to the namespace spec.
1370  putChar(c);
1371  return n;
1372  }
1373  } else {
1374  putChar(c);
1375  return n;
1376  }
1377  // fall through
1378  default:
1379  textBuffer += QChar(c);
1380  ++n;
1381  }
1382  }
1383 
1384  if (prefix)
1385  *prefix = 0;
1386  int pos = textBuffer.size() - n;
1387  putString(textBuffer, pos);
1388  textBuffer.resize(pos);
1389  return 0;
1390 }
1391 
1393 
1394 static const char Begi = static_cast<char>(NameBeginning);
1395 static const char NtBg = static_cast<char>(NameNotBeginning);
1396 static const char NotN = static_cast<char>(NotName);
1397 
1398 static const char nameCharTable[128] =
1399 {
1400 // 0x00
1401  NotN, NotN, NotN, NotN, NotN, NotN, NotN, NotN,
1402  NotN, NotN, NotN, NotN, NotN, NotN, NotN, NotN,
1403 // 0x10
1404  NotN, NotN, NotN, NotN, NotN, NotN, NotN, NotN,
1405  NotN, NotN, NotN, NotN, NotN, NotN, NotN, NotN,
1406 // 0x20 (0x2D is '-', 0x2E is '.')
1407  NotN, NotN, NotN, NotN, NotN, NotN, NotN, NotN,
1408  NotN, NotN, NotN, NotN, NotN, NtBg, NtBg, NotN,
1409 // 0x30 (0x30..0x39 are '0'..'9', 0x3A is ':')
1410  NtBg, NtBg, NtBg, NtBg, NtBg, NtBg, NtBg, NtBg,
1411  NtBg, NtBg, Begi, NotN, NotN, NotN, NotN, NotN,
1412 // 0x40 (0x41..0x5A are 'A'..'Z')
1413  NotN, Begi, Begi, Begi, Begi, Begi, Begi, Begi,
1414  Begi, Begi, Begi, Begi, Begi, Begi, Begi, Begi,
1415 // 0x50 (0x5F is '_')
1416  Begi, Begi, Begi, Begi, Begi, Begi, Begi, Begi,
1417  Begi, Begi, Begi, NotN, NotN, NotN, NotN, Begi,
1418 // 0x60 (0x61..0x7A are 'a'..'z')
1419  NotN, Begi, Begi, Begi, Begi, Begi, Begi, Begi,
1420  Begi, Begi, Begi, Begi, Begi, Begi, Begi, Begi,
1421 // 0x70
1422  Begi, Begi, Begi, Begi, Begi, Begi, Begi, Begi,
1423  Begi, Begi, Begi, NotN, NotN, NotN, NotN, NotN
1424 };
1425 
1427 {
1428  ushort uc = ch.unicode();
1429  if (!(uc & ~0x7f)) // uc < 128
1430  return static_cast<NameChar>(nameCharTable[uc]);
1431 
1432  QChar::Category cat = ch.category();
1433  // ### some these categories might be slightly wrong
1434  if ((cat >= QChar::Letter_Uppercase && cat <= QChar::Letter_Other)
1435  || cat == QChar::Number_Letter)
1436  return NameBeginning;
1437  if ((cat >= QChar::Number_DecimalDigit && cat <= QChar::Number_Other)
1438  || (cat >= QChar::Mark_NonSpacing && cat <= QChar::Mark_Enclosing))
1439  return NameNotBeginning;
1440  return NotName;
1441 }
1442 
1444 {
1445  int n = 0;
1446  uint c;
1447  while ((c = getChar())) {
1448  if (fastDetermineNameChar(c) == NotName) {
1449  putChar(c);
1450  return n;
1451  } else {
1452  ++n;
1453  textBuffer += QChar(c);
1454  }
1455  }
1456 
1457  int pos = textBuffer.size() - n;
1458  putString(textBuffer, pos);
1459  textBuffer.resize(pos);
1460 
1461  return n;
1462 }
1463 
1465 {
1466  putStack.reserve(s.size());
1467  for (int i = s.size()-1; i >= from; --i)
1468  putStack.rawPush() = s.at(i).unicode();
1469 }
1470 
1472 {
1473  putStack.reserve(s.size());
1474  for (int i = s.size()-1; i >= 0; --i)
1475  putStack.rawPush() = ((LETTER << 16) | s.at(i).unicode());
1476 }
1477 
1479 {
1480  putStack.reserve(s.size());
1481  for (int i = s.size()-1; i >= 0; --i) {
1482  ushort c = s.at(i).unicode();
1483  if (c == '\n' || c == '\r')
1484  putStack.rawPush() = ((LETTER << 16) | c);
1485  else
1486  putStack.rawPush() = c;
1487  }
1488 }
1490 {
1491  putStack.reserve(s.size());
1492  for (int i = s.size()-1; i >= 0; --i) {
1493  ushort c = s.at(i).unicode();
1494  if (c == '&' || c == ';')
1495  putStack.rawPush() = c;
1496  else if (c == '\n' || c == '\r')
1497  putStack.rawPush() = ' ';
1498  else
1499  putStack.rawPush() = ((LETTER << 16) | c);
1500  }
1501 }
1502 
1504 {
1505  const int BUFFER_SIZE = 8192;
1507  readBufferPos = 0;
1508  readBuffer.resize(0);
1509 #ifndef QT_NO_TEXTCODEC
1510  if (decoder)
1511 #endif
1512  nbytesread = 0;
1513  if (device) {
1514  rawReadBuffer.resize(BUFFER_SIZE);
1515  int nbytesreadOrMinus1 = device->read(rawReadBuffer.data() + nbytesread, BUFFER_SIZE - nbytesread);
1516  nbytesread += qMax(nbytesreadOrMinus1, 0);
1517  } else {
1518  if (nbytesread)
1520  else
1523  dataBuffer.clear();
1524  }
1525  if (!nbytesread) {
1526  atEnd = true;
1527  return 0;
1528  }
1529 
1530 #ifndef QT_NO_TEXTCODEC
1531  if (!decoder) {
1532  if (nbytesread < 4) { // the 4 is to cover 0xef 0xbb 0xbf plus
1533  // one extra for the utf8 codec
1534  atEnd = true;
1535  return 0;
1536  }
1537  int mib = 106; // UTF-8
1538 
1539  // look for byte order mark
1540  uchar ch1 = rawReadBuffer.at(0);
1541  uchar ch2 = rawReadBuffer.at(1);
1542  uchar ch3 = rawReadBuffer.at(2);
1543  uchar ch4 = rawReadBuffer.at(3);
1544 
1545  if ((ch1 == 0 && ch2 == 0 && ch3 == 0xfe && ch4 == 0xff) ||
1546  (ch1 == 0xff && ch2 == 0xfe && ch3 == 0 && ch4 == 0))
1547  mib = 1017; // UTF-32 with byte order mark
1548  else if (ch1 == 0x3c && ch2 == 0x00 && ch3 == 0x00 && ch4 == 0x00)
1549  mib = 1019; // UTF-32LE
1550  else if (ch1 == 0x00 && ch2 == 0x00 && ch3 == 0x00 && ch4 == 0x3c)
1551  mib = 1018; // UTF-32BE
1552  else if ((ch1 == 0xfe && ch2 == 0xff) || (ch1 == 0xff && ch2 == 0xfe))
1553  mib = 1015; // UTF-16 with byte order mark
1554  else if (ch1 == 0x3c && ch2 == 0x00)
1555  mib = 1014; // UTF-16LE
1556  else if (ch1 == 0x00 && ch2 == 0x3c)
1557  mib = 1013; // UTF-16BE
1559  Q_ASSERT(codec);
1560  decoder = codec->makeDecoder();
1561  }
1562 
1564 
1565  if(lockEncoding && decoder->hasFailure()) {
1566  raiseWellFormedError(QXmlStream::tr("Encountered incorrectly encoded content."));
1567  readBuffer.clear();
1568  return 0;
1569  }
1570 #else
1572 #endif // QT_NO_TEXTCODEC
1573 
1574  readBuffer.reserve(1); // keep capacity when calling resize() next time
1575 
1576  if (readBufferPos < readBuffer.size()) {
1578  return c;
1579  }
1580 
1581  atEnd = true;
1582  return 0;
1583 }
1584 
1586 {
1587  for (int j = namespaceDeclarations.size() - 1; j >= 0; --j) {
1588  const NamespaceDeclaration &namespaceDeclaration = namespaceDeclarations.at(j);
1589  if (namespaceDeclaration.prefix == prefix) {
1590  return namespaceDeclaration.namespaceUri;
1591  }
1592  }
1593 
1594 #if 1
1595  if (namespaceProcessing && !prefix.isEmpty())
1596  raiseWellFormedError(QXmlStream::tr("Namespace prefix '%1' not declared").arg(prefix.toString()));
1597 #endif
1598 
1599  return QStringRef();
1600 }
1601 
1602 /*
1603  uses namespaceForPrefix and builds the attribute vector
1604  */
1606 {
1607  int n = attributeStack.size();
1608 
1609  if (namespaceProcessing) {
1610  for (int a = 0; a < dtdAttributes.size(); ++a) {
1611  DtdAttribute &dtdAttribute = dtdAttributes[a];
1612  if (!dtdAttribute.isNamespaceAttribute
1613  || dtdAttribute.defaultValue.isNull()
1614  || dtdAttribute.tagName != qualifiedName
1615  || dtdAttribute.attributeQualifiedName.isNull())
1616  continue;
1617  int i = 0;
1618  while (i < n && symName(attributeStack[i].key) != dtdAttribute.attributeQualifiedName)
1619  ++i;
1620  if (i != n)
1621  continue;
1622  if (dtdAttribute.attributePrefix.isEmpty() && dtdAttribute.attributeName == QLatin1String("xmlns")) {
1623  NamespaceDeclaration &namespaceDeclaration = namespaceDeclarations.push();
1624  namespaceDeclaration.prefix.clear();
1625 
1626  const QStringRef ns(dtdAttribute.defaultValue);
1627  if(ns == QLatin1String("http://www.w3.org/2000/xmlns/") ||
1628  ns == QLatin1String("http://www.w3.org/XML/1998/namespace"))
1629  raiseWellFormedError(QXmlStream::tr("Illegal namespace declaration."));
1630  else
1631  namespaceDeclaration.namespaceUri = ns;
1632  } else if (dtdAttribute.attributePrefix == QLatin1String("xmlns")) {
1633  NamespaceDeclaration &namespaceDeclaration = namespaceDeclarations.push();
1634  QStringRef namespacePrefix = dtdAttribute.attributeName;
1635  QStringRef namespaceUri = dtdAttribute.defaultValue;
1636  if (((namespacePrefix == QLatin1String("xml"))
1637  ^ (namespaceUri == QLatin1String("http://www.w3.org/XML/1998/namespace")))
1638  || namespaceUri == QLatin1String("http://www.w3.org/2000/xmlns/")
1639  || namespaceUri.isEmpty()
1640  || namespacePrefix == QLatin1String("xmlns"))
1641  raiseWellFormedError(QXmlStream::tr("Illegal namespace declaration."));
1642 
1643  namespaceDeclaration.prefix = namespacePrefix;
1644  namespaceDeclaration.namespaceUri = namespaceUri;
1645  }
1646  }
1647  }
1648 
1649  tagStack.top().namespaceDeclaration.namespaceUri = namespaceUri = namespaceForPrefix(prefix);
1650 
1651  attributes.resize(n);
1652 
1653  for (int i = 0; i < n; ++i) {
1654  QXmlStreamAttribute &attribute = attributes[i];
1655  Attribute &attrib = attributeStack[i];
1656  QStringRef prefix(symPrefix(attrib.key));
1657  QStringRef name(symString(attrib.key));
1659  QStringRef value(symString(attrib.value));
1660 
1661  attribute.m_name = QXmlStreamStringRef(name);
1662  attribute.m_qualifiedName = QXmlStreamStringRef(qualifiedName);
1663  attribute.m_value = QXmlStreamStringRef(value);
1664 
1665  if (!prefix.isEmpty()) {
1666  QStringRef attributeNamespaceUri = namespaceForPrefix(prefix);
1667  attribute.m_namespaceUri = QXmlStreamStringRef(attributeNamespaceUri);
1668  }
1669 
1670  for (int j = 0; j < i; ++j) {
1671  if (attributes[j].name() == attribute.name()
1672  && attributes[j].namespaceUri() == attribute.namespaceUri()
1673  && (namespaceProcessing || attributes[j].qualifiedName() == attribute.qualifiedName()))
1674  raiseWellFormedError(QXmlStream::tr("Attribute redefined."));
1675  }
1676  }
1677 
1678  for (int a = 0; a < dtdAttributes.size(); ++a) {
1679  DtdAttribute &dtdAttribute = dtdAttributes[a];
1680  if (dtdAttribute.isNamespaceAttribute
1681  || dtdAttribute.defaultValue.isNull()
1682  || dtdAttribute.tagName != qualifiedName
1683  || dtdAttribute.attributeQualifiedName.isNull())
1684  continue;
1685  int i = 0;
1686  while (i < n && symName(attributeStack[i].key) != dtdAttribute.attributeQualifiedName)
1687  ++i;
1688  if (i != n)
1689  continue;
1690 
1691 
1692 
1693  QXmlStreamAttribute attribute;
1694  attribute.m_name = QXmlStreamStringRef(dtdAttribute.attributeName);
1696  attribute.m_value = QXmlStreamStringRef(dtdAttribute.defaultValue);
1697 
1698  if (!dtdAttribute.attributePrefix.isEmpty()) {
1699  QStringRef attributeNamespaceUri = namespaceForPrefix(dtdAttribute.attributePrefix);
1700  attribute.m_namespaceUri = QXmlStreamStringRef(attributeNamespaceUri);
1701  }
1702  attribute.m_isDefault = true;
1703  attributes.append(attribute);
1704  }
1705 
1706  attributeStack.clear();
1707 }
1708 
1710 {
1711  const Tag &tag = tagStack.top();
1712  int n = namespaceDeclarations.size() - tag.namespaceDeclarationsSize;
1714  for (int i = 0; i < n; ++i) {
1715  const NamespaceDeclaration &namespaceDeclaration = namespaceDeclarations.at(tag.namespaceDeclarationsSize + i);
1716  QXmlStreamNamespaceDeclaration &publicNamespaceDeclaration = publicNamespaceDeclarations[i];
1717  publicNamespaceDeclaration.m_prefix = QXmlStreamStringRef(namespaceDeclaration.prefix);
1718  publicNamespaceDeclaration.m_namespaceUri = QXmlStreamStringRef(namespaceDeclaration.namespaceUri);
1719  }
1720 }
1721 
1723 {
1725  for (int i = 0; i < notationDeclarations.size(); ++i) {
1726  const QXmlStreamReaderPrivate::NotationDeclaration &notationDeclaration = notationDeclarations.at(i);
1727  QXmlStreamNotationDeclaration &publicNotationDeclaration = publicNotationDeclarations[i];
1728  publicNotationDeclaration.m_name = QXmlStreamStringRef(notationDeclaration.name);
1729  publicNotationDeclaration.m_systemId = QXmlStreamStringRef(notationDeclaration.systemId);
1730  publicNotationDeclaration.m_publicId = QXmlStreamStringRef(notationDeclaration.publicId);
1731 
1732  }
1733  notationDeclarations.clear();
1735  for (int i = 0; i < entityDeclarations.size(); ++i) {
1736  const QXmlStreamReaderPrivate::EntityDeclaration &entityDeclaration = entityDeclarations.at(i);
1737  QXmlStreamEntityDeclaration &publicEntityDeclaration = publicEntityDeclarations[i];
1738  publicEntityDeclaration.m_name = QXmlStreamStringRef(entityDeclaration.name);
1739  publicEntityDeclaration.m_notationName = QXmlStreamStringRef(entityDeclaration.notationName);
1740  publicEntityDeclaration.m_systemId = QXmlStreamStringRef(entityDeclaration.systemId);
1741  publicEntityDeclaration.m_publicId = QXmlStreamStringRef(entityDeclaration.publicId);
1742  publicEntityDeclaration.m_value = QXmlStreamStringRef(entityDeclaration.value);
1743  }
1744  entityDeclarations.clear();
1745  parameterEntityHash.clear();
1746 }
1747 
1749 {
1750  bool ok = true;
1751  uint s;
1752  // ### add toXShort to QStringRef?
1753  if (sym(symbolIndex).c == 'x')
1754  s = symString(symbolIndex, 1).toString().toUInt(&ok, 16);
1755  else
1756  s = symString(symbolIndex).toString().toUInt(&ok, 10);
1757 
1758  ok &= (s == 0x9 || s == 0xa || s == 0xd || (s >= 0x20 && s <= 0xd7ff)
1759  || (s >= 0xe000 && s <= 0xfffd) || (s >= 0x10000 && s <= 0x10ffff));
1760 
1761  return ok ? s : 0;
1762 }
1763 
1764 
1766 {
1767 //#x20 | #xD | #xA | [a-zA-Z0-9] | [-'()+,./:=?;!*#@$_%]
1768 
1769  const ushort *data = reinterpret_cast<const ushort *>(publicId.constData());
1770  uchar c = 0;
1771  int i;
1772  for (i = publicId.size() - 1; i >= 0; --i) {
1773  if (data[i] < 256)
1774  switch ((c = data[i])) {
1775  case ' ': case '\n': case '\r': case '-': case '(': case ')':
1776  case '+': case ',': case '.': case '/': case ':': case '=':
1777  case '?': case ';': case '!': case '*': case '#': case '@':
1778  case '$': case '_': case '%': case '\'': case '\"':
1779  continue;
1780  default:
1781  if ((c >= 'a' && c <= 'z')
1782  || (c >= 'A' && c <= 'Z')
1783  || (c >= '0' && c <= '9'))
1784  continue;
1785  }
1786  break;
1787  }
1788  if (i >= 0)
1789  raiseWellFormedError(QXmlStream::tr("Unexpected character '%1' in public id literal.").arg(QChar(QLatin1Char(c))));
1790 }
1791 
1792 /*
1793  Checks whether the document starts with an xml declaration. If it
1794  does, this function returns true; otherwise it sets up everything
1795  for a synthetic start document event and returns false.
1796  */
1798 {
1799  hasCheckedStartDocument = true;
1800 
1801  if (scanString(spell[XML], XML))
1802  return true;
1803 
1805  if (atEnd) {
1806  hasCheckedStartDocument = false;
1808  }
1809  return false;
1810 }
1811 
1813 {
1814  QString err;
1815  if (documentVersion != QLatin1String("1.0")) {
1817  err = QXmlStream::tr("Invalid XML version string.");
1818  else
1819  err = QXmlStream::tr("Unsupported XML version.");
1820  }
1821  int n = attributeStack.size();
1822 
1823  /* We use this bool to ensure that the pesudo attributes are in the
1824  * proper order:
1825  *
1826  * [23] XMLDecl ::= '<?xml' VersionInfo EncodingDecl? SDDecl? S? '?>' */
1827  bool hasStandalone = false;
1828 
1829  for (int i = 0; err.isNull() && i < n; ++i) {
1830  Attribute &attrib = attributeStack[i];
1831  QStringRef prefix(symPrefix(attrib.key));
1832  QStringRef key(symString(attrib.key));
1833  QStringRef value(symString(attrib.value));
1834 
1835  if (prefix.isEmpty() && key == QLatin1String("encoding")) {
1836  const QString name(value.toString());
1837  documentEncoding = value;
1838 
1839  if(hasStandalone)
1840  err = QXmlStream::tr("The standalone pseudo attribute must appear after the encoding.");
1842  err = QXmlStream::tr("%1 is an invalid encoding name.").arg(name);
1843  else {
1844 #ifdef QT_NO_TEXTCODEC
1846 #else
1847  QTextCodec *const newCodec = QTextCodec::codecForName(name.toLatin1());
1848  if (!newCodec)
1849  err = QXmlStream::tr("Encoding %1 is unsupported").arg(name);
1850  else if (newCodec != codec && !lockEncoding) {
1851  codec = newCodec;
1852  delete decoder;
1853  decoder = codec->makeDecoder();
1855  }
1856 #endif // QT_NO_TEXTCODEC
1857  }
1858  } else if (prefix.isEmpty() && key == QLatin1String("standalone")) {
1859  hasStandalone = true;
1860  if (value == QLatin1String("yes"))
1861  standalone = true;
1862  else if (value == QLatin1String("no"))
1863  standalone = false;
1864  else
1865  err = QXmlStream::tr("Standalone accepts only yes or no.");
1866  } else {
1867  err = QXmlStream::tr("Invalid attribute in XML declaration.");
1868  }
1869  }
1870 
1871  if (!err.isNull())
1872  raiseWellFormedError(err);
1873  attributeStack.clear();
1874 }
1875 
1876 
1878 {
1879  this->error = error;
1880  errorString = message;
1881  if (errorString.isNull()) {
1883  errorString = QXmlStream::tr("Premature end of document.");
1884  else if (error == QXmlStreamReader::CustomError)
1885  errorString = QXmlStream::tr("Invalid document.");
1886  }
1887 
1889 }
1890 
1892 {
1894 }
1895 
1897 {
1898 
1899  if (token == EOF_SYMBOL) {
1901  return;
1902  }
1903  const int nmax = 4;
1904  QString error_message;
1905  int ers = state_stack[tos];
1906  int nexpected = 0;
1907  int expected[nmax];
1908  if (token != ERROR)
1909  for (int tk = 0; tk < TERMINAL_COUNT; ++tk) {
1910  int k = t_action(ers, tk);
1911  if (k <= 0)
1912  continue;
1913  if (spell[tk]) {
1914  if (nexpected < nmax)
1915  expected[nexpected++] = tk;
1916  }
1917  }
1918 
1919  error_message.clear ();
1920  if (nexpected && nexpected < nmax) {
1921  bool first = true;
1922 
1923  for (int s = 0; s < nexpected; ++s) {
1924  if (first)
1925  error_message += QXmlStream::tr ("Expected ");
1926  else if (s == nexpected - 1)
1927  error_message += QLatin1String (nexpected > 2 ? ", or " : " or ");
1928  else
1929  error_message += QLatin1String (", ");
1930 
1931  first = false;
1932  error_message += QLatin1String("\'");
1933  error_message += QLatin1String (spell [expected[s]]);
1934  error_message += QLatin1String("\'");
1935  }
1936  error_message += QXmlStream::tr(", but got \'");
1937  error_message += QLatin1String(spell [token]);
1938  error_message += QLatin1String("\'");
1939  } else {
1940  error_message += QXmlStream::tr("Unexpected \'");
1941  error_message += QLatin1String(spell [token]);
1942  error_message += QLatin1String("\'");
1943  }
1944  error_message += QLatin1Char('.');
1945 
1946  raiseWellFormedError(error_message);
1947 }
1948 
1950  resumeReduction = rule;
1953 }
1954 
1960 {
1961  Q_D(const QXmlStreamReader);
1962  return d->lineNumber + 1; // in public we start with 1
1963 }
1964 
1970 {
1971  Q_D(const QXmlStreamReader);
1972  return d->characterOffset - d->lastLineStart + d->readBufferPos;
1973 }
1974 
1980 {
1981  Q_D(const QXmlStreamReader);
1982  return d->characterOffset + d->readBufferPos;
1983 }
1984 
1985 
1990 {
1991  Q_D(const QXmlStreamReader);
1992  return d->text;
1993 }
1994 
1995 
2003 {
2004  Q_D(const QXmlStreamReader);
2005  if (d->notationDeclarations.size())
2006  const_cast<QXmlStreamReaderPrivate *>(d)->resolveDtd();
2007  return d->publicNotationDeclarations;
2008 }
2009 
2010 
2018 {
2019  Q_D(const QXmlStreamReader);
2020  if (d->entityDeclarations.size())
2021  const_cast<QXmlStreamReaderPrivate *>(d)->resolveDtd();
2022  return d->publicEntityDeclarations;
2023 }
2024 
2036 {
2037  Q_D(const QXmlStreamReader);
2038  if (d->type == QXmlStreamReader::DTD)
2039  return d->dtdName;
2040  return QStringRef();
2041 }
2042 
2054 {
2055  Q_D(const QXmlStreamReader);
2056  if (d->type == QXmlStreamReader::DTD)
2057  return d->dtdPublicId;
2058  return QStringRef();
2059 }
2060 
2072 {
2073  Q_D(const QXmlStreamReader);
2074  if (d->type == QXmlStreamReader::DTD)
2075  return d->dtdSystemId;
2076  return QStringRef();
2077 }
2078 
2089 {
2090  Q_D(const QXmlStreamReader);
2091  if (d->publicNamespaceDeclarations.isEmpty() && d->type == StartElement)
2092  const_cast<QXmlStreamReaderPrivate *>(d)->resolvePublicNamespaces();
2093  return d->publicNamespaceDeclarations;
2094 }
2095 
2096 
2111 {
2113  QXmlStreamReaderPrivate::NamespaceDeclaration &namespaceDeclaration = d->namespaceDeclarations.push();
2114  namespaceDeclaration.prefix = d->addToStringStorage(extraNamespaceDeclaration.prefix());
2115  namespaceDeclaration.namespaceUri = d->addToStringStorage(extraNamespaceDeclaration.namespaceUri());
2116 }
2117 
2129 {
2130  for (int i = 0; i < extraNamespaceDeclarations.size(); ++i)
2131  addExtraNamespaceDeclaration(extraNamespaceDeclarations.at(i));
2132 }
2133 
2134 
2152 {
2154  if (isStartElement()) {
2155  QString result;
2156  forever {
2157  switch (readNext()) {
2158  case Characters:
2159  case EntityReference:
2160  result.insert(result.size(), d->text.unicode(), d->text.size());
2161  break;
2162  case EndElement:
2163  return result;
2164  case ProcessingInstruction:
2165  case Comment:
2166  break;
2167  case StartElement:
2168  if (behaviour == SkipChildElements) {
2169  skipCurrentElement();
2170  break;
2171  } else if (behaviour == IncludeChildElements) {
2172  result += readElementText(behaviour);
2173  break;
2174  }
2175  // Fall through (for ErrorOnUnexpectedElement)
2176  default:
2177  if (d->error || behaviour == ErrorOnUnexpectedElement) {
2178  if (!d->error)
2179  d->raiseError(UnexpectedElementError, QXmlStream::tr("Expected character data."));
2180  return result;
2181  }
2182  }
2183  }
2184  }
2185  return QString();
2186 }
2187 
2197 {
2198  return readElementText(ErrorOnUnexpectedElement);
2199 }
2200 
2206 {
2208  d->raiseError(CustomError, message);
2209 }
2210 
2217 {
2218  Q_D(const QXmlStreamReader);
2219  if (d->type == QXmlStreamReader::Invalid)
2220  return d->errorString;
2221  return QString();
2222 }
2223 
2229 {
2230  Q_D(const QXmlStreamReader);
2231  if (d->type == QXmlStreamReader::Invalid)
2232  return d->error;
2233  return NoError;
2234 }
2235 
2240 {
2241  Q_D(const QXmlStreamReader);
2242  return d->processingInstructionTarget;
2243 }
2244 
2249 {
2250  Q_D(const QXmlStreamReader);
2251  return d->processingInstructionData;
2252 }
2253 
2254 
2255 
2262 {
2263  Q_D(const QXmlStreamReader);
2264  return d->name;
2265 }
2266 
2273 {
2274  Q_D(const QXmlStreamReader);
2275  return d->namespaceUri;
2276 }
2277 
2291 {
2292  Q_D(const QXmlStreamReader);
2293  return d->qualifiedName;
2294 }
2295 
2296 
2297 
2309 {
2310  Q_D(const QXmlStreamReader);
2311  return d->prefix;
2312 }
2313 
2318 {
2319  Q_D(const QXmlStreamReader);
2320  return d->attributes;
2321 }
2322 
2323 #endif // QT_NO_XMLSTREAMREADER
2324 
2346 {
2347  m_isDefault = false;
2348 }
2349 
2354 {
2355 }
2356 
2361 {
2362  m_namespaceUri = QXmlStreamStringRef(QStringRef(&namespaceUri));
2363  m_name = m_qualifiedName = QXmlStreamStringRef(QStringRef(&name));
2364  m_value = QXmlStreamStringRef(QStringRef(&value));
2365  m_namespaceUri = QXmlStreamStringRef(QStringRef(&namespaceUri));
2366 }
2367 
2372 {
2373  int colon = qualifiedName.indexOf(QLatin1Char(':'));
2374  m_name = QXmlStreamStringRef(QStringRef(&qualifiedName,
2375  colon + 1,
2376  qualifiedName.size() - (colon + 1)));
2377  m_qualifiedName = QXmlStreamStringRef(QStringRef(&qualifiedName));
2378  m_value = QXmlStreamStringRef(QStringRef(&value));
2379 }
2380 
2459 {
2460  *this = other;
2461 }
2462 
2467 {
2468  m_name = other.m_name;
2469  m_namespaceUri = other.m_namespaceUri;
2470  m_qualifiedName = other.m_qualifiedName;
2471  m_value = other.m_value;
2472  m_isDefault = other.m_isDefault;
2473  return *this;
2474 }
2475 
2476 
2542 {
2543 }
2548 {
2549  *this = other;
2550 }
2551 
2556 {
2557  m_name = other.m_name;
2558  m_systemId = other.m_systemId;
2559  m_publicId = other.m_publicId;
2560  return *this;
2561 }
2562 
2567 {
2568 }
2569 
2644 {
2645 }
2646 
2656 {
2657  m_prefix = prefix;
2658  m_namespaceUri = namespaceUri;
2659 }
2660 
2665 {
2666  *this = other;
2667 }
2668 
2673 {
2674  m_prefix = other.m_prefix;
2675  m_namespaceUri = other.m_namespaceUri;
2676  return *this;
2677 }
2682 {
2683 }
2684 
2732 {
2733 }
2734 
2739 {
2740  *this = other;
2741 }
2742 
2747 {
2748  m_name = other.m_name;
2749  m_notationName = other.m_notationName;
2750  m_systemId = other.m_systemId;
2751  m_publicId = other.m_publicId;
2752  m_value = other.m_value;
2753  return *this;
2754 }
2755 
2760 {
2761 }
2762 
2806 {
2807  for (int i = 0; i < size(); ++i) {
2808  const QXmlStreamAttribute &attribute = at(i);
2809  if (attribute.name() == name && attribute.namespaceUri() == namespaceUri)
2810  return attribute.value();
2811  }
2812  return QStringRef();
2813 }
2814 
2821 {
2822  for (int i = 0; i < size(); ++i) {
2823  const QXmlStreamAttribute &attribute = at(i);
2824  if (attribute.name() == name && attribute.namespaceUri() == namespaceUri)
2825  return attribute.value();
2826  }
2827  return QStringRef();
2828 }
2829 
2836 {
2837  for (int i = 0; i < size(); ++i) {
2838  const QXmlStreamAttribute &attribute = at(i);
2839  if (attribute.name() == name && attribute.namespaceUri() == namespaceUri)
2840  return attribute.value();
2841  }
2842  return QStringRef();
2843 }
2844 
2858 {
2859  for (int i = 0; i < size(); ++i) {
2860  const QXmlStreamAttribute &attribute = at(i);
2861  if (attribute.qualifiedName() == qualifiedName)
2862  return attribute.value();
2863  }
2864  return QStringRef();
2865 }
2866 
2880 {
2881  for (int i = 0; i < size(); ++i) {
2882  const QXmlStreamAttribute &attribute = at(i);
2883  if (attribute.qualifiedName() == qualifiedName)
2884  return attribute.value();
2885  }
2886  return QStringRef();
2887 }
2888 
2894 {
2895  append(QXmlStreamAttribute(namespaceUri, name, value));
2896 }
2897 
2903 {
2904  append(QXmlStreamAttribute(qualifiedName, value));
2905 }
2906 
2907 #ifndef QT_NO_XMLSTREAMREADER
2908 
2972 {
2973  Q_D(const QXmlStreamReader);
2974  return d->type == QXmlStreamReader::Characters && d->isWhitespace;
2975 }
2976 
2983 {
2984  Q_D(const QXmlStreamReader);
2985  return d->type == QXmlStreamReader::Characters && d->isCDATA;
2986 }
2987 
2988 
2989 
2997 {
2998  Q_D(const QXmlStreamReader);
2999  return d->standalone;
3000 }
3001 
3002 
3014 {
3015  Q_D(const QXmlStreamReader);
3016  if (d->type == QXmlStreamReader::StartDocument)
3017  return d->documentVersion;
3018  return QStringRef();
3019 }
3020 
3032 {
3033  Q_D(const QXmlStreamReader);
3034  if (d->type == QXmlStreamReader::StartDocument)
3035  return d->documentEncoding;
3036  return QStringRef();
3037 }
3038 
3039 #endif // QT_NO_XMLSTREAMREADER
3040 
3118 #ifndef QT_NO_XMLSTREAMWRITER
3119 
3123 public:
3126  if (deleteDevice)
3127  delete device;
3128 #ifndef QT_NO_TEXTCODEC
3129  delete encoder;
3130 #endif
3131  }
3132 
3133  void write(const QStringRef &);
3134  void write(const QString &);
3135  void writeEscaped(const QString &, bool escapeWhitespace = false);
3136  void write(const char *s, int len);
3137  template <int N> void write(const char (&s)[N]) { write(s, N - 1); }
3138  bool finishStartElement(bool contents = true);
3139  void writeStartElement(const QString &namespaceUri, const QString &name);
3153 
3154 #ifndef QT_NO_TEXTCODEC
3157 #endif
3158  void checkIfASCIICompatibleCodec();
3159 
3160  NamespaceDeclaration &findNamespace(const QString &namespaceUri, bool writeDeclaration = false, bool noDefault = false);
3161  void writeNamespaceDeclaration(const NamespaceDeclaration &namespaceDeclaration);
3162 
3164 
3165  void indent(int level);
3166 };
3167 
3168 
3170  :autoFormattingIndent(4, ' ')
3171 {
3172  q_ptr = q;
3173  device = 0;
3174  stringDevice = 0;
3175  deleteDevice = false;
3176 #ifndef QT_NO_TEXTCODEC
3177  codec = QTextCodec::codecForMib(106); // utf8
3178  encoder = codec->makeEncoder(QTextCodec::IgnoreHeader); // no byte order mark for utf8
3179 #endif
3181  inStartElement = inEmptyElement = false;
3182  wroteSomething = false;
3183  hasError = false;
3184  lastWasStartElement = false;
3186  autoFormatting = false;
3188 }
3189 
3191 {
3192 #ifndef QT_NO_TEXTCODEC
3193  Q_ASSERT(encoder);
3194  // assumes ASCII-compatibility for all 8-bit encodings
3195  const QByteArray bytes = encoder->fromUnicode(QLatin1String(" "));
3196  isCodecASCIICompatible = (bytes.count() == 1);
3197 #else
3198  isCodecASCIICompatible = true;
3199 #endif
3200 }
3201 
3203 {
3204  if (device) {
3205  if (hasError)
3206  return;
3207 #ifdef QT_NO_TEXTCODEC
3208  QByteArray bytes = s.toLatin1();
3209 #else
3210  QByteArray bytes = encoder->fromUnicode(s.constData(), s.size());
3211 #endif
3212  if (device->write(bytes) != bytes.size())
3213  hasError = true;
3214  }
3215  else if (stringDevice)
3217  else
3218  qWarning("QXmlStreamWriter: No device");
3219 }
3220 
3222 {
3223  if (device) {
3224  if (hasError)
3225  return;
3226 #ifdef QT_NO_TEXTCODEC
3227  QByteArray bytes = s.toLatin1();
3228 #else
3229  QByteArray bytes = encoder->fromUnicode(s);
3230 #endif
3231  if (device->write(bytes) != bytes.size())
3232  hasError = true;
3233  }
3234  else if (stringDevice)
3235  stringDevice->append(s);
3236  else
3237  qWarning("QXmlStreamWriter: No device");
3238 }
3239 
3240 void QXmlStreamWriterPrivate::writeEscaped(const QString &s, bool escapeWhitespace)
3241 {
3242  QString escaped;
3243  escaped.reserve(s.size());
3244  for ( int i = 0; i < s.size(); ++i ) {
3245  QChar c = s.at(i);
3246  if (c.unicode() == '<' )
3247  escaped.append(QLatin1String("&lt;"));
3248  else if (c.unicode() == '>' )
3249  escaped.append(QLatin1String("&gt;"));
3250  else if (c.unicode() == '&' )
3251  escaped.append(QLatin1String("&amp;"));
3252  else if (c.unicode() == '\"' )
3253  escaped.append(QLatin1String("&quot;"));
3254  else if (escapeWhitespace && c.isSpace()) {
3255  if (c.unicode() == '\n')
3256  escaped.append(QLatin1String("&#10;"));
3257  else if (c.unicode() == '\r')
3258  escaped.append(QLatin1String("&#13;"));
3259  else if (c.unicode() == '\t')
3260  escaped.append(QLatin1String("&#9;"));
3261  else
3262  escaped += c;
3263  } else {
3264  escaped += QChar(c);
3265  }
3266  }
3267  write(escaped);
3268 }
3269 
3270 // Converts from ASCII to output encoding
3271 void QXmlStreamWriterPrivate::write(const char *s, int len)
3272 {
3273  if (device) {
3274  if (hasError)
3275  return;
3276  if (isCodecASCIICompatible) {
3277  if (device->write(s, len) != len)
3278  hasError = true;
3279  return;
3280  }
3281  }
3282 
3283  write(QString::fromLatin1(s, len));
3284 }
3285 
3287  if (namespaceDeclaration.prefix.isEmpty()) {
3288  write(" xmlns=\"");
3289  write(namespaceDeclaration.namespaceUri);
3290  write("\"");
3291  } else {
3292  write(" xmlns:");
3293  write(namespaceDeclaration.prefix);
3294  write("=\"");
3295  write(namespaceDeclaration.namespaceUri);
3296  write("\"");
3297  }
3298 }
3299 
3301 {
3302  bool hadSomethingWritten = wroteSomething;
3303  wroteSomething = contents;
3304  if (!inStartElement)
3305  return hadSomethingWritten;
3306 
3307  if (inEmptyElement) {
3308  write("/>");
3311  lastWasStartElement = false;
3312  } else {
3313  write(">");
3314  }
3315  inStartElement = inEmptyElement = false;
3317  return hadSomethingWritten;
3318 }
3319 
3320 QXmlStreamPrivateTagStack::NamespaceDeclaration &QXmlStreamWriterPrivate::findNamespace(const QString &namespaceUri, bool writeDeclaration, bool noDefault)
3321 {
3322  for (int j = namespaceDeclarations.size() - 1; j >= 0; --j) {
3323  NamespaceDeclaration &namespaceDeclaration = namespaceDeclarations[j];
3324  if (namespaceDeclaration.namespaceUri == namespaceUri) {
3325  if (!noDefault || !namespaceDeclaration.prefix.isEmpty())
3326  return namespaceDeclaration;
3327  }
3328  }
3329  if (namespaceUri.isEmpty())
3330  return emptyNamespace;
3331  NamespaceDeclaration &namespaceDeclaration = namespaceDeclarations.push();
3332  if (namespaceUri.isEmpty()) {
3333  namespaceDeclaration.prefix.clear();
3334  } else {
3335  QString s;
3336  int n = ++namespacePrefixCount;
3337  forever {
3338  s = QLatin1Char('n') + QString::number(n++);
3339  int j = namespaceDeclarations.size() - 2;
3340  while (j >= 0 && namespaceDeclarations.at(j).prefix != s)
3341  --j;
3342  if (j < 0)
3343  break;
3344  }
3345  namespaceDeclaration.prefix = addToStringStorage(s);
3346  }
3347  namespaceDeclaration.namespaceUri = addToStringStorage(namespaceUri);
3348  if (writeDeclaration)
3349  writeNamespaceDeclaration(namespaceDeclaration);
3350  return namespaceDeclaration;
3351 }
3352 
3353 
3354 
3356 {
3357  write("\n");
3358  for (int i = level; i > 0; --i)
3360 }
3361 
3362 
3369  : d_ptr(new QXmlStreamWriterPrivate(this))
3370 {
3371 }
3372 
3377  : d_ptr(new QXmlStreamWriterPrivate(this))
3378 {
3380  d->device = device;
3381 }
3382 
3388  : d_ptr(new QXmlStreamWriterPrivate(this))
3389 {
3391  d->device = new QBuffer(array);
3392  d->device->open(QIODevice::WriteOnly);
3393  d->deleteDevice = true;
3394 }
3395 
3396 
3400  : d_ptr(new QXmlStreamWriterPrivate(this))
3401 {
3403  d->stringDevice = string;
3404 }
3405 
3410 {
3411 }
3412 
3413 
3421 {
3423  if (device == d->device)
3424  return;
3425  d->stringDevice = 0;
3426  if (d->deleteDevice) {
3427  delete d->device;
3428  d->deleteDevice = false;
3429  }
3430  d->device = device;
3431 }
3432 
3440 {
3441  Q_D(const QXmlStreamWriter);
3442  return d->device;
3443 }
3444 
3445 
3446 #ifndef QT_NO_TEXTCODEC
3447 
3459 {
3461  if (codec) {
3462  d->codec = codec;
3463  delete d->encoder;
3464  d->encoder = codec->makeEncoder(QTextCodec::IgnoreHeader); // no byte order mark for utf8
3465  d->checkIfASCIICompatibleCodec();
3466  }
3467 }
3468 
3477 void QXmlStreamWriter::setCodec(const char *codecName)
3478 {
3479  setCodec(QTextCodec::codecForName(codecName));
3480 }
3481 
3488 {
3489  Q_D(const QXmlStreamWriter);
3490  return d->codec;
3491 }
3492 #endif // QT_NO_TEXTCODEC
3493 
3522 {
3524  d->autoFormatting = enable;
3525 }
3526 
3533 {
3534  Q_D(const QXmlStreamWriter);
3535  return d->autoFormatting;
3536 }
3537 
3556 {
3558  d->autoFormattingIndent = QByteArray(qAbs(spacesOrTabs), spacesOrTabs >= 0 ? ' ' : '\t');
3559 }
3560 
3562 {
3563  Q_D(const QXmlStreamWriter);
3564  return d->autoFormattingIndent.count(' ') - d->autoFormattingIndent.count('\t');
3565 }
3566 
3580 {
3581  Q_D(const QXmlStreamWriter);
3582  return d->hasError;
3583 }
3584 
3597 {
3599  Q_ASSERT(d->inStartElement);
3600  Q_ASSERT(qualifiedName.count(QLatin1Char(':')) <= 1);
3601  d->write(" ");
3602  d->write(qualifiedName);
3603  d->write("=\"");
3604  d->writeEscaped(value, true);
3605  d->write("\"");
3606 }
3607 
3616 void QXmlStreamWriter::writeAttribute(const QString &namespaceUri, const QString &name, const QString &value)
3617 {
3619  Q_ASSERT(d->inStartElement);
3620  Q_ASSERT(!name.contains(QLatin1Char(':')));
3621  QXmlStreamWriterPrivate::NamespaceDeclaration &namespaceDeclaration = d->findNamespace(namespaceUri, true, true);
3622  d->write(" ");
3623  if (!namespaceDeclaration.prefix.isEmpty()) {
3624  d->write(namespaceDeclaration.prefix);
3625  d->write(":");
3626  }
3627  d->write(name);
3628  d->write("=\"");
3629  d->writeEscaped(value, true);
3630  d->write("\"");
3631 }
3632 
3645 {
3646  if (attribute.namespaceUri().isEmpty())
3647  writeAttribute(attribute.qualifiedName().toString(),
3648  attribute.value().toString());
3649  else
3650  writeAttribute(attribute.namespaceUri().toString(),
3651  attribute.name().toString(),
3652  attribute.value().toString());
3653 }
3654 
3655 
3666 {
3668  Q_ASSERT(d->inStartElement);
3669  Q_UNUSED(d);
3670  for (int i = 0; i < attributes.size(); ++i)
3671  writeAttribute(attributes.at(i));
3672 }
3673 
3674 
3684 {
3686  d->finishStartElement();
3687  QString copy(text);
3688  copy.replace(QLatin1String("]]>"), QLatin1String("]]]]><![CDATA[>"));
3689  d->write("<![CDATA[");
3690  d->write(copy);
3691  d->write("]]>");
3692 }
3693 
3694 
3702 {
3704  d->finishStartElement();
3705  d->writeEscaped(text);
3706 }
3707 
3708 
3714 {
3716  Q_ASSERT(!text.contains(QLatin1String("--")) && !text.endsWith(QLatin1Char('-')));
3717  if (!d->finishStartElement(false) && d->autoFormatting)
3718  d->indent(d->tagStack.size());
3719  d->write("<!--");
3720  d->write(text);
3721  d->write("-->");
3722  d->inStartElement = d->lastWasStartElement = false;
3723 }
3724 
3725 
3730 {
3732  d->finishStartElement();
3733  if (d->autoFormatting)
3734  d->write("\n");
3735  d->write(dtd);
3736  if (d->autoFormatting)
3737  d->write("\n");
3738 }
3739 
3740 
3741 
3750 {
3752  Q_ASSERT(qualifiedName.count(QLatin1Char(':')) <= 1);
3753  d->writeStartElement(QString(), qualifiedName);
3754  d->inEmptyElement = true;
3755 }
3756 
3757 
3765 void QXmlStreamWriter::writeEmptyElement(const QString &namespaceUri, const QString &name)
3766 {
3768  Q_ASSERT(!name.contains(QLatin1Char(':')));
3769  d->writeStartElement(namespaceUri, name);
3770  d->inEmptyElement = true;
3771 }
3772 
3773 
3783 {
3784  writeStartElement(qualifiedName);
3785  writeCharacters(text);
3786  writeEndElement();
3787 }
3788 
3799 void QXmlStreamWriter::writeTextElement(const QString &namespaceUri, const QString &name, const QString &text)
3800 {
3801  writeStartElement(namespaceUri, name);
3802  writeCharacters(text);
3803  writeEndElement();
3804 }
3805 
3806 
3813 {
3815  while (d->tagStack.size())
3816  writeEndElement();
3817  d->write("\n");
3818 }
3819 
3826 {
3828  if (d->tagStack.isEmpty())
3829  return;
3830 
3831  // shortcut: if nothing was written, close as empty tag
3832  if (d->inStartElement && !d->inEmptyElement) {
3833  d->write("/>");
3834  d->lastWasStartElement = d->inStartElement = false;
3835  QXmlStreamWriterPrivate::Tag &tag = d->tagStack_pop();
3836  d->lastNamespaceDeclaration = tag.namespaceDeclarationsSize;
3837  return;
3838  }
3839 
3840  if (!d->finishStartElement(false) && !d->lastWasStartElement && d->autoFormatting)
3841  d->indent(d->tagStack.size()-1);
3842  if (d->tagStack.isEmpty())
3843  return;
3844  d->lastWasStartElement = false;
3845  QXmlStreamWriterPrivate::Tag &tag = d->tagStack_pop();
3846  d->lastNamespaceDeclaration = tag.namespaceDeclarationsSize;
3847  d->write("</");
3848  if (!tag.namespaceDeclaration.prefix.isEmpty()) {
3849  d->write(tag.namespaceDeclaration.prefix);
3850  d->write(":");
3851  }
3852  d->write(tag.name);
3853  d->write(">");
3854 }
3855 
3856 
3857 
3862 {
3864  d->finishStartElement();
3865  d->write("&");
3866  d->write(name);
3867  d->write(";");
3868 }
3869 
3870 
3886 void QXmlStreamWriter::writeNamespace(const QString &namespaceUri, const QString &prefix)
3887 {
3889  Q_ASSERT(!namespaceUri.isEmpty());
3890  Q_ASSERT(prefix != QLatin1String("xmlns"));
3891  if (prefix.isEmpty()) {
3892  d->findNamespace(namespaceUri, d->inStartElement);
3893  } else {
3894  Q_ASSERT(!((prefix == QLatin1String("xml")) ^ (namespaceUri == QLatin1String("http://www.w3.org/XML/1998/namespace"))));
3895  Q_ASSERT(namespaceUri != QLatin1String("http://www.w3.org/2000/xmlns/"));
3896  QXmlStreamWriterPrivate::NamespaceDeclaration &namespaceDeclaration = d->namespaceDeclarations.push();
3897  namespaceDeclaration.prefix = d->addToStringStorage(prefix);
3898  namespaceDeclaration.namespaceUri = d->addToStringStorage(namespaceUri);
3899  if (d->inStartElement)
3900  d->writeNamespaceDeclaration(namespaceDeclaration);
3901  }
3902 }
3903 
3904 
3916 {
3918  Q_ASSERT(namespaceUri != QLatin1String("http://www.w3.org/XML/1998/namespace"));
3919  Q_ASSERT(namespaceUri != QLatin1String("http://www.w3.org/2000/xmlns/"));
3920  QXmlStreamWriterPrivate::NamespaceDeclaration &namespaceDeclaration = d->namespaceDeclarations.push();
3921  namespaceDeclaration.prefix.clear();
3922  namespaceDeclaration.namespaceUri = d->addToStringStorage(namespaceUri);
3923  if (d->inStartElement)
3924  d->writeNamespaceDeclaration(namespaceDeclaration);
3925 }
3926 
3927 
3933 {
3935  Q_ASSERT(!data.contains(QLatin1String("?>")));
3936  if (!d->finishStartElement(false) && d->autoFormatting)
3937  d->indent(d->tagStack.size());
3938  d->write("<?");
3939  d->write(target);
3940  if (!data.isNull()) {
3941  d->write(" ");
3942  d->write(data);
3943  }
3944  d->write("?>");
3945 }
3946 
3947 
3948 
3958 {
3960 }
3961 
3962 
3969 {
3971  d->finishStartElement(false);
3972  d->write("<?xml version=\"");
3973  d->write(version);
3974  if (d->device) { // stringDevice does not get any encoding
3975  d->write("\" encoding=\"");
3976 #ifdef QT_NO_TEXTCODEC
3977  d->write("iso-8859-1");
3978 #else
3979  d->write(d->codec->name().constData(), d->codec->name().length());
3980 #endif
3981  }
3982  d->write("\"?>");
3983 }
3984 
3991 void QXmlStreamWriter::writeStartDocument(const QString &version, bool standalone)
3992 {
3994  d->finishStartElement(false);
3995  d->write("<?xml version=\"");
3996  d->write(version);
3997  if (d->device) { // stringDevice does not get any encoding
3998  d->write("\" encoding=\"");
3999 #ifdef QT_NO_TEXTCODEC
4000  d->write("iso-8859-1");
4001 #else
4002  d->write(d->codec->name().constData(), d->codec->name().length());
4003 #endif
4004  }
4005  if (standalone)
4006  d->write("\" standalone=\"yes\"?>");
4007  else
4008  d->write("\" standalone=\"no\"?>");
4009 }
4010 
4011 
4020 {
4022  Q_ASSERT(qualifiedName.count(QLatin1Char(':')) <= 1);
4023  d->writeStartElement(QString(), qualifiedName);
4024 }
4025 
4026 
4035 void QXmlStreamWriter::writeStartElement(const QString &namespaceUri, const QString &name)
4036 {
4038  Q_ASSERT(!name.contains(QLatin1Char(':')));
4039  d->writeStartElement(namespaceUri, name);
4040 }
4041 
4043 {
4044  if (!finishStartElement(false) && autoFormatting)
4045  indent(tagStack.size());
4046 
4047  Tag &tag = tagStack_push();
4048  tag.name = addToStringStorage(name);
4049  tag.namespaceDeclaration = findNamespace(namespaceUri);
4050  write("<");
4051  if (!tag.namespaceDeclaration.prefix.isEmpty()) {
4052  write(tag.namespaceDeclaration.prefix);
4053  write(":");
4054  }
4055  write(tag.name);
4056  inStartElement = lastWasStartElement = true;
4057 
4058  for (int i = lastNamespaceDeclaration; i < namespaceDeclarations.size(); ++i)
4059  writeNamespaceDeclaration(namespaceDeclarations[i]);
4060  tag.namespaceDeclarationsSize = lastNamespaceDeclaration;
4061 }
4062 
4063 #ifndef QT_NO_XMLSTREAMREADER
4064 
4072 {
4073  switch (reader.tokenType()) {
4075  break;
4078  break;
4080  writeEndDocument();
4081  break;
4083  QXmlStreamNamespaceDeclarations namespaceDeclarations = reader.namespaceDeclarations();
4084  for (int i = 0; i < namespaceDeclarations.size(); ++i) {
4085  const QXmlStreamNamespaceDeclaration &namespaceDeclaration = namespaceDeclarations.at(i);
4086  writeNamespace(namespaceDeclaration.namespaceUri().toString(),
4087  namespaceDeclaration.prefix().toString());
4088  }
4089  writeStartElement(reader.namespaceUri().toString(), reader.name().toString());
4090  writeAttributes(reader.attributes());
4091  } break;
4093  writeEndElement();
4094  break;
4096  if (reader.isCDATA())
4097  writeCDATA(reader.text().toString());
4098  else
4099  writeCharacters(reader.text().toString());
4100  break;
4102  writeComment(reader.text().toString());
4103  break;
4104  case QXmlStreamReader::DTD:
4105  writeDTD(reader.text().toString());
4106  break;
4108  writeEntityReference(reader.name().toString());
4109  break;
4112  reader.processingInstructionData().toString());
4113  break;
4114  default:
4116  qWarning("QXmlStreamWriter: writeCurrentToken() with invalid state.");
4117  break;
4118  }
4119 }
4120 
4153 #endif // QT_NO_XMLSTREAMREADER
4154 #endif // QT_NO_XMLSTREAMWRITER
4155 
4157 
4158 #endif // QT_NO_XMLSTREAM
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.cpp:6448
Error error() const
Returns the type of the current error, or NoError if no error occurred.
uint resolveCharRef(int symbolIndex)
QXmlStreamStringRef m_namespaceUri
Definition: qxmlstream.h:136
QXmlStreamEntityDeclaration & operator=(const QXmlStreamEntityDeclaration &)
Assigns other to this entity declaration.
QBool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.h:904
double d
Definition: qnumeric_p.h:62
const T & top() const
Definition: qxmlstream_p.h:661
QString toString() const
Returns a copy of the string reference as a QString object.
Definition: qstring.cpp:8653
void checkPublicLiteral(const QStringRef &publicId)
void clear()
Clears the contents of the string reference by making it null and empty.
Definition: qstring.h:1167
The QXmlStreamWriter class provides an XML writer with a simple streaming API.
Definition: qxmlstream.h:416
int autoFormattingIndent() const
the number of spaces or tabs used for indentation when auto-formatting is enabled.
QXmlStreamWriter * q_ptr
QXmlStreamWriterPrivate(QXmlStreamWriter *q)
QXmlStreamStringRef m_name
Definition: qxmlstream.h:228
QStringRef appendTo(QString *string) const
Appends the string reference to string, and returns a new reference to the combined string data...
Definition: qstring.cpp:8828
Category
This enum maps the Unicode character categories.
Definition: qchar.h:106
unsigned char c[8]
Definition: qnumeric_p.h:62
~QXmlStreamWriter()
Destructor.
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
bool finishStartElement(bool contents=true)
QXmlStreamAttribute & operator=(const QXmlStreamAttribute &)
Assigns other to this attribute.
bool autoFormatting() const
This property controls whether or not the stream writer automatically formats the generated XML data...
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
qint64 characterOffset() const
Returns the current character offset, starting with 0.
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
qint64 lineNumber() const
Returns the current line number, starting with 1.
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qchar.h:251
QXmlStreamSimpleStack< DtdAttribute > dtdAttributes
Definition: qxmlstream_p.h:831
static const char QXmlStreamReader_tokenTypeString_string[]
Definition: qxmlstream.cpp:749
QXmlStreamAttributes attributes
Definition: qxmlstream_p.h:808
void setEntityResolver(QXmlStreamEntityResolver *resolver)
Makes resolver the new entityResolver().
Definition: qxmlstream.cpp:248
The QXmlStreamEntityDeclaration class represents a DTD entity declaration.
Definition: qxmlstream.h:251
bool isCDATA() const
Returns true if the reader reports characters that stem from a CDATA section; otherwise returns false...
QXmlStreamEntityDeclarations entityDeclarations() const
If the state() is DTD , this function returns the DTD&#39;s unparsed (external) entity declarations...
QHash< QString, Entity > entityHash
Definition: qxmlstream_p.h:770
Q_CORE_EXPORT void qFree(void *ptr)
Definition: qmalloc.cpp:58
QString & replace(int i, int len, QChar after)
Definition: qstring.cpp:2005
#define at(className, varName)
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
bool scanString(const char *str, short tokenToInject, bool requireSpace=true)
QXmlStreamStringRef m_notationName
Definition: qxmlstream.h:252
QString resolveUndeclaredEntity(const QString &name)
Definition: qxmlstream.cpp:224
The QXmlStreamNotationDeclaration class represents a DTD notation declaration.
Definition: qxmlstream.h:227
QXmlStreamEntityResolver * entityResolver
Definition: qxmlstream_p.h:999
QStringRef value() const
Returns the attribute&#39;s value.
Definition: qxmlstream.h:156
bool isEndElement() const
Returns true if tokenType() equals EndElement ; otherwise returns false.
Definition: qxmlstream.h:338
QXmlStreamStringRef m_publicId
Definition: qxmlstream.h:228
~QXmlStreamNamespaceDeclaration()
Destructs this namespace declaration.
QTextDecoder * makeDecoder() const
Creates a QTextDecoder which stores enough state to decode chunks of char * data to create chunks of ...
void raiseError(const QString &message=QString())
Raises a custom error with an optional error message.
void writeEndDocument()
Closes all remaining open start elements and writes a newline.
QXmlStreamSimpleStack< Attribute > attributeStack
Definition: qxmlstream_p.h:918
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
QStringRef name() const
Returns the local name of a StartElement, EndElement, or an EntityReference.
long ASN1_INTEGER_get ASN1_INTEGER * a
Q_CORE_EXPORT void * qRealloc(void *ptr, size_t size)
Definition: qmalloc.cpp:63
QTextEncoder * encoder
void parseEntity(const QString &value)
Definition: qxmlstream.cpp:895
virtual ~QXmlStreamEntityResolver()
Destroys the entity resolver.
Definition: qxmlstream.cpp:195
The QBuffer class provides a QIODevice interface for a QByteArray.
Definition: qbuffer.h:57
bool atEnd() const
Returns true if the reader has read until the end of the XML document, or if an error() has occurred ...
Definition: qxmlstream.cpp:590
The QString class provides a Unicode character string.
Definition: qstring.h:83
void injectToken(ushort tokenToInject)
Definition: qxmlstream_p.h:969
bool scanUntil(const char *str, short tokenToInject=-1)
Scans characters until str is encountered, and validates the characters as according to the Char[2] p...
Q_DECL_CONSTEXPR T qAbs(const T &t)
Definition: qglobal.h:1201
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
TokenType
This enum specifies the type of token the reader just read.
Definition: qxmlstream.h:293
void writeDTD(const QString &dtd)
Writes a DTD section.
QStringRef prefix() const
Returns the prefix of a StartElement or EndElement.
#define Q_D(Class)
Definition: qglobal.h:2482
void putStringLiteral(const QString &s)
QStringRef qualifiedName() const
Returns the attribute&#39;s qualified name.
Definition: qxmlstream.h:150
static QByteArray qualifiedName(const QMetaEnum &e)
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
void writeEntityReference(const QString &name)
Writes the entity reference name to the stream, as "&\a{name};".
QXmlStreamStringRef m_value
Definition: qxmlstream.h:136
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
bool isSpace() const
Returns true if the character is a separator character (Separator_* categories); otherwise returns fa...
Definition: qchar.cpp:609
Category category() const
Returns the character&#39;s category.
Definition: qchar.cpp:853
void resize(int size)
Sets the size of the vector to size.
Definition: qvector.h:342
#define Q_Q(Class)
Definition: qglobal.h:2483
QStringRef value(const QString &namespaceUri, const QString &name) const
Returns the value of the attribute name in the namespace described with namespaceUri, or an empty string reference if the attribute is not defined.
QXmlStreamStringRef m_name
Definition: qxmlstream.h:136
void writeEscaped(const QString &, bool escapeWhitespace=false)
qint64 read(char *data, qint64 maxlen)
Reads at most maxSize bytes from the device into data, and returns the number of bytes read...
Definition: qiodevice.cpp:791
Value & sym(int index) const
Definition: qxmlstream_p.h:905
QXmlStreamNotationDeclaration()
Creates an empty notation declaration.
const QChar * constData() const
Same as unicode().
Definition: qstring.h:1159
The QXmlStreamAttribute class represents a single XML attribute.
Definition: qxmlstream.h:135
void writeCDATA(const QString &text)
Writes text as CDATA section.
void reserve(int size)
Attempts to allocate memory for at least size characters.
Definition: qstring.h:881
QStringRef namespaceUri() const
Returns the namespaceUri of a StartElement or EndElement.
unsigned char uchar
Definition: qglobal.h:994
void setCodec(QTextCodec *codec)
Sets the codec for this stream to codec.
virtual QString resolveEntity(const QString &publicId, const QString &systemId)
Definition: qxmlstream.cpp:203
TokenType tokenType() const
Returns the type of the current token.
Definition: qxmlstream.cpp:656
int size() const
Returns the number of characters referred to by the string reference.
Definition: qstring.h:1114
QXmlStreamReader()
Constructs a stream reader.
Definition: qxmlstream.cpp:406
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QScopedPointer< QXmlStreamReaderPrivate > d_ptr
Definition: qxmlstream.h:407
void writeAttribute(const QString &qualifiedName, const QString &value)
Writes an attribute with qualifiedName and value.
QIODevice * device() const
Returns the current device associated with the QXmlStreamWriter, or 0 if no device has been assigned...
int fastScanContentCharList()
Used for text nodes essentially.
void writeNamespaceDeclaration(const NamespaceDeclaration &namespaceDeclaration)
void raiseError(QXmlStreamReader::Error error, const QString &message=QString())
The QXmlStreamEntityResolver class provides an entity resolver for a QXmlStreamReader.
Definition: qxmlstream.h:281
QHash< QString, Entity > parameterEntityHash
Definition: qxmlstream_p.h:771
QXmlStreamSimpleStack< NamespaceDeclaration > namespaceDeclarations
Definition: qxmlstream_p.h:697
void clear()
Removes all the elements from the vector and releases the memory used by the vector.
Definition: qvector.h:347
QXmlStreamSimpleStack< uint > putStack
Definition: qxmlstream_p.h:756
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
void skipCurrentElement()
Reads until the end of the current element, skipping any child nodes.
Definition: qxmlstream.cpp:706
QXmlStreamStringRef m_systemId
Definition: qxmlstream.h:228
void writeStartElement(const QString &namespaceUri, const QString &name)
ReadElementTextBehaviour
This enum specifies the different behaviours of readElementText().
Definition: qxmlstream.h:357
const char * name
void writeNamespace(const QString &namespaceUri, const QString &prefix=QString())
Writes a namespace declaration for namespaceUri with prefix.
QXmlStreamStringRef m_systemId
Definition: qxmlstream.h:252
The QTextEncoder class provides a state-based encoder.
Definition: qtextcodec.h:160
QXmlStreamStringRef m_name
Definition: qxmlstream.h:252
Q_CORE_EXPORT void qWarning(const char *,...)
bool isEmpty() const
Returns true if the string reference has no characters; otherwise returns false.
Definition: qstring.h:1169
virtual QString resolveUndeclaredEntity(const QString &name)
Resolves the undeclared entity name and returns its replacement text.
Definition: qxmlstream.cpp:217
QXmlStreamNotationDeclaration & operator=(const QXmlStreamNotationDeclaration &)
Assigns other to this notation declaration.
static const char NtBg
static const char * data(const QByteArray &arr)
unsigned int uint
Definition: qglobal.h:996
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
void indent(int level)
QStringRef namespaceUri() const
Returns the namespaceUri.
Definition: qxmlstream.h:216
int mib
static const char NotN
static QTextCodec * codecForMib(int mib)
Returns the QTextCodec which matches the MIBenum mib.
QStringRef prefix() const
Returns the prefix.
Definition: qxmlstream.h:215
NamespaceDeclaration & findNamespace(const QString &namespaceUri, bool writeDeclaration=false, bool noDefault=false)
void addExtraNamespaceDeclaration(const QXmlStreamNamespaceDeclaration &extraNamespaceDeclaraction)
Adds an extraNamespaceDeclaration.
QXmlStreamStringRef m_qualifiedName
Definition: qxmlstream.h:136
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
QStringRef name() const
Returns the attribute&#39;s local name.
Definition: qxmlstream.h:149
__int64 qint64
Definition: qglobal.h:942
QXmlStreamNotationDeclarations publicNotationDeclarations
Definition: qxmlstream_p.h:838
QXmlStreamStringRef m_namespaceUri
Definition: qxmlstream.h:205
void writeCharacters(const QString &text)
Writes text.
QStringRef documentEncoding() const
If the state() is StartDocument , this function returns the encoding string as specified in the XML d...
int count() const
Definition: qstring.h:103
QIODevice * device() const
Returns the current device associated with the QXmlStreamReader, or 0 if no device has been assigned...
Definition: qxmlstream.cpp:507
The QStringRef class provides a thin wrapper around QString substrings.
Definition: qstring.h:1099
NamespaceDeclaration emptyNamespace
QXmlStreamReader::Error error
Definition: qxmlstream_p.h:797
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
bool isStartElement() const
Returns true if tokenType() equals StartElement ; otherwise returns false.
Definition: qxmlstream.h:337
~QXmlStreamReader()
Destructs the reader.
Definition: qxmlstream.cpp:467
TokenType readNext()
Reads the next token and returns its type.
Definition: qxmlstream.cpp:623
QXmlStreamEntityDeclaration()
Creates an empty entity declaration.
int length() const
Same as size().
Definition: qbytearray.h:356
QStringRef qualifiedName() const
Returns the qualified name of a StartElement or EndElement;.
The QXmlStreamNamespaceDeclaration class represents a namespace declaration.
Definition: qxmlstream.h:204
void resize(int size)
Sets the size of the string to size characters.
Definition: qstring.cpp:1353
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
QXmlStreamWriter()
Constructs a stream writer.
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition: qstring.h:505
QStringRef dtdPublicId() const
If the state() is DTD , this function returns the DTD&#39;s public identifier.
QStringRef namespaceForPrefix(const QStringRef &prefix)
bool hasFailure() const
Determines whether the decoder encountered a failure while decoding the input.
#define Q_CHECK_PTR(p)
Definition: qglobal.h:1853
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
QXmlStreamReader::TokenType type
Definition: qxmlstream_p.h:796
QString & append(QChar c)
Definition: qstring.cpp:1777
bool readNextStartElement()
Reads until the next start element within the current element.
Definition: qxmlstream.cpp:684
QStringRef symName(int index)
Definition: qxmlstream_p.h:924
QByteArray autoFormattingIndent
NameChar
void writeStartDocument()
This is an overloaded member function, provided for convenience. It differs from the above function o...
void setAutoFormattingIndent(int spacesOrTabs)
int count(char c) const
Returns the number of occurrences of character ch in the byte array.
void writeEndElement()
Closes the previous start element.
void putReplacement(const QString &s)
QStringRef documentVersion() const
If the state() is StartDocument , this function returns the version string as specified in the XML de...
The QXmlStreamAttributes class represents a vector of QXmlStreamAttribute.
Definition: qxmlstream.h:169
void clear()
Clears the contents of the string and makes it empty.
Definition: qstring.h:723
unsigned short ushort
Definition: qglobal.h:995
void writeCurrentToken(const QXmlStreamReader &reader)
Writes the current state of the reader.
void writeDefaultNamespace(const QString &namespaceUri)
Writes a default namespace declaration for namespaceUri.
QXmlStreamNamespaceDeclaration()
Creates an empty namespace declaration.
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
int fastScanName(int *prefix=0)
QXmlStreamSimpleStack< NotationDeclaration > notationDeclarations
Definition: qxmlstream_p.h:837
Error
This enum specifies different error cases.
Definition: qxmlstream.h:385
qint64 columnNumber() const
Returns the current column number, starting with 0.
void reserve(int extraCapacity)
Definition: qxmlstream_p.h:651
QXmlStreamStringRef m_value
Definition: qxmlstream.h:252
void setDevice(QIODevice *device)
Sets the current device to device.
Definition: qxmlstream.cpp:489
int key
static const char nameCharTable[128]
void addData(const QByteArray &data)
Adds more data for the reader to read.
Definition: qxmlstream.cpp:520
void resize(int size)
Sets the size of the byte array to size bytes.
void putString(const QString &s, int from=0)
QXmlStreamNamespaceDeclarations namespaceDeclarations() const
If the state() is StartElement , this function returns the element&#39;s namespace declarations.
void writeTextElement(const QString &qualifiedName, const QString &text)
This is an overloaded member function, provided for convenience. It differs from the above function o...
void setDevice(QIODevice *device)
Sets the current device to device.
QString toUnicode(const char *chars, int len)
Converts the first len bytes in chars to Unicode, returning the result.
uint toUInt(bool *ok=0, int base=10) const
Returns the string converted to an unsigned int using base base, which is 10 by default and must be b...
Definition: qstring.cpp:6120
QXmlStreamStringRef m_prefix
Definition: qxmlstream.h:205
void writeEmptyElement(const QString &qualifiedName)
Writes an empty element with qualified name qualifiedName.
NamespaceDeclaration namespaceDeclaration
Definition: qxmlstream_p.h:690
static QTextCodec * codecForName(const QByteArray &name)
Searches all installed QTextCodec objects and returns the one which best matches name; the match is c...
QXmlStreamStringRef m_publicId
Definition: qxmlstream.h:252
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
QStringRef processingInstructionData() const
Returns the data of a ProcessingInstruction.
bool isWhitespace() const
Returns true if the reader reports characters that only consist of white-space; otherwise returns fal...
static NameChar fastDetermineNameChar(QChar ch)
static int t_action(int state, int token)
Definition: qxmlstream_p.h:152
QStringRef addToStringStorage(const QStringRef &s)
Definition: qxmlstream_p.h:702
bool namespaceProcessing() const
This property controls whether or not the stream reader processes namespaces.
Definition: qxmlstream.cpp:788
void write(const QStringRef &)
QStringRef dtdSystemId() const
If the state() is DTD , this function returns the DTD&#39;s system identifier.
QScopedPointer< QXmlStreamWriterPrivate > d_ptr
Definition: qxmlstream.h:482
void setAutoFormatting(bool)
static const char Begi
QXmlStreamAttribute()
Creates an empty attribute.
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:9788
void writeProcessingInstruction(const QString &target, const QString &data=QString())
Writes an XML processing instruction with target and data, where data must not contain the sequence "...
The QXmlStreamReader class provides a fast parser for reading well-formed XML via a simple streaming ...
Definition: qxmlstream.h:290
QTextEncoder * makeEncoder() const
Creates a QTextEncoder which stores enough state to encode chunks of Unicode data as char * data...
void reserve(int size)
Attempts to allocate memory for at least size elements.
Definition: qvector.h:339
QXmlStreamReaderPrivate(QXmlStreamReader *q)
Definition: qxmlstream.cpp:819
QStringRef processingInstructionTarget() const
Returns the target of a ProcessingInstruction.
static Entity createLiteral(const QString &entity)
Definition: qxmlstream_p.h:761
bool isNull() const
Returns true if string() returns a null pointer or a pointer to a null string; otherwise returns true...
Definition: qstring.h:1170
void raiseWellFormedError(const QString &message)
bool hasError() const
Returns true if the stream failed to write to the underlying device; otherwise returns false...
~QXmlStreamNotationDeclaration()
Destructs this notation declaration.
qint64 write(const char *data, qint64 len)
Writes at most maxSize bytes of data from data to the device.
Definition: qiodevice.cpp:1342
QXmlStreamEntityResolver * entityResolver() const
Returns the entity resolver, or 0 if there is no entity resolver.
Definition: qxmlstream.cpp:264
The QTextCodec class provides conversions between text encodings.
Definition: qtextcodec.h:62
QStringRef text() const
Returns the text of Characters , Comment , DTD , or EntityReference.
bool isStandaloneDocument() const
Returns true if this document has been declared standalone in the XML declaration; otherwise returns ...
QString errorString() const
Returns the error message that was set with raiseError().
QXmlStreamReaderPrivate * entityParser
Definition: qxmlstream_p.h:975
QStringRef dtdName() const
If the state() is DTD , this function returns the DTD&#39;s name.
char at(int i) const
Returns the character at index position i in the byte array.
Definition: qbytearray.h:413
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
Definition: qstring.cpp:3796
void setNamespaceProcessing(bool)
Definition: qxmlstream.cpp:782
void writeComment(const QString &text)
Writes text as XML comment, where text must not contain the forbidden sequence "--" or end with "-"...
The QIODevice class is the base interface class of all I/O devices in Qt.
Definition: qiodevice.h:66
QXmlStreamSimpleStack< Tag > tagStack
Definition: qxmlstream_p.h:721
void putReplacementInAttributeValue(const QString &s)
QXmlStreamNamespaceDeclaration & operator=(const QXmlStreamNamespaceDeclaration &)
Assigns other to this namespace declaration.
QStringRef symString(int index)
Definition: qxmlstream_p.h:920
QTextDecoder * decoder
Definition: qxmlstream_p.h:789
void append(const QString &namespaceUri, const QString &name, const QString &value)
Appends a new attribute with name in the namespace described with namespaceUri, and value value...
QString & insert(int i, QChar c)
Definition: qstring.cpp:1671
QString readElementText()
QXmlStreamEntityDeclarations publicEntityDeclarations
Definition: qxmlstream_p.h:859
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
~QXmlStreamAttribute()
Destructs an attribute.
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
QXmlStreamAttributes attributes() const
Returns the attributes of a StartElement.
QXmlStreamNamespaceDeclarations publicNamespaceDeclarations
Definition: qxmlstream_p.h:839
void writeAttributes(const QXmlStreamAttributes &attributes)
Writes the attribute vector attributes.
void clear()
Removes any device() or data from the reader and resets its internal state to the initial state...
Definition: qxmlstream.cpp:564
void clear()
Clears the contents of the byte array and makes it empty.
QXmlStreamSimpleStack< EntityDeclaration > entityDeclarations
Definition: qxmlstream_p.h:858
QString tokenString() const
Returns the reader&#39;s current token as string.
Definition: qxmlstream.cpp:798
~QXmlStreamEntityDeclaration()
Destructs this entity declaration.
QXmlStreamNotationDeclarations notationDeclarations() const
If the state() is DTD , this function returns the DTD&#39;s notation declarations.
void writeStartElement(const QString &qualifiedName)
This is an overloaded member function, provided for convenience. It differs from the above function o...
#define text
Definition: qobjectdefs.h:80
QStringRef symPrefix(int index)
Definition: qxmlstream_p.h:932
static bool isEncName(const QString &encName)
Determines whether encName is a valid instance of production [81]EncName in the XML 1...
Definition: qxmlutils.cpp:234
QByteArray fromUnicode(const QString &str)
Converts the Unicode string str into an encoded QByteArray.
static const char *const spell[]
Definition: qxmlstream_p.h:134
QTextCodec * codec() const
Returns the codec that is currently assigned to the stream.
void addExtraNamespaceDeclarations(const QXmlStreamNamespaceDeclarations &extraNamespaceDeclaractions)
Adds a vector of declarations specified by extraNamespaceDeclarations.
static const short QXmlStreamReader_tokenTypeString_indices[]
Definition: qxmlstream.cpp:762
void write(const char(&s)[N])
#define forever
This macro is provided for convenience for writing infinite loops.
Definition: qglobal.h:2452
QStringRef namespaceUri() const
Returns the attribute&#39;s resolved namespaceUri, or an empty string reference if the attribute does not...
Definition: qxmlstream.h:148
void write(const QString &)