Warning, file /include/QtCore/qxmlstream.h was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004 #ifndef QXMLSTREAM_H
0005 #define QXMLSTREAM_H
0006
0007 #include <QtCore/qiodevice.h>
0008
0009 #if QT_CONFIG(xmlstream)
0010
0011 #include <QtCore/qlist.h>
0012 #include <QtCore/qscopedpointer.h>
0013 #include <QtCore/qstring.h>
0014
0015 QT_BEGIN_NAMESPACE
0016
0017 namespace QtPrivate {
0018
0019 class QXmlString {
0020 QStringPrivate m_string;
0021 public:
0022 QXmlString(QStringPrivate &&d) : m_string(std::move(d)) {}
0023 QXmlString(const QString &s) : m_string(s.data_ptr()) {}
0024 QXmlString & operator=(const QString &s) { m_string = s.data_ptr(); return *this; }
0025 QXmlString & operator=(QString &&s) { m_string.swap(s.data_ptr()); return *this; }
0026 inline constexpr QXmlString() {}
0027
0028 void swap(QXmlString &other) noexcept
0029 {
0030 m_string.swap(other.m_string);
0031 }
0032
0033 inline operator QStringView() const { return QStringView(m_string.data(), m_string.size); }
0034 inline qsizetype size() const { return m_string.size; }
0035 };
0036
0037 }
0038 Q_DECLARE_SHARED(QtPrivate::QXmlString)
0039
0040
0041 class QXmlStreamReaderPrivate;
0042 class QXmlStreamAttributes;
0043 class Q_CORE_EXPORT QXmlStreamAttribute {
0044 QtPrivate::QXmlString m_name, m_namespaceUri, m_qualifiedName, m_value;
0045 uint m_isDefault : 1;
0046 friend class QXmlStreamReaderPrivate;
0047 friend class QXmlStreamAttributes;
0048 public:
0049 QXmlStreamAttribute();
0050 QXmlStreamAttribute(const QString &qualifiedName, const QString &value);
0051 QXmlStreamAttribute(const QString &namespaceUri, const QString &name, const QString &value);
0052
0053 inline QStringView namespaceUri() const { return m_namespaceUri; }
0054 inline QStringView name() const { return m_name; }
0055 inline QStringView qualifiedName() const { return m_qualifiedName; }
0056 inline QStringView prefix() const {
0057 return QStringView(m_qualifiedName).left(qMax(0, m_qualifiedName.size() - m_name.size() - 1));
0058 }
0059 inline QStringView value() const { return m_value; }
0060 inline bool isDefault() const { return m_isDefault; }
0061 inline bool operator==(const QXmlStreamAttribute &other) const {
0062 return (value() == other.value()
0063 && (namespaceUri().isNull() ? (qualifiedName() == other.qualifiedName())
0064 : (namespaceUri() == other.namespaceUri() && name() == other.name())));
0065 }
0066 inline bool operator!=(const QXmlStreamAttribute &other) const
0067 { return !operator==(other); }
0068 };
0069
0070 Q_DECLARE_TYPEINFO(QXmlStreamAttribute, Q_RELOCATABLE_TYPE);
0071
0072
0073
0074 class QXmlStreamAttributes : public QList<QXmlStreamAttribute>
0075 {
0076 public:
0077 inline QXmlStreamAttributes() {}
0078 #if QT_CORE_REMOVED_SINCE(6, 6)
0079 Q_CORE_EXPORT QStringView value(const QString &namespaceUri, const QString &name) const;
0080 Q_CORE_EXPORT QStringView value(const QString &namespaceUri, QLatin1StringView name) const;
0081 Q_CORE_EXPORT QStringView value(QLatin1StringView namespaceUri, QLatin1StringView name) const;
0082 Q_CORE_EXPORT QStringView value(const QString &qualifiedName) const;
0083 Q_CORE_EXPORT QStringView value(QLatin1StringView qualifiedName) const;
0084 #endif
0085 Q_CORE_EXPORT QStringView value(QAnyStringView namespaceUri, QAnyStringView name) const noexcept;
0086 Q_CORE_EXPORT QStringView value(QAnyStringView qualifiedName) const noexcept;
0087
0088 Q_CORE_EXPORT void append(const QString &namespaceUri, const QString &name, const QString &value);
0089 Q_CORE_EXPORT void append(const QString &qualifiedName, const QString &value);
0090
0091 bool hasAttribute(QAnyStringView qualifiedName) const
0092 {
0093 return !value(qualifiedName).isNull();
0094 }
0095
0096 bool hasAttribute(QAnyStringView namespaceUri, QAnyStringView name) const
0097 {
0098 return !value(namespaceUri, name).isNull();
0099 }
0100
0101 using QList<QXmlStreamAttribute>::append;
0102 };
0103
0104 class Q_CORE_EXPORT QXmlStreamNamespaceDeclaration {
0105 QtPrivate::QXmlString m_prefix, m_namespaceUri;
0106
0107 friend class QXmlStreamReaderPrivate;
0108 public:
0109 QXmlStreamNamespaceDeclaration();
0110 QXmlStreamNamespaceDeclaration(const QString &prefix, const QString &namespaceUri);
0111
0112 inline QStringView prefix() const { return m_prefix; }
0113 inline QStringView namespaceUri() const { return m_namespaceUri; }
0114 inline bool operator==(const QXmlStreamNamespaceDeclaration &other) const {
0115 return (prefix() == other.prefix() && namespaceUri() == other.namespaceUri());
0116 }
0117 inline bool operator!=(const QXmlStreamNamespaceDeclaration &other) const
0118 { return !operator==(other); }
0119 };
0120
0121 Q_DECLARE_TYPEINFO(QXmlStreamNamespaceDeclaration, Q_RELOCATABLE_TYPE);
0122 typedef QList<QXmlStreamNamespaceDeclaration> QXmlStreamNamespaceDeclarations;
0123
0124 class Q_CORE_EXPORT QXmlStreamNotationDeclaration {
0125 QtPrivate::QXmlString m_name, m_systemId, m_publicId;
0126
0127 friend class QXmlStreamReaderPrivate;
0128 public:
0129 QXmlStreamNotationDeclaration();
0130
0131 inline QStringView name() const { return m_name; }
0132 inline QStringView systemId() const { return m_systemId; }
0133 inline QStringView publicId() const { return m_publicId; }
0134 inline bool operator==(const QXmlStreamNotationDeclaration &other) const {
0135 return (name() == other.name() && systemId() == other.systemId()
0136 && publicId() == other.publicId());
0137 }
0138 inline bool operator!=(const QXmlStreamNotationDeclaration &other) const
0139 { return !operator==(other); }
0140 };
0141
0142 Q_DECLARE_TYPEINFO(QXmlStreamNotationDeclaration, Q_RELOCATABLE_TYPE);
0143 typedef QList<QXmlStreamNotationDeclaration> QXmlStreamNotationDeclarations;
0144
0145 class Q_CORE_EXPORT QXmlStreamEntityDeclaration {
0146 QtPrivate::QXmlString m_name, m_notationName, m_systemId, m_publicId, m_value;
0147
0148 friend class QXmlStreamReaderPrivate;
0149 public:
0150 QXmlStreamEntityDeclaration();
0151
0152 inline QStringView name() const { return m_name; }
0153 inline QStringView notationName() const { return m_notationName; }
0154 inline QStringView systemId() const { return m_systemId; }
0155 inline QStringView publicId() const { return m_publicId; }
0156 inline QStringView value() const { return m_value; }
0157 inline bool operator==(const QXmlStreamEntityDeclaration &other) const {
0158 return (name() == other.name()
0159 && notationName() == other.notationName()
0160 && systemId() == other.systemId()
0161 && publicId() == other.publicId()
0162 && value() == other.value());
0163 }
0164 inline bool operator!=(const QXmlStreamEntityDeclaration &other) const
0165 { return !operator==(other); }
0166 };
0167
0168 Q_DECLARE_TYPEINFO(QXmlStreamEntityDeclaration, Q_RELOCATABLE_TYPE);
0169 typedef QList<QXmlStreamEntityDeclaration> QXmlStreamEntityDeclarations;
0170
0171 class Q_CORE_EXPORT QXmlStreamEntityResolver
0172 {
0173 public:
0174 virtual ~QXmlStreamEntityResolver();
0175 virtual QString resolveEntity(const QString& publicId, const QString& systemId);
0176 virtual QString resolveUndeclaredEntity(const QString &name);
0177 };
0178
0179 #if QT_CONFIG(xmlstreamreader)
0180 class Q_CORE_EXPORT QXmlStreamReader
0181 {
0182 QDOC_PROPERTY(bool namespaceProcessing READ namespaceProcessing WRITE setNamespaceProcessing)
0183 public:
0184 enum TokenType {
0185 NoToken = 0,
0186 Invalid,
0187 StartDocument,
0188 EndDocument,
0189 StartElement,
0190 EndElement,
0191 Characters,
0192 Comment,
0193 DTD,
0194 EntityReference,
0195 ProcessingInstruction
0196 };
0197
0198
0199 QXmlStreamReader();
0200 explicit QXmlStreamReader(QIODevice *device);
0201 #if QT_CORE_REMOVED_SINCE(6, 5)
0202 explicit QXmlStreamReader(const QByteArray &data);
0203 explicit QXmlStreamReader(const QString &data);
0204 explicit QXmlStreamReader(const char * data);
0205 #endif
0206 Q_WEAK_OVERLOAD
0207 explicit QXmlStreamReader(const QByteArray &data)
0208 : QXmlStreamReader(data, PrivateConstructorTag{}) { }
0209 explicit QXmlStreamReader(QAnyStringView data);
0210 ~QXmlStreamReader();
0211
0212 void setDevice(QIODevice *device);
0213 QIODevice *device() const;
0214 #if QT_CORE_REMOVED_SINCE(6, 5)
0215 void addData(const QByteArray &data);
0216 void addData(const QString &data);
0217 void addData(const char *data);
0218 #endif
0219 Q_WEAK_OVERLOAD
0220 void addData(const QByteArray &data) { addDataImpl(data); }
0221 void addData(QAnyStringView data);
0222 void clear();
0223
0224
0225 bool atEnd() const;
0226 TokenType readNext();
0227
0228 bool readNextStartElement();
0229 void skipCurrentElement();
0230
0231 TokenType tokenType() const;
0232 QString tokenString() const;
0233
0234 void setNamespaceProcessing(bool);
0235 bool namespaceProcessing() const;
0236
0237 inline bool isStartDocument() const { return tokenType() == StartDocument; }
0238 inline bool isEndDocument() const { return tokenType() == EndDocument; }
0239 inline bool isStartElement() const { return tokenType() == StartElement; }
0240 inline bool isEndElement() const { return tokenType() == EndElement; }
0241 inline bool isCharacters() const { return tokenType() == Characters; }
0242 bool isWhitespace() const;
0243 bool isCDATA() const;
0244 inline bool isComment() const { return tokenType() == Comment; }
0245 inline bool isDTD() const { return tokenType() == DTD; }
0246 inline bool isEntityReference() const { return tokenType() == EntityReference; }
0247 inline bool isProcessingInstruction() const { return tokenType() == ProcessingInstruction; }
0248
0249 bool isStandaloneDocument() const;
0250 bool hasStandaloneDeclaration() const;
0251 QStringView documentVersion() const;
0252 QStringView documentEncoding() const;
0253
0254 qint64 lineNumber() const;
0255 qint64 columnNumber() const;
0256 qint64 characterOffset() const;
0257
0258 QXmlStreamAttributes attributes() const;
0259
0260 enum ReadElementTextBehaviour {
0261 ErrorOnUnexpectedElement,
0262 IncludeChildElements,
0263 SkipChildElements
0264 };
0265 QString readElementText(ReadElementTextBehaviour behaviour = ErrorOnUnexpectedElement);
0266
0267 QStringView name() const;
0268 QStringView namespaceUri() const;
0269 QStringView qualifiedName() const;
0270 QStringView prefix() const;
0271
0272 QStringView processingInstructionTarget() const;
0273 QStringView processingInstructionData() const;
0274
0275 QStringView text() const;
0276
0277 QXmlStreamNamespaceDeclarations namespaceDeclarations() const;
0278 void addExtraNamespaceDeclaration(const QXmlStreamNamespaceDeclaration &extraNamespaceDeclaraction);
0279 void addExtraNamespaceDeclarations(const QXmlStreamNamespaceDeclarations &extraNamespaceDeclaractions);
0280 QXmlStreamNotationDeclarations notationDeclarations() const;
0281 QXmlStreamEntityDeclarations entityDeclarations() const;
0282 QStringView dtdName() const;
0283 QStringView dtdPublicId() const;
0284 QStringView dtdSystemId() const;
0285
0286 int entityExpansionLimit() const;
0287 void setEntityExpansionLimit(int limit);
0288
0289 enum Error {
0290 NoError,
0291 UnexpectedElementError,
0292 CustomError,
0293 NotWellFormedError,
0294 PrematureEndOfDocumentError
0295 };
0296 void raiseError(const QString& message = QString());
0297 QString errorString() const;
0298 Error error() const;
0299
0300 inline bool hasError() const
0301 {
0302 return error() != NoError;
0303 }
0304
0305 void setEntityResolver(QXmlStreamEntityResolver *resolver);
0306 QXmlStreamEntityResolver *entityResolver() const;
0307
0308 private:
0309 struct PrivateConstructorTag { };
0310 QXmlStreamReader(const QByteArray &data, PrivateConstructorTag);
0311 void addDataImpl(const QByteArray &data);
0312
0313 Q_DISABLE_COPY(QXmlStreamReader)
0314 Q_DECLARE_PRIVATE(QXmlStreamReader)
0315 QScopedPointer<QXmlStreamReaderPrivate> d_ptr;
0316
0317 };
0318 #endif
0319
0320 #if QT_CONFIG(xmlstreamwriter)
0321
0322 class QXmlStreamWriterPrivate;
0323
0324 class Q_CORE_EXPORT QXmlStreamWriter
0325 {
0326 QDOC_PROPERTY(bool autoFormatting READ autoFormatting WRITE setAutoFormatting)
0327 QDOC_PROPERTY(int autoFormattingIndent READ autoFormattingIndent WRITE setAutoFormattingIndent)
0328 public:
0329 QXmlStreamWriter();
0330 explicit QXmlStreamWriter(QIODevice *device);
0331 explicit QXmlStreamWriter(QByteArray *array);
0332 explicit QXmlStreamWriter(QString *string);
0333 ~QXmlStreamWriter();
0334
0335 void setDevice(QIODevice *device);
0336 QIODevice *device() const;
0337
0338 void setAutoFormatting(bool);
0339 bool autoFormatting() const;
0340
0341 void setAutoFormattingIndent(int spacesOrTabs);
0342 int autoFormattingIndent() const;
0343
0344 #if QT_CORE_REMOVED_SINCE(6,5)
0345 void writeAttribute(const QString &qualifiedName, const QString &value);
0346 void writeAttribute(const QString &namespaceUri, const QString &name, const QString &value);
0347 #endif
0348 void writeAttribute(QAnyStringView qualifiedName, QAnyStringView value);
0349 void writeAttribute(QAnyStringView namespaceUri, QAnyStringView name, QAnyStringView value);
0350
0351 void writeAttribute(const QXmlStreamAttribute& attribute);
0352 void writeAttributes(const QXmlStreamAttributes& attributes);
0353
0354 #if QT_CORE_REMOVED_SINCE(6,5)
0355 void writeCDATA(const QString &text);
0356 void writeCharacters(const QString &text);
0357 void writeComment(const QString &text);
0358
0359 void writeDTD(const QString &dtd);
0360
0361 void writeEmptyElement(const QString &qualifiedName);
0362 void writeEmptyElement(const QString &namespaceUri, const QString &name);
0363
0364 void writeTextElement(const QString &qualifiedName, const QString &text);
0365 void writeTextElement(const QString &namespaceUri, const QString &name, const QString &text);
0366 #endif
0367 void writeCDATA(QAnyStringView text);
0368 void writeCharacters(QAnyStringView text);
0369 void writeComment(QAnyStringView text);
0370
0371 void writeDTD(QAnyStringView dtd);
0372
0373 void writeEmptyElement(QAnyStringView qualifiedName);
0374 void writeEmptyElement(QAnyStringView namespaceUri, QAnyStringView name);
0375
0376 void writeTextElement(QAnyStringView qualifiedName, QAnyStringView text);
0377 void writeTextElement(QAnyStringView namespaceUri, QAnyStringView name, QAnyStringView text);
0378
0379
0380 void writeEndDocument();
0381 void writeEndElement();
0382
0383 #if QT_CORE_REMOVED_SINCE(6,5)
0384 void writeEntityReference(const QString &name);
0385 void writeNamespace(const QString &namespaceUri, const QString &prefix);
0386 void writeDefaultNamespace(const QString &namespaceUri);
0387 void writeProcessingInstruction(const QString &target, const QString &data);
0388 #endif
0389 void writeEntityReference(QAnyStringView name);
0390 void writeNamespace(QAnyStringView namespaceUri, QAnyStringView prefix = {});
0391 void writeDefaultNamespace(QAnyStringView namespaceUri);
0392 void writeProcessingInstruction(QAnyStringView target, QAnyStringView data = {});
0393
0394 void writeStartDocument();
0395 #if QT_CORE_REMOVED_SINCE(6,5)
0396 void writeStartDocument(const QString &version);
0397 void writeStartDocument(const QString &version, bool standalone);
0398 void writeStartElement(const QString &qualifiedName);
0399 void writeStartElement(const QString &namespaceUri, const QString &name);
0400 #endif
0401 void writeStartDocument(QAnyStringView version);
0402 void writeStartDocument(QAnyStringView version, bool standalone);
0403 void writeStartElement(QAnyStringView qualifiedName);
0404 void writeStartElement(QAnyStringView namespaceUri, QAnyStringView name);
0405
0406 #if QT_CONFIG(xmlstreamreader)
0407 void writeCurrentToken(const QXmlStreamReader &reader);
0408 #endif
0409
0410 bool hasError() const;
0411
0412 private:
0413 Q_DISABLE_COPY(QXmlStreamWriter)
0414 Q_DECLARE_PRIVATE(QXmlStreamWriter)
0415 QScopedPointer<QXmlStreamWriterPrivate> d_ptr;
0416 };
0417 #endif
0418
0419 QT_END_NAMESPACE
0420
0421 #endif
0422
0423 #endif