1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtXml 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 The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/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 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QDOM_H
41#define QDOM_H
42
43#include <QtXml/qtxmlglobal.h>
44#include <QtCore/qstring.h>
45
46QT_BEGIN_NAMESPACE
47
48
49#ifndef QT_NO_DOM
50
51class QIODevice;
52class QTextStream;
53
54class QXmlInputSource;
55class QXmlReader;
56
57class QDomDocumentPrivate;
58class QDomDocumentTypePrivate;
59class QDomDocumentFragmentPrivate;
60class QDomNodePrivate;
61class QDomNodeListPrivate;
62class QDomImplementationPrivate;
63class QDomElementPrivate;
64class QDomNotationPrivate;
65class QDomEntityPrivate;
66class QDomEntityReferencePrivate;
67class QDomProcessingInstructionPrivate;
68class QDomAttrPrivate;
69class QDomCharacterDataPrivate;
70class QDomTextPrivate;
71class QDomCommentPrivate;
72class QDomCDATASectionPrivate;
73class QDomNamedNodeMapPrivate;
74class QDomImplementationPrivate;
75
76class QDomNodeList;
77class QDomElement;
78class QDomText;
79class QDomComment;
80class QDomCDATASection;
81class QDomProcessingInstruction;
82class QDomAttr;
83class QDomEntityReference;
84class QDomDocument;
85class QDomNamedNodeMap;
86class QDomDocument;
87class QDomDocumentFragment;
88class QDomDocumentType;
89class QDomImplementation;
90class QDomNode;
91class QDomEntity;
92class QDomNotation;
93class QDomCharacterData;
94class QXmlStreamReader;
95
96class Q_XML_EXPORT QDomImplementation
97{
98public:
99 QDomImplementation();
100 QDomImplementation(const QDomImplementation&);
101 ~QDomImplementation();
102 QDomImplementation& operator= (const QDomImplementation&);
103 bool operator== (const QDomImplementation&) const;
104 bool operator!= (const QDomImplementation&) const;
105
106 // functions
107 bool hasFeature(const QString& feature, const QString& version) const;
108 QDomDocumentType createDocumentType(const QString& qName, const QString& publicId, const QString& systemId);
109 QDomDocument createDocument(const QString& nsURI, const QString& qName, const QDomDocumentType& doctype);
110
111 enum InvalidDataPolicy { AcceptInvalidChars = 0, DropInvalidChars, ReturnNullNode };
112 static InvalidDataPolicy invalidDataPolicy();
113 static void setInvalidDataPolicy(InvalidDataPolicy policy);
114
115 // Qt extension
116 bool isNull();
117
118private:
119 QDomImplementationPrivate* impl;
120 QDomImplementation(QDomImplementationPrivate*);
121
122 friend class QDomDocument;
123};
124
125class Q_XML_EXPORT QDomNode
126{
127public:
128 enum NodeType {
129 ElementNode = 1,
130 AttributeNode = 2,
131 TextNode = 3,
132 CDATASectionNode = 4,
133 EntityReferenceNode = 5,
134 EntityNode = 6,
135 ProcessingInstructionNode = 7,
136 CommentNode = 8,
137 DocumentNode = 9,
138 DocumentTypeNode = 10,
139 DocumentFragmentNode = 11,
140 NotationNode = 12,
141 BaseNode = 21,// this is not in the standard
142 CharacterDataNode = 22 // this is not in the standard
143 };
144
145 enum EncodingPolicy
146 {
147 EncodingFromDocument = 1,
148 EncodingFromTextStream = 2
149 };
150
151 QDomNode();
152 QDomNode(const QDomNode&);
153 QDomNode& operator= (const QDomNode&);
154 bool operator== (const QDomNode&) const;
155 bool operator!= (const QDomNode&) const;
156 ~QDomNode();
157
158 // DOM functions
159 QDomNode insertBefore(const QDomNode& newChild, const QDomNode& refChild);
160 QDomNode insertAfter(const QDomNode& newChild, const QDomNode& refChild);
161 QDomNode replaceChild(const QDomNode& newChild, const QDomNode& oldChild);
162 QDomNode removeChild(const QDomNode& oldChild);
163 QDomNode appendChild(const QDomNode& newChild);
164 bool hasChildNodes() const;
165 QDomNode cloneNode(bool deep = true) const;
166 void normalize();
167 bool isSupported(const QString& feature, const QString& version) const;
168
169 // DOM read-only attributes
170 QString nodeName() const;
171 NodeType nodeType() const;
172 QDomNode parentNode() const;
173 QDomNodeList childNodes() const;
174 QDomNode firstChild() const;
175 QDomNode lastChild() const;
176 QDomNode previousSibling() const;
177 QDomNode nextSibling() const;
178 QDomNamedNodeMap attributes() const;
179 QDomDocument ownerDocument() const;
180 QString namespaceURI() const;
181 QString localName() const;
182 bool hasAttributes() const;
183
184 // DOM attributes
185 QString nodeValue() const;
186 void setNodeValue(const QString&);
187 QString prefix() const;
188 void setPrefix(const QString& pre);
189
190 // Qt extensions
191 bool isAttr() const;
192 bool isCDATASection() const;
193 bool isDocumentFragment() const;
194 bool isDocument() const;
195 bool isDocumentType() const;
196 bool isElement() const;
197 bool isEntityReference() const;
198 bool isText() const;
199 bool isEntity() const;
200 bool isNotation() const;
201 bool isProcessingInstruction() const;
202 bool isCharacterData() const;
203 bool isComment() const;
204
205 /**
206 * Shortcut to avoid dealing with QDomNodeList
207 * all the time.
208 */
209 QDomNode namedItem(const QString& name) const;
210
211 bool isNull() const;
212 void clear();
213
214 QDomAttr toAttr() const;
215 QDomCDATASection toCDATASection() const;
216 QDomDocumentFragment toDocumentFragment() const;
217 QDomDocument toDocument() const;
218 QDomDocumentType toDocumentType() const;
219 QDomElement toElement() const;
220 QDomEntityReference toEntityReference() const;
221 QDomText toText() const;
222 QDomEntity toEntity() const;
223 QDomNotation toNotation() const;
224 QDomProcessingInstruction toProcessingInstruction() const;
225 QDomCharacterData toCharacterData() const;
226 QDomComment toComment() const;
227
228 void save(QTextStream&, int, EncodingPolicy=QDomNode::EncodingFromDocument) const;
229
230 QDomElement firstChildElement(const QString &tagName = QString()) const;
231 QDomElement lastChildElement(const QString &tagName = QString()) const;
232 QDomElement previousSiblingElement(const QString &tagName = QString()) const;
233 QDomElement nextSiblingElement(const QString &taName = QString()) const;
234
235 int lineNumber() const;
236 int columnNumber() const;
237
238protected:
239 QDomNodePrivate* impl;
240 QDomNode(QDomNodePrivate*);
241
242private:
243 friend class QDomDocument;
244 friend class QDomDocumentType;
245 friend class QDomNodeList;
246 friend class QDomNamedNodeMap;
247};
248
249class Q_XML_EXPORT QDomNodeList
250{
251public:
252 QDomNodeList();
253 QDomNodeList(const QDomNodeList&);
254 QDomNodeList& operator= (const QDomNodeList&);
255 bool operator== (const QDomNodeList&) const;
256 bool operator!= (const QDomNodeList&) const;
257 ~QDomNodeList();
258
259 // DOM functions
260 QDomNode item(int index) const;
261 inline QDomNode at(int index) const { return item(index); } // Qt API consistency
262
263 // DOM read only attributes
264 int length() const;
265 inline int count() const { return length(); } // Qt API consitancy
266 inline int size() const { return length(); } // Qt API consistency
267 inline bool isEmpty() const { return length() == 0; } // Qt API consistency
268
269private:
270 QDomNodeListPrivate* impl;
271 QDomNodeList(QDomNodeListPrivate*);
272
273 friend class QDomNode;
274 friend class QDomElement;
275 friend class QDomDocument;
276};
277
278class Q_XML_EXPORT QDomDocumentType : public QDomNode
279{
280public:
281 QDomDocumentType();
282 QDomDocumentType(const QDomDocumentType& x);
283 QDomDocumentType& operator= (const QDomDocumentType&);
284
285 // DOM read only attributes
286 QString name() const;
287 QDomNamedNodeMap entities() const;
288 QDomNamedNodeMap notations() const;
289 QString publicId() const;
290 QString systemId() const;
291 QString internalSubset() const;
292
293 // Overridden from QDomNode
294 inline QDomNode::NodeType nodeType() const { return DocumentTypeNode; }
295
296private:
297 QDomDocumentType(QDomDocumentTypePrivate*);
298
299 friend class QDomImplementation;
300 friend class QDomDocument;
301 friend class QDomNode;
302};
303
304class Q_XML_EXPORT QDomDocument : public QDomNode
305{
306public:
307 QDomDocument();
308 explicit QDomDocument(const QString& name);
309 explicit QDomDocument(const QDomDocumentType& doctype);
310 QDomDocument(const QDomDocument& x);
311 QDomDocument& operator= (const QDomDocument&);
312 ~QDomDocument();
313
314 // DOM functions
315 QDomElement createElement(const QString& tagName);
316 QDomDocumentFragment createDocumentFragment();
317 QDomText createTextNode(const QString& data);
318 QDomComment createComment(const QString& data);
319 QDomCDATASection createCDATASection(const QString& data);
320 QDomProcessingInstruction createProcessingInstruction(const QString& target, const QString& data);
321 QDomAttr createAttribute(const QString& name);
322 QDomEntityReference createEntityReference(const QString& name);
323 QDomNodeList elementsByTagName(const QString& tagname) const;
324 QDomNode importNode(const QDomNode& importedNode, bool deep);
325 QDomElement createElementNS(const QString& nsURI, const QString& qName);
326 QDomAttr createAttributeNS(const QString& nsURI, const QString& qName);
327 QDomNodeList elementsByTagNameNS(const QString& nsURI, const QString& localName);
328 QDomElement elementById(const QString& elementId);
329
330 // DOM read only attributes
331 QDomDocumentType doctype() const;
332 QDomImplementation implementation() const;
333 QDomElement documentElement() const;
334
335 // Overridden from QDomNode
336 inline QDomNode::NodeType nodeType() const { return DocumentNode; }
337
338 // Qt extensions
339 bool setContent(const QByteArray& text, bool namespaceProcessing, QString *errorMsg=nullptr, int *errorLine=nullptr, int *errorColumn=nullptr );
340 bool setContent(const QString& text, bool namespaceProcessing, QString *errorMsg=nullptr, int *errorLine=nullptr, int *errorColumn=nullptr );
341 bool setContent(QIODevice* dev, bool namespaceProcessing, QString *errorMsg=nullptr, int *errorLine=nullptr, int *errorColumn=nullptr );
342#if QT_DEPRECATED_SINCE(5, 15)
343QT_WARNING_PUSH
344QT_WARNING_DISABLE_DEPRECATED
345 QT_DEPRECATED_X("Use other overloads instead")
346 bool setContent(QXmlInputSource *source, bool namespaceProcessing, QString *errorMsg=nullptr, int *errorLine=nullptr, int *errorColumn=nullptr );
347QT_WARNING_POP
348#endif
349 bool setContent(const QByteArray& text, QString *errorMsg=nullptr, int *errorLine=nullptr, int *errorColumn=nullptr );
350 bool setContent(const QString& text, QString *errorMsg=nullptr, int *errorLine=nullptr, int *errorColumn=nullptr );
351 bool setContent(QIODevice* dev, QString *errorMsg=nullptr, int *errorLine=nullptr, int *errorColumn=nullptr );
352#if QT_DEPRECATED_SINCE(5, 15)
353QT_WARNING_PUSH
354QT_WARNING_DISABLE_DEPRECATED
355 QT_DEPRECATED_X("Use other overloads instead")
356 bool setContent(QXmlInputSource *source, QXmlReader *reader, QString *errorMsg=nullptr, int *errorLine=nullptr, int *errorColumn=nullptr );
357QT_WARNING_POP
358#endif
359 bool setContent(QXmlStreamReader *reader, bool namespaceProcessing, QString *errorMsg = nullptr,
360 int *errorLine = nullptr, int *errorColumn = nullptr);
361
362 // Qt extensions
363 QString toString(int = 1) const;
364 QByteArray toByteArray(int = 1) const;
365
366private:
367 QDomDocument(QDomDocumentPrivate*);
368
369 friend class QDomNode;
370};
371
372class Q_XML_EXPORT QDomNamedNodeMap
373{
374public:
375 QDomNamedNodeMap();
376 QDomNamedNodeMap(const QDomNamedNodeMap&);
377 QDomNamedNodeMap& operator= (const QDomNamedNodeMap&);
378 bool operator== (const QDomNamedNodeMap&) const;
379 bool operator!= (const QDomNamedNodeMap&) const;
380 ~QDomNamedNodeMap();
381
382 // DOM functions
383 QDomNode namedItem(const QString& name) const;
384 QDomNode setNamedItem(const QDomNode& newNode);
385 QDomNode removeNamedItem(const QString& name);
386 QDomNode item(int index) const;
387 QDomNode namedItemNS(const QString& nsURI, const QString& localName) const;
388 QDomNode setNamedItemNS(const QDomNode& newNode);
389 QDomNode removeNamedItemNS(const QString& nsURI, const QString& localName);
390
391 // DOM read only attributes
392 int length() const;
393 int count() const { return length(); } // Qt API consitancy
394 inline int size() const { return length(); } // Qt API consistency
395 inline bool isEmpty() const { return length() == 0; } // Qt API consistency
396
397 // Qt extension
398 bool contains(const QString& name) const;
399
400private:
401 QDomNamedNodeMapPrivate* impl;
402 QDomNamedNodeMap(QDomNamedNodeMapPrivate*);
403
404 friend class QDomNode;
405 friend class QDomDocumentType;
406 friend class QDomElement;
407};
408
409class Q_XML_EXPORT QDomDocumentFragment : public QDomNode
410{
411public:
412 QDomDocumentFragment();
413 QDomDocumentFragment(const QDomDocumentFragment& x);
414 QDomDocumentFragment& operator= (const QDomDocumentFragment&);
415
416 // Overridden from QDomNode
417 inline QDomNode::NodeType nodeType() const { return DocumentFragmentNode; }
418
419private:
420 QDomDocumentFragment(QDomDocumentFragmentPrivate*);
421
422 friend class QDomDocument;
423 friend class QDomNode;
424};
425
426class Q_XML_EXPORT QDomCharacterData : public QDomNode
427{
428public:
429 QDomCharacterData();
430 QDomCharacterData(const QDomCharacterData& x);
431 QDomCharacterData& operator= (const QDomCharacterData&);
432
433 // DOM functions
434 QString substringData(unsigned long offset, unsigned long count);
435 void appendData(const QString& arg);
436 void insertData(unsigned long offset, const QString& arg);
437 void deleteData(unsigned long offset, unsigned long count);
438 void replaceData(unsigned long offset, unsigned long count, const QString& arg);
439
440 // DOM read only attributes
441 int length() const;
442
443 // DOM attributes
444 QString data() const;
445 void setData(const QString&);
446
447 // Overridden from QDomNode
448 QDomNode::NodeType nodeType() const;
449
450private:
451 QDomCharacterData(QDomCharacterDataPrivate*);
452
453 friend class QDomDocument;
454 friend class QDomText;
455 friend class QDomComment;
456 friend class QDomNode;
457};
458
459class Q_XML_EXPORT QDomAttr : public QDomNode
460{
461public:
462 QDomAttr();
463 QDomAttr(const QDomAttr& x);
464 QDomAttr& operator= (const QDomAttr&);
465
466 // DOM read only attributes
467 QString name() const;
468 bool specified() const;
469 QDomElement ownerElement() const;
470
471 // DOM attributes
472 QString value() const;
473 void setValue(const QString&);
474
475 // Overridden from QDomNode
476 inline QDomNode::NodeType nodeType() const { return AttributeNode; }
477
478private:
479 QDomAttr(QDomAttrPrivate*);
480
481 friend class QDomDocument;
482 friend class QDomElement;
483 friend class QDomNode;
484};
485
486class Q_XML_EXPORT QDomElement : public QDomNode
487{
488public:
489 QDomElement();
490 QDomElement(const QDomElement& x);
491 QDomElement& operator= (const QDomElement&);
492
493 // DOM functions
494 QString attribute(const QString& name, const QString& defValue = QString() ) const;
495 void setAttribute(const QString& name, const QString& value);
496 void setAttribute(const QString& name, qlonglong value);
497 void setAttribute(const QString& name, qulonglong value);
498 inline void setAttribute(const QString& name, int value)
499 { setAttribute(name, value: qlonglong(value)); }
500 inline void setAttribute(const QString& name, uint value)
501 { setAttribute(name, value: qulonglong(value)); }
502 void setAttribute(const QString& name, float value);
503 void setAttribute(const QString& name, double value);
504 void removeAttribute(const QString& name);
505 QDomAttr attributeNode(const QString& name);
506 QDomAttr setAttributeNode(const QDomAttr& newAttr);
507 QDomAttr removeAttributeNode(const QDomAttr& oldAttr);
508 QDomNodeList elementsByTagName(const QString& tagname) const;
509 bool hasAttribute(const QString& name) const;
510
511 QString attributeNS(const QString nsURI, const QString& localName, const QString& defValue = QString()) const;
512 void setAttributeNS(const QString nsURI, const QString& qName, const QString& value);
513 inline void setAttributeNS(const QString nsURI, const QString& qName, int value)
514 { setAttributeNS(nsURI, qName, value: qlonglong(value)); }
515 inline void setAttributeNS(const QString nsURI, const QString& qName, uint value)
516 { setAttributeNS(nsURI, qName, value: qulonglong(value)); }
517 void setAttributeNS(const QString nsURI, const QString& qName, qlonglong value);
518 void setAttributeNS(const QString nsURI, const QString& qName, qulonglong value);
519 void setAttributeNS(const QString nsURI, const QString& qName, double value);
520 void removeAttributeNS(const QString& nsURI, const QString& localName);
521 QDomAttr attributeNodeNS(const QString& nsURI, const QString& localName);
522 QDomAttr setAttributeNodeNS(const QDomAttr& newAttr);
523 QDomNodeList elementsByTagNameNS(const QString& nsURI, const QString& localName) const;
524 bool hasAttributeNS(const QString& nsURI, const QString& localName) const;
525
526 // DOM read only attributes
527 QString tagName() const;
528 void setTagName(const QString& name); // Qt extension
529
530 // Overridden from QDomNode
531 QDomNamedNodeMap attributes() const;
532 inline QDomNode::NodeType nodeType() const { return ElementNode; }
533
534 QString text() const;
535
536private:
537 QDomElement(QDomElementPrivate*);
538
539 friend class QDomDocument;
540 friend class QDomNode;
541 friend class QDomAttr;
542};
543
544class Q_XML_EXPORT QDomText : public QDomCharacterData
545{
546public:
547 QDomText();
548 QDomText(const QDomText& x);
549 QDomText& operator= (const QDomText&);
550
551 // DOM functions
552 QDomText splitText(int offset);
553
554 // Overridden from QDomCharacterData
555 inline QDomNode::NodeType nodeType() const { return TextNode; }
556
557private:
558 QDomText(QDomTextPrivate*);
559
560 friend class QDomCDATASection;
561 friend class QDomDocument;
562 friend class QDomNode;
563};
564
565class Q_XML_EXPORT QDomComment : public QDomCharacterData
566{
567public:
568 QDomComment();
569 QDomComment(const QDomComment& x);
570 QDomComment& operator= (const QDomComment&);
571
572 // Overridden from QDomCharacterData
573 inline QDomNode::NodeType nodeType() const { return CommentNode; }
574
575private:
576 QDomComment(QDomCommentPrivate*);
577
578 friend class QDomDocument;
579 friend class QDomNode;
580};
581
582class Q_XML_EXPORT QDomCDATASection : public QDomText
583{
584public:
585 QDomCDATASection();
586 QDomCDATASection(const QDomCDATASection& x);
587 QDomCDATASection& operator= (const QDomCDATASection&);
588
589 // Overridden from QDomText
590 inline QDomNode::NodeType nodeType() const { return CDATASectionNode; }
591
592private:
593 QDomCDATASection(QDomCDATASectionPrivate*);
594
595 friend class QDomDocument;
596 friend class QDomNode;
597};
598
599class Q_XML_EXPORT QDomNotation : public QDomNode
600{
601public:
602 QDomNotation();
603 QDomNotation(const QDomNotation& x);
604 QDomNotation& operator= (const QDomNotation&);
605
606 // DOM read only attributes
607 QString publicId() const;
608 QString systemId() const;
609
610 // Overridden from QDomNode
611 inline QDomNode::NodeType nodeType() const { return NotationNode; }
612
613private:
614 QDomNotation(QDomNotationPrivate*);
615
616 friend class QDomDocument;
617 friend class QDomNode;
618};
619
620class Q_XML_EXPORT QDomEntity : public QDomNode
621{
622public:
623 QDomEntity();
624 QDomEntity(const QDomEntity& x);
625 QDomEntity& operator= (const QDomEntity&);
626
627 // DOM read only attributes
628 QString publicId() const;
629 QString systemId() const;
630 QString notationName() const;
631
632 // Overridden from QDomNode
633 inline QDomNode::NodeType nodeType() const { return EntityNode; }
634
635private:
636 QDomEntity(QDomEntityPrivate*);
637
638 friend class QDomNode;
639};
640
641class Q_XML_EXPORT QDomEntityReference : public QDomNode
642{
643public:
644 QDomEntityReference();
645 QDomEntityReference(const QDomEntityReference& x);
646 QDomEntityReference& operator= (const QDomEntityReference&);
647
648 // Overridden from QDomNode
649 inline QDomNode::NodeType nodeType() const { return EntityReferenceNode; }
650
651private:
652 QDomEntityReference(QDomEntityReferencePrivate*);
653
654 friend class QDomDocument;
655 friend class QDomNode;
656};
657
658class Q_XML_EXPORT QDomProcessingInstruction : public QDomNode
659{
660public:
661 QDomProcessingInstruction();
662 QDomProcessingInstruction(const QDomProcessingInstruction& x);
663 QDomProcessingInstruction& operator= (const QDomProcessingInstruction&);
664
665 // DOM read only attributes
666 QString target() const;
667
668 // DOM attributes
669 QString data() const;
670 void setData(const QString& d);
671
672 // Overridden from QDomNode
673 inline QDomNode::NodeType nodeType() const { return ProcessingInstructionNode; }
674
675private:
676 QDomProcessingInstruction(QDomProcessingInstructionPrivate*);
677
678 friend class QDomDocument;
679 friend class QDomNode;
680};
681
682
683Q_XML_EXPORT QTextStream& operator<<(QTextStream&, const QDomNode&);
684
685#endif // QT_NO_DOM
686
687QT_END_NAMESPACE
688
689#endif // QDOM_H
690

source code of qtbase/src/xml/dom/qdom.h