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 QString &namespaceURI = QString()) const;
231 QDomElement lastChildElement(const QString &tagName = QString(), const QString &namespaceURI = QString()) const;
232 QDomElement previousSiblingElement(const QString &tagName = QString(), const QString &namespaceURI = QString()) const;
233 QDomElement nextSiblingElement(const QString &taName = QString(), const QString &namespaceURI = 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 bool setContent(const QByteArray& text, QString *errorMsg=nullptr, int *errorLine=nullptr, int *errorColumn=nullptr );
343 bool setContent(const QString& text, QString *errorMsg=nullptr, int *errorLine=nullptr, int *errorColumn=nullptr );
344 bool setContent(QIODevice* dev, QString *errorMsg=nullptr, int *errorLine=nullptr, int *errorColumn=nullptr );
345 bool setContent(QXmlStreamReader *reader, bool namespaceProcessing, QString *errorMsg = nullptr,
346 int *errorLine = nullptr, int *errorColumn = nullptr);
347
348 // Qt extensions
349 QString toString(int = 1) const;
350 QByteArray toByteArray(int = 1) const;
351
352private:
353 QDomDocument(QDomDocumentPrivate*);
354
355 friend class QDomNode;
356};
357
358class Q_XML_EXPORT QDomNamedNodeMap
359{
360public:
361 QDomNamedNodeMap();
362 QDomNamedNodeMap(const QDomNamedNodeMap&);
363 QDomNamedNodeMap& operator= (const QDomNamedNodeMap&);
364 bool operator== (const QDomNamedNodeMap&) const;
365 bool operator!= (const QDomNamedNodeMap&) const;
366 ~QDomNamedNodeMap();
367
368 // DOM functions
369 QDomNode namedItem(const QString& name) const;
370 QDomNode setNamedItem(const QDomNode& newNode);
371 QDomNode removeNamedItem(const QString& name);
372 QDomNode item(int index) const;
373 QDomNode namedItemNS(const QString& nsURI, const QString& localName) const;
374 QDomNode setNamedItemNS(const QDomNode& newNode);
375 QDomNode removeNamedItemNS(const QString& nsURI, const QString& localName);
376
377 // DOM read only attributes
378 int length() const;
379 int count() const { return length(); } // Qt API consitancy
380 inline int size() const { return length(); } // Qt API consistency
381 inline bool isEmpty() const { return length() == 0; } // Qt API consistency
382
383 // Qt extension
384 bool contains(const QString& name) const;
385
386private:
387 QDomNamedNodeMapPrivate* impl;
388 QDomNamedNodeMap(QDomNamedNodeMapPrivate*);
389
390 friend class QDomNode;
391 friend class QDomDocumentType;
392 friend class QDomElement;
393};
394
395class Q_XML_EXPORT QDomDocumentFragment : public QDomNode
396{
397public:
398 QDomDocumentFragment();
399 QDomDocumentFragment(const QDomDocumentFragment& x);
400 QDomDocumentFragment& operator= (const QDomDocumentFragment&);
401
402 // Overridden from QDomNode
403 inline QDomNode::NodeType nodeType() const { return DocumentFragmentNode; }
404
405private:
406 QDomDocumentFragment(QDomDocumentFragmentPrivate*);
407
408 friend class QDomDocument;
409 friend class QDomNode;
410};
411
412class Q_XML_EXPORT QDomCharacterData : public QDomNode
413{
414public:
415 QDomCharacterData();
416 QDomCharacterData(const QDomCharacterData& x);
417 QDomCharacterData& operator= (const QDomCharacterData&);
418
419 // DOM functions
420 QString substringData(unsigned long offset, unsigned long count);
421 void appendData(const QString& arg);
422 void insertData(unsigned long offset, const QString& arg);
423 void deleteData(unsigned long offset, unsigned long count);
424 void replaceData(unsigned long offset, unsigned long count, const QString& arg);
425
426 // DOM read only attributes
427 int length() const;
428
429 // DOM attributes
430 QString data() const;
431 void setData(const QString&);
432
433 // Overridden from QDomNode
434 QDomNode::NodeType nodeType() const;
435
436private:
437 QDomCharacterData(QDomCharacterDataPrivate*);
438
439 friend class QDomDocument;
440 friend class QDomText;
441 friend class QDomComment;
442 friend class QDomNode;
443};
444
445class Q_XML_EXPORT QDomAttr : public QDomNode
446{
447public:
448 QDomAttr();
449 QDomAttr(const QDomAttr& x);
450 QDomAttr& operator= (const QDomAttr&);
451
452 // DOM read only attributes
453 QString name() const;
454 bool specified() const;
455 QDomElement ownerElement() const;
456
457 // DOM attributes
458 QString value() const;
459 void setValue(const QString&);
460
461 // Overridden from QDomNode
462 inline QDomNode::NodeType nodeType() const { return AttributeNode; }
463
464private:
465 QDomAttr(QDomAttrPrivate*);
466
467 friend class QDomDocument;
468 friend class QDomElement;
469 friend class QDomNode;
470};
471
472class Q_XML_EXPORT QDomElement : public QDomNode
473{
474public:
475 QDomElement();
476 QDomElement(const QDomElement& x);
477 QDomElement& operator= (const QDomElement&);
478
479 // DOM functions
480 QString attribute(const QString& name, const QString& defValue = QString() ) const;
481 void setAttribute(const QString& name, const QString& value);
482 void setAttribute(const QString& name, qlonglong value);
483 void setAttribute(const QString& name, qulonglong value);
484 inline void setAttribute(const QString& name, int value)
485 { setAttribute(name, qlonglong(value)); }
486 inline void setAttribute(const QString& name, uint value)
487 { setAttribute(name, qulonglong(value)); }
488 void setAttribute(const QString& name, float value);
489 void setAttribute(const QString& name, double value);
490 void removeAttribute(const QString& name);
491 QDomAttr attributeNode(const QString& name);
492 QDomAttr setAttributeNode(const QDomAttr& newAttr);
493 QDomAttr removeAttributeNode(const QDomAttr& oldAttr);
494 QDomNodeList elementsByTagName(const QString& tagname) const;
495 bool hasAttribute(const QString& name) const;
496
497 QString attributeNS(const QString& nsURI, const QString& localName, const QString& defValue = QString()) const;
498 void setAttributeNS(const QString& nsURI, const QString& qName, const QString& value);
499 inline void setAttributeNS(const QString& nsURI, const QString& qName, int value)
500 { setAttributeNS(nsURI, qName, qlonglong(value)); }
501 inline void setAttributeNS(const QString& nsURI, const QString& qName, uint value)
502 { setAttributeNS(nsURI, qName, qulonglong(value)); }
503 void setAttributeNS(const QString& nsURI, const QString& qName, qlonglong value);
504 void setAttributeNS(const QString& nsURI, const QString& qName, qulonglong value);
505 void setAttributeNS(const QString& nsURI, const QString& qName, double value);
506 void removeAttributeNS(const QString& nsURI, const QString& localName);
507 QDomAttr attributeNodeNS(const QString& nsURI, const QString& localName);
508 QDomAttr setAttributeNodeNS(const QDomAttr& newAttr);
509 QDomNodeList elementsByTagNameNS(const QString& nsURI, const QString& localName) const;
510 bool hasAttributeNS(const QString& nsURI, const QString& localName) const;
511
512 // DOM read only attributes
513 QString tagName() const;
514 void setTagName(const QString& name); // Qt extension
515
516 // Overridden from QDomNode
517 QDomNamedNodeMap attributes() const;
518 inline QDomNode::NodeType nodeType() const { return ElementNode; }
519
520 QString text() const;
521
522private:
523 QDomElement(QDomElementPrivate*);
524
525 friend class QDomDocument;
526 friend class QDomNode;
527 friend class QDomAttr;
528};
529
530class Q_XML_EXPORT QDomText : public QDomCharacterData
531{
532public:
533 QDomText();
534 QDomText(const QDomText& x);
535 QDomText& operator= (const QDomText&);
536
537 // DOM functions
538 QDomText splitText(int offset);
539
540 // Overridden from QDomCharacterData
541 inline QDomNode::NodeType nodeType() const { return TextNode; }
542
543private:
544 QDomText(QDomTextPrivate*);
545
546 friend class QDomCDATASection;
547 friend class QDomDocument;
548 friend class QDomNode;
549};
550
551class Q_XML_EXPORT QDomComment : public QDomCharacterData
552{
553public:
554 QDomComment();
555 QDomComment(const QDomComment& x);
556 QDomComment& operator= (const QDomComment&);
557
558 // Overridden from QDomCharacterData
559 inline QDomNode::NodeType nodeType() const { return CommentNode; }
560
561private:
562 QDomComment(QDomCommentPrivate*);
563
564 friend class QDomDocument;
565 friend class QDomNode;
566};
567
568class Q_XML_EXPORT QDomCDATASection : public QDomText
569{
570public:
571 QDomCDATASection();
572 QDomCDATASection(const QDomCDATASection& x);
573 QDomCDATASection& operator= (const QDomCDATASection&);
574
575 // Overridden from QDomText
576 inline QDomNode::NodeType nodeType() const { return CDATASectionNode; }
577
578private:
579 QDomCDATASection(QDomCDATASectionPrivate*);
580
581 friend class QDomDocument;
582 friend class QDomNode;
583};
584
585class Q_XML_EXPORT QDomNotation : public QDomNode
586{
587public:
588 QDomNotation();
589 QDomNotation(const QDomNotation& x);
590 QDomNotation& operator= (const QDomNotation&);
591
592 // DOM read only attributes
593 QString publicId() const;
594 QString systemId() const;
595
596 // Overridden from QDomNode
597 inline QDomNode::NodeType nodeType() const { return NotationNode; }
598
599private:
600 QDomNotation(QDomNotationPrivate*);
601
602 friend class QDomDocument;
603 friend class QDomNode;
604};
605
606class Q_XML_EXPORT QDomEntity : public QDomNode
607{
608public:
609 QDomEntity();
610 QDomEntity(const QDomEntity& x);
611 QDomEntity& operator= (const QDomEntity&);
612
613 // DOM read only attributes
614 QString publicId() const;
615 QString systemId() const;
616 QString notationName() const;
617
618 // Overridden from QDomNode
619 inline QDomNode::NodeType nodeType() const { return EntityNode; }
620
621private:
622 QDomEntity(QDomEntityPrivate*);
623
624 friend class QDomNode;
625};
626
627class Q_XML_EXPORT QDomEntityReference : public QDomNode
628{
629public:
630 QDomEntityReference();
631 QDomEntityReference(const QDomEntityReference& x);
632 QDomEntityReference& operator= (const QDomEntityReference&);
633
634 // Overridden from QDomNode
635 inline QDomNode::NodeType nodeType() const { return EntityReferenceNode; }
636
637private:
638 QDomEntityReference(QDomEntityReferencePrivate*);
639
640 friend class QDomDocument;
641 friend class QDomNode;
642};
643
644class Q_XML_EXPORT QDomProcessingInstruction : public QDomNode
645{
646public:
647 QDomProcessingInstruction();
648 QDomProcessingInstruction(const QDomProcessingInstruction& x);
649 QDomProcessingInstruction& operator= (const QDomProcessingInstruction&);
650
651 // DOM read only attributes
652 QString target() const;
653
654 // DOM attributes
655 QString data() const;
656 void setData(const QString& d);
657
658 // Overridden from QDomNode
659 inline QDomNode::NodeType nodeType() const { return ProcessingInstructionNode; }
660
661private:
662 QDomProcessingInstruction(QDomProcessingInstructionPrivate*);
663
664 friend class QDomDocument;
665 friend class QDomNode;
666};
667
668
669Q_XML_EXPORT QTextStream& operator<<(QTextStream&, const QDomNode&);
670
671#endif // QT_NO_DOM
672
673QT_END_NAMESPACE
674
675#endif // QDOM_H
676