File indexing completed on 2025-01-30 10:21:25
0001
0002
0003
0004 #ifndef QDOM_H
0005 #define QDOM_H
0006
0007 #include <QtXml/qtxmlglobal.h>
0008 #include <QtCore/qstring.h>
0009
0010 class tst_QDom;
0011
0012 QT_BEGIN_NAMESPACE
0013
0014
0015 #ifndef QT_NO_DOM
0016
0017 class QIODevice;
0018 class QTextStream;
0019
0020 class QDomDocumentPrivate;
0021 class QDomDocumentTypePrivate;
0022 class QDomDocumentFragmentPrivate;
0023 class QDomNodePrivate;
0024 class QDomNodeListPrivate;
0025 class QDomImplementationPrivate;
0026 class QDomElementPrivate;
0027 class QDomNotationPrivate;
0028 class QDomEntityPrivate;
0029 class QDomEntityReferencePrivate;
0030 class QDomProcessingInstructionPrivate;
0031 class QDomAttrPrivate;
0032 class QDomCharacterDataPrivate;
0033 class QDomTextPrivate;
0034 class QDomCommentPrivate;
0035 class QDomCDATASectionPrivate;
0036 class QDomNamedNodeMapPrivate;
0037 class QDomImplementationPrivate;
0038
0039 class QDomNodeList;
0040 class QDomElement;
0041 class QDomText;
0042 class QDomComment;
0043 class QDomCDATASection;
0044 class QDomProcessingInstruction;
0045 class QDomAttr;
0046 class QDomEntityReference;
0047 class QDomDocument;
0048 class QDomNamedNodeMap;
0049 class QDomDocument;
0050 class QDomDocumentFragment;
0051 class QDomDocumentType;
0052 class QDomImplementation;
0053 class QDomNode;
0054 class QDomEntity;
0055 class QDomNotation;
0056 class QDomCharacterData;
0057 class QXmlStreamReader;
0058
0059 class Q_XML_EXPORT QDomImplementation
0060 {
0061 public:
0062 QDomImplementation();
0063 QDomImplementation(const QDomImplementation&);
0064 ~QDomImplementation();
0065 QDomImplementation& operator= (const QDomImplementation&);
0066 bool operator== (const QDomImplementation&) const;
0067 bool operator!= (const QDomImplementation&) const;
0068
0069
0070 bool hasFeature(const QString& feature, const QString& version) const;
0071 QDomDocumentType createDocumentType(const QString& qName, const QString& publicId, const QString& systemId);
0072 QDomDocument createDocument(const QString& nsURI, const QString& qName, const QDomDocumentType& doctype);
0073
0074 enum InvalidDataPolicy { AcceptInvalidChars = 0, DropInvalidChars, ReturnNullNode };
0075 static InvalidDataPolicy invalidDataPolicy();
0076 static void setInvalidDataPolicy(InvalidDataPolicy policy);
0077
0078
0079 bool isNull();
0080
0081 private:
0082 QDomImplementationPrivate* impl;
0083 QDomImplementation(QDomImplementationPrivate*);
0084
0085 friend class QDomDocument;
0086 };
0087
0088 class Q_XML_EXPORT QDomNode
0089 {
0090 public:
0091 enum NodeType {
0092 ElementNode = 1,
0093 AttributeNode = 2,
0094 TextNode = 3,
0095 CDATASectionNode = 4,
0096 EntityReferenceNode = 5,
0097 EntityNode = 6,
0098 ProcessingInstructionNode = 7,
0099 CommentNode = 8,
0100 DocumentNode = 9,
0101 DocumentTypeNode = 10,
0102 DocumentFragmentNode = 11,
0103 NotationNode = 12,
0104 BaseNode = 21,
0105 CharacterDataNode = 22
0106 };
0107
0108 enum EncodingPolicy
0109 {
0110 EncodingFromDocument = 1,
0111 EncodingFromTextStream = 2
0112 };
0113
0114 QDomNode();
0115 QDomNode(const QDomNode&);
0116 QDomNode& operator= (const QDomNode&);
0117 bool operator== (const QDomNode&) const;
0118 bool operator!= (const QDomNode&) const;
0119 ~QDomNode();
0120
0121
0122 QDomNode insertBefore(const QDomNode& newChild, const QDomNode& refChild);
0123 QDomNode insertAfter(const QDomNode& newChild, const QDomNode& refChild);
0124 QDomNode replaceChild(const QDomNode& newChild, const QDomNode& oldChild);
0125 QDomNode removeChild(const QDomNode& oldChild);
0126 QDomNode appendChild(const QDomNode& newChild);
0127 bool hasChildNodes() const;
0128 QDomNode cloneNode(bool deep = true) const;
0129 void normalize();
0130 bool isSupported(const QString& feature, const QString& version) const;
0131
0132
0133 QString nodeName() const;
0134 NodeType nodeType() const;
0135 QDomNode parentNode() const;
0136 QDomNodeList childNodes() const;
0137 QDomNode firstChild() const;
0138 QDomNode lastChild() const;
0139 QDomNode previousSibling() const;
0140 QDomNode nextSibling() const;
0141 QDomNamedNodeMap attributes() const;
0142 QDomDocument ownerDocument() const;
0143 QString namespaceURI() const;
0144 QString localName() const;
0145 bool hasAttributes() const;
0146
0147
0148 QString nodeValue() const;
0149 void setNodeValue(const QString&);
0150 QString prefix() const;
0151 void setPrefix(const QString& pre);
0152
0153
0154 bool isAttr() const;
0155 bool isCDATASection() const;
0156 bool isDocumentFragment() const;
0157 bool isDocument() const;
0158 bool isDocumentType() const;
0159 bool isElement() const;
0160 bool isEntityReference() const;
0161 bool isText() const;
0162 bool isEntity() const;
0163 bool isNotation() const;
0164 bool isProcessingInstruction() const;
0165 bool isCharacterData() const;
0166 bool isComment() const;
0167
0168
0169
0170
0171
0172 QDomNode namedItem(const QString& name) const;
0173
0174 bool isNull() const;
0175 void clear();
0176
0177 QDomAttr toAttr() const;
0178 QDomCDATASection toCDATASection() const;
0179 QDomDocumentFragment toDocumentFragment() const;
0180 QDomDocument toDocument() const;
0181 QDomDocumentType toDocumentType() const;
0182 QDomElement toElement() const;
0183 QDomEntityReference toEntityReference() const;
0184 QDomText toText() const;
0185 QDomEntity toEntity() const;
0186 QDomNotation toNotation() const;
0187 QDomProcessingInstruction toProcessingInstruction() const;
0188 QDomCharacterData toCharacterData() const;
0189 QDomComment toComment() const;
0190
0191 void save(QTextStream&, int, EncodingPolicy=QDomNode::EncodingFromDocument) const;
0192
0193 QDomElement firstChildElement(const QString &tagName = QString(), const QString &namespaceURI = QString()) const;
0194 QDomElement lastChildElement(const QString &tagName = QString(), const QString &namespaceURI = QString()) const;
0195 QDomElement previousSiblingElement(const QString &tagName = QString(), const QString &namespaceURI = QString()) const;
0196 QDomElement nextSiblingElement(const QString &taName = QString(), const QString &namespaceURI = QString()) const;
0197
0198 int lineNumber() const;
0199 int columnNumber() const;
0200
0201 protected:
0202 QDomNodePrivate* impl;
0203 QDomNode(QDomNodePrivate*);
0204
0205 private:
0206 friend class ::tst_QDom;
0207 friend class QDomDocument;
0208 friend class QDomDocumentType;
0209 friend class QDomNodeList;
0210 friend class QDomNamedNodeMap;
0211 };
0212
0213 class Q_XML_EXPORT QDomNodeList
0214 {
0215 public:
0216 QDomNodeList();
0217 QDomNodeList(const QDomNodeList&);
0218 QDomNodeList& operator= (const QDomNodeList&);
0219 bool operator== (const QDomNodeList&) const;
0220 bool operator!= (const QDomNodeList&) const;
0221 ~QDomNodeList();
0222
0223
0224 QDomNode item(int index) const;
0225 inline QDomNode at(int index) const { return item(index); }
0226
0227
0228 int length() const;
0229 inline int count() const { return length(); }
0230 inline int size() const { return length(); }
0231 inline bool isEmpty() const { return length() == 0; }
0232
0233 private:
0234 QDomNodeListPrivate* impl;
0235 QDomNodeList(QDomNodeListPrivate*);
0236
0237 friend class QDomNode;
0238 friend class QDomElement;
0239 friend class QDomDocument;
0240 };
0241
0242 class Q_XML_EXPORT QDomDocumentType : public QDomNode
0243 {
0244 public:
0245 QDomDocumentType();
0246 QDomDocumentType(const QDomDocumentType& x);
0247 QDomDocumentType& operator= (const QDomDocumentType&);
0248
0249
0250 QString name() const;
0251 QDomNamedNodeMap entities() const;
0252 QDomNamedNodeMap notations() const;
0253 QString publicId() const;
0254 QString systemId() const;
0255 QString internalSubset() const;
0256
0257
0258 inline QDomNode::NodeType nodeType() const { return DocumentTypeNode; }
0259
0260 private:
0261 QDomDocumentType(QDomDocumentTypePrivate*);
0262
0263 friend class QDomImplementation;
0264 friend class QDomDocument;
0265 friend class QDomNode;
0266 };
0267
0268 class Q_XML_EXPORT QDomDocument : public QDomNode
0269 {
0270 public:
0271 enum class ParseOption {
0272 Default = 0x00,
0273 UseNamespaceProcessing = 0x01,
0274 PreserveSpacingOnlyNodes = 0x02,
0275 };
0276 Q_DECLARE_FLAGS(ParseOptions, ParseOption)
0277
0278 struct ParseResult
0279 {
0280 QString errorMessage;
0281 qsizetype errorLine = 0;
0282 qsizetype errorColumn = 0;
0283
0284 explicit operator bool() const noexcept { return errorMessage.isEmpty(); }
0285 };
0286
0287 QDomDocument();
0288 explicit QDomDocument(const QString& name);
0289 explicit QDomDocument(const QDomDocumentType& doctype);
0290 QDomDocument(const QDomDocument& x);
0291 QDomDocument& operator= (const QDomDocument&);
0292 ~QDomDocument();
0293
0294
0295 QDomElement createElement(const QString& tagName);
0296 QDomDocumentFragment createDocumentFragment();
0297 QDomText createTextNode(const QString& data);
0298 QDomComment createComment(const QString& data);
0299 QDomCDATASection createCDATASection(const QString& data);
0300 QDomProcessingInstruction createProcessingInstruction(const QString& target, const QString& data);
0301 QDomAttr createAttribute(const QString& name);
0302 QDomEntityReference createEntityReference(const QString& name);
0303 QDomNodeList elementsByTagName(const QString& tagname) const;
0304 QDomNode importNode(const QDomNode& importedNode, bool deep);
0305 QDomElement createElementNS(const QString& nsURI, const QString& qName);
0306 QDomAttr createAttributeNS(const QString& nsURI, const QString& qName);
0307 QDomNodeList elementsByTagNameNS(const QString& nsURI, const QString& localName);
0308 QDomElement elementById(const QString& elementId);
0309
0310
0311 QDomDocumentType doctype() const;
0312 QDomImplementation implementation() const;
0313 QDomElement documentElement() const;
0314
0315
0316 inline QDomNode::NodeType nodeType() const { return DocumentNode; }
0317
0318
0319 #if QT_DEPRECATED_SINCE(6, 8)
0320 QT_DEPRECATED_VERSION_X_6_8("Use the overload taking ParseOptions instead.")
0321 bool setContent(const QByteArray &text, bool namespaceProcessing, QString *errorMsg = nullptr, int *errorLine = nullptr, int *errorColumn = nullptr);
0322 QT_DEPRECATED_VERSION_X_6_8("Use the overload taking ParseOptions instead.")
0323 bool setContent(const QString &text, bool namespaceProcessing, QString *errorMsg = nullptr, int *errorLine = nullptr, int *errorColumn = nullptr);
0324 QT_DEPRECATED_VERSION_X_6_8("Use the overload taking ParseOptions instead.")
0325 bool setContent(QIODevice *dev, bool namespaceProcessing, QString *errorMsg = nullptr, int *errorLine = nullptr, int *errorColumn = nullptr);
0326 QT_DEPRECATED_VERSION_X_6_8("Use the overload returning ParseResult instead.")
0327 bool setContent(const QByteArray &text, QString *errorMsg, int *errorLine = nullptr, int *errorColumn = nullptr);
0328 QT_DEPRECATED_VERSION_X_6_8("Use the overload returning ParseResult instead.")
0329 bool setContent(const QString &text, QString *errorMsg, int *errorLine = nullptr, int *errorColumn = nullptr);
0330 QT_DEPRECATED_VERSION_X_6_8("Use the overload returning ParseResult instead.")
0331 bool setContent(QIODevice *dev, QString *errorMsg, int *errorLine = nullptr, int *errorColumn = nullptr);
0332 QT_DEPRECATED_VERSION_X_6_8("Use the overload taking ParseOptions instead.")
0333 bool setContent(QXmlStreamReader *reader, bool namespaceProcessing, QString *errorMsg = nullptr,
0334 int *errorLine = nullptr, int *errorColumn = nullptr);
0335 #endif
0336
0337 Q_WEAK_OVERLOAD
0338 ParseResult setContent(const QByteArray &data, ParseOptions options = ParseOption::Default)
0339 { return setContentImpl(data, options); }
0340 ParseResult setContent(QAnyStringView data, ParseOptions options = ParseOption::Default);
0341 ParseResult setContent(QIODevice *device, ParseOptions options = ParseOption::Default);
0342 ParseResult setContent(QXmlStreamReader *reader, ParseOptions options = ParseOption::Default);
0343
0344
0345 QString toString(int = 1) const;
0346 QByteArray toByteArray(int = 1) const;
0347
0348 private:
0349 ParseResult setContentImpl(const QByteArray &data, ParseOptions options);
0350
0351 QDomDocument(QDomDocumentPrivate*);
0352
0353 friend class QDomNode;
0354 };
0355
0356 class Q_XML_EXPORT QDomNamedNodeMap
0357 {
0358 public:
0359 QDomNamedNodeMap();
0360 QDomNamedNodeMap(const QDomNamedNodeMap&);
0361 QDomNamedNodeMap& operator= (const QDomNamedNodeMap&);
0362 bool operator== (const QDomNamedNodeMap&) const;
0363 bool operator!= (const QDomNamedNodeMap&) const;
0364 ~QDomNamedNodeMap();
0365
0366
0367 QDomNode namedItem(const QString& name) const;
0368 QDomNode setNamedItem(const QDomNode& newNode);
0369 QDomNode removeNamedItem(const QString& name);
0370 QDomNode item(int index) const;
0371 QDomNode namedItemNS(const QString& nsURI, const QString& localName) const;
0372 QDomNode setNamedItemNS(const QDomNode& newNode);
0373 QDomNode removeNamedItemNS(const QString& nsURI, const QString& localName);
0374
0375
0376 int length() const;
0377 int count() const { return length(); }
0378 inline int size() const { return length(); }
0379 inline bool isEmpty() const { return length() == 0; }
0380
0381
0382 bool contains(const QString& name) const;
0383
0384 private:
0385 QDomNamedNodeMapPrivate* impl;
0386 QDomNamedNodeMap(QDomNamedNodeMapPrivate*);
0387
0388 friend class QDomNode;
0389 friend class QDomDocumentType;
0390 friend class QDomElement;
0391 };
0392
0393 class Q_XML_EXPORT QDomDocumentFragment : public QDomNode
0394 {
0395 public:
0396 QDomDocumentFragment();
0397 QDomDocumentFragment(const QDomDocumentFragment& x);
0398 QDomDocumentFragment& operator= (const QDomDocumentFragment&);
0399
0400
0401 inline QDomNode::NodeType nodeType() const { return DocumentFragmentNode; }
0402
0403 private:
0404 QDomDocumentFragment(QDomDocumentFragmentPrivate*);
0405
0406 friend class QDomDocument;
0407 friend class QDomNode;
0408 };
0409
0410 class Q_XML_EXPORT QDomCharacterData : public QDomNode
0411 {
0412 public:
0413 QDomCharacterData();
0414 QDomCharacterData(const QDomCharacterData& x);
0415 QDomCharacterData& operator= (const QDomCharacterData&);
0416
0417
0418 QString substringData(unsigned long offset, unsigned long count);
0419 void appendData(const QString& arg);
0420 void insertData(unsigned long offset, const QString& arg);
0421 void deleteData(unsigned long offset, unsigned long count);
0422 void replaceData(unsigned long offset, unsigned long count, const QString& arg);
0423
0424
0425 int length() const;
0426
0427
0428 QString data() const;
0429 void setData(const QString&);
0430
0431
0432 QDomNode::NodeType nodeType() const;
0433
0434 private:
0435 QDomCharacterData(QDomCharacterDataPrivate*);
0436
0437 friend class QDomDocument;
0438 friend class QDomText;
0439 friend class QDomComment;
0440 friend class QDomNode;
0441 };
0442
0443 class Q_XML_EXPORT QDomAttr : public QDomNode
0444 {
0445 public:
0446 QDomAttr();
0447 QDomAttr(const QDomAttr& x);
0448 QDomAttr& operator= (const QDomAttr&);
0449
0450
0451 QString name() const;
0452 bool specified() const;
0453 QDomElement ownerElement() const;
0454
0455
0456 QString value() const;
0457 void setValue(const QString&);
0458
0459
0460 inline QDomNode::NodeType nodeType() const { return AttributeNode; }
0461
0462 private:
0463 QDomAttr(QDomAttrPrivate*);
0464
0465 friend class QDomDocument;
0466 friend class QDomElement;
0467 friend class QDomNode;
0468 };
0469
0470 class Q_XML_EXPORT QDomElement : public QDomNode
0471 {
0472 public:
0473 QDomElement();
0474 QDomElement(const QDomElement& x);
0475 QDomElement& operator= (const QDomElement&);
0476
0477
0478 QString attribute(const QString& name, const QString& defValue = QString() ) const;
0479 void setAttribute(const QString& name, const QString& value);
0480 void setAttribute(const QString& name, qlonglong value);
0481 void setAttribute(const QString& name, qulonglong value);
0482 inline void setAttribute(const QString& name, int value)
0483 { setAttribute(name, qlonglong(value)); }
0484 inline void setAttribute(const QString& name, uint value)
0485 { setAttribute(name, qulonglong(value)); }
0486 void setAttribute(const QString& name, float value);
0487 void setAttribute(const QString& name, double value);
0488 void removeAttribute(const QString& name);
0489 QDomAttr attributeNode(const QString& name);
0490 QDomAttr setAttributeNode(const QDomAttr& newAttr);
0491 QDomAttr removeAttributeNode(const QDomAttr& oldAttr);
0492 QDomNodeList elementsByTagName(const QString& tagname) const;
0493 bool hasAttribute(const QString& name) const;
0494
0495 QString attributeNS(const QString& nsURI, const QString& localName, const QString& defValue = QString()) const;
0496 void setAttributeNS(const QString& nsURI, const QString& qName, const QString& value);
0497 inline void setAttributeNS(const QString& nsURI, const QString& qName, int value)
0498 { setAttributeNS(nsURI, qName, qlonglong(value)); }
0499 inline void setAttributeNS(const QString& nsURI, const QString& qName, uint value)
0500 { setAttributeNS(nsURI, qName, qulonglong(value)); }
0501 void setAttributeNS(const QString& nsURI, const QString& qName, qlonglong value);
0502 void setAttributeNS(const QString& nsURI, const QString& qName, qulonglong value);
0503 void setAttributeNS(const QString& nsURI, const QString& qName, double value);
0504 void removeAttributeNS(const QString& nsURI, const QString& localName);
0505 QDomAttr attributeNodeNS(const QString& nsURI, const QString& localName);
0506 QDomAttr setAttributeNodeNS(const QDomAttr& newAttr);
0507 QDomNodeList elementsByTagNameNS(const QString& nsURI, const QString& localName) const;
0508 bool hasAttributeNS(const QString& nsURI, const QString& localName) const;
0509
0510
0511 QString tagName() const;
0512 void setTagName(const QString& name);
0513
0514
0515 QDomNamedNodeMap attributes() const;
0516 inline QDomNode::NodeType nodeType() const { return ElementNode; }
0517
0518 QString text() const;
0519
0520 private:
0521 QDomElement(QDomElementPrivate*);
0522
0523 friend class QDomDocument;
0524 friend class QDomNode;
0525 friend class QDomAttr;
0526 };
0527
0528 class Q_XML_EXPORT QDomText : public QDomCharacterData
0529 {
0530 public:
0531 QDomText();
0532 QDomText(const QDomText& x);
0533 QDomText& operator= (const QDomText&);
0534
0535
0536 QDomText splitText(int offset);
0537
0538
0539 inline QDomNode::NodeType nodeType() const { return TextNode; }
0540
0541 private:
0542 QDomText(QDomTextPrivate*);
0543
0544 friend class QDomCDATASection;
0545 friend class QDomDocument;
0546 friend class QDomNode;
0547 };
0548
0549 class Q_XML_EXPORT QDomComment : public QDomCharacterData
0550 {
0551 public:
0552 QDomComment();
0553 QDomComment(const QDomComment& x);
0554 QDomComment& operator= (const QDomComment&);
0555
0556
0557 inline QDomNode::NodeType nodeType() const { return CommentNode; }
0558
0559 private:
0560 QDomComment(QDomCommentPrivate*);
0561
0562 friend class QDomDocument;
0563 friend class QDomNode;
0564 };
0565
0566 class Q_XML_EXPORT QDomCDATASection : public QDomText
0567 {
0568 public:
0569 QDomCDATASection();
0570 QDomCDATASection(const QDomCDATASection& x);
0571 QDomCDATASection& operator= (const QDomCDATASection&);
0572
0573
0574 inline QDomNode::NodeType nodeType() const { return CDATASectionNode; }
0575
0576 private:
0577 QDomCDATASection(QDomCDATASectionPrivate*);
0578
0579 friend class QDomDocument;
0580 friend class QDomNode;
0581 };
0582
0583 class Q_XML_EXPORT QDomNotation : public QDomNode
0584 {
0585 public:
0586 QDomNotation();
0587 QDomNotation(const QDomNotation& x);
0588 QDomNotation& operator= (const QDomNotation&);
0589
0590
0591 QString publicId() const;
0592 QString systemId() const;
0593
0594
0595 inline QDomNode::NodeType nodeType() const { return NotationNode; }
0596
0597 private:
0598 QDomNotation(QDomNotationPrivate*);
0599
0600 friend class QDomDocument;
0601 friend class QDomNode;
0602 };
0603
0604 class Q_XML_EXPORT QDomEntity : public QDomNode
0605 {
0606 public:
0607 QDomEntity();
0608 QDomEntity(const QDomEntity& x);
0609 QDomEntity& operator= (const QDomEntity&);
0610
0611
0612 QString publicId() const;
0613 QString systemId() const;
0614 QString notationName() const;
0615
0616
0617 inline QDomNode::NodeType nodeType() const { return EntityNode; }
0618
0619 private:
0620 QDomEntity(QDomEntityPrivate*);
0621
0622 friend class QDomNode;
0623 };
0624
0625 class Q_XML_EXPORT QDomEntityReference : public QDomNode
0626 {
0627 public:
0628 QDomEntityReference();
0629 QDomEntityReference(const QDomEntityReference& x);
0630 QDomEntityReference& operator= (const QDomEntityReference&);
0631
0632
0633 inline QDomNode::NodeType nodeType() const { return EntityReferenceNode; }
0634
0635 private:
0636 QDomEntityReference(QDomEntityReferencePrivate*);
0637
0638 friend class QDomDocument;
0639 friend class QDomNode;
0640 };
0641
0642 class Q_XML_EXPORT QDomProcessingInstruction : public QDomNode
0643 {
0644 public:
0645 QDomProcessingInstruction();
0646 QDomProcessingInstruction(const QDomProcessingInstruction& x);
0647 QDomProcessingInstruction& operator= (const QDomProcessingInstruction&);
0648
0649
0650 QString target() const;
0651
0652
0653 QString data() const;
0654 void setData(const QString& d);
0655
0656
0657 inline QDomNode::NodeType nodeType() const { return ProcessingInstructionNode; }
0658
0659 private:
0660 QDomProcessingInstruction(QDomProcessingInstructionPrivate*);
0661
0662 friend class QDomDocument;
0663 friend class QDomNode;
0664 };
0665
0666
0667 Q_XML_EXPORT QTextStream& operator<<(QTextStream&, const QDomNode&);
0668
0669 #endif
0670
0671 QT_END_NAMESPACE
0672
0673 #endif