Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qdom.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include <qplatformdefs.h>
5#include <qdom.h>
6#include "private/qxmlutils_p.h"
7
8#ifndef QT_NO_DOM
9
10#include "qdom_p.h"
11#include "qdomhelpers_p.h"
12
13#include <qatomic.h>
14#include <qbuffer.h>
15#include <qiodevice.h>
16#if QT_CONFIG(regularexpression)
17#include <qregularexpression.h>
18#endif
19#include <qtextstream.h>
20#include <qvariant.h>
21#include <qshareddata.h>
22#include <qdebug.h>
23#include <qxmlstream.h>
24#include <private/qduplicatetracker_p.h>
25#include <private/qstringiterator_p.h>
26#include <qvarlengtharray.h>
27
28#include <stdio.h>
29#include <limits>
30#include <memory>
31
33
34using namespace Qt::StringLiterals;
35
36/*
37 ### old todo comments -- I don't know if they still apply...
38
39 If the document dies, remove all pointers to it from children
40 which can not be deleted at this time.
41
42 If a node dies and has direct children which can not be deleted,
43 then remove the pointer to the parent.
44
45 createElement and friends create double reference counts.
46*/
47
48/* ##### new TODOs:
49
50 Remove empty emthods in the *Private classes
51
52 Make a lot of the (mostly empty) methods in the public classes inline.
53 Specially constructors assignment operators and comparison operators are candidates.
54*/
55
56/*
57 Reference counting:
58
59 Some simple rules:
60 1) If an intern object returns a pointer to another intern object
61 then the reference count of the returned object is not increased.
62 2) If an extern object is created and gets a pointer to some intern
63 object, then the extern object increases the intern objects reference count.
64 3) If an extern object is deleted, then it decreases the reference count
65 on its associated intern object and deletes it if nobody else hold references
66 on the intern object.
67*/
68
69
70/*
71 Helper to split a qualified name in the prefix and local name.
72*/
73static void qt_split_namespace(QString& prefix, QString& name, const QString& qName, bool hasURI)
74{
75 qsizetype i = qName.indexOf(u':');
76 if (i == -1) {
77 if (hasURI)
78 prefix = u""_s;
79 else
80 prefix.clear();
81 name = qName;
82 } else {
83 prefix = qName.left(i);
84 name = qName.mid(i + 1);
85 }
86}
87
88/**************************************************************
89 *
90 * Functions for verifying legal data
91 *
92 **************************************************************/
95
96// [5] Name ::= (Letter | '_' | ':') (NameChar)*
97
98static QString fixedXmlName(const QString &_name, bool *ok, bool namespaces = false)
99{
100 QString name, prefix;
101 if (namespaces)
102 qt_split_namespace(prefix, name, _name, true);
103 else
104 name = _name;
105
106 if (name.isEmpty()) {
107 *ok = false;
108 return QString();
109 }
110
112 *ok = true;
113 return _name;
114 }
115
117 bool firstChar = true;
118 for (int i = 0; i < name.size(); ++i) {
119 QChar c = name.at(i);
120 if (firstChar) {
121 if (QXmlUtils::isLetter(c) || c.unicode() == '_' || c.unicode() == ':') {
122 result.append(c);
123 firstChar = false;
125 *ok = false;
126 return QString();
127 }
128 } else {
130 result.append(c);
132 *ok = false;
133 return QString();
134 }
135 }
136 }
137
138 if (result.isEmpty()) {
139 *ok = false;
140 return QString();
141 }
142
143 *ok = true;
144 if (namespaces && !prefix.isEmpty())
145 return prefix + u':' + result;
146 return result;
147}
148
149// [14] CharData ::= [^<&]* - ([^<&]* ']]>' [^<&]*)
150// '<', '&' and "]]>" will be escaped when writing
151
152static QString fixedCharData(const QString &data, bool *ok)
153{
155 *ok = true;
156 return data;
157 }
158
161 while (it.hasNext()) {
162 const char32_t c = it.next(QChar::Null);
163 if (QXmlUtils::isChar(c)) {
164 result.append(QChar::fromUcs4(c));
166 *ok = false;
167 return QString();
168 }
169 }
170
171 *ok = true;
172 return result;
173}
174
175// [15] Comment ::= '<!--' ((Char - '-') | ('-' (Char - '-')))* '-->'
176// can't escape "--", since entities are not recognised within comments
177
178static QString fixedComment(const QString &data, bool *ok)
179{
181 *ok = true;
182 return data;
183 }
184
185 QString fixedData = fixedCharData(data, ok);
186 if (!*ok)
187 return QString();
188
189 for (;;) {
190 qsizetype idx = fixedData.indexOf("--"_L1);
191 if (idx == -1)
192 break;
194 *ok = false;
195 return QString();
196 }
197 fixedData.remove(idx, 2);
198 }
199
200 *ok = true;
201 return fixedData;
202}
203
204// [20] CData ::= (Char* - (Char* ']]>' Char*))
205// can't escape "]]>", since entities are not recognised within comments
206
208{
210 *ok = true;
211 return data;
212 }
213
214 QString fixedData = fixedCharData(data, ok);
215 if (!*ok)
216 return QString();
217
218 for (;;) {
219 qsizetype idx = fixedData.indexOf("]]>"_L1);
220 if (idx == -1)
221 break;
223 *ok = false;
224 return QString();
225 }
226 fixedData.remove(idx, 3);
227 }
228
229 *ok = true;
230 return fixedData;
231}
232
233// [16] PI ::= '<?' PITarget (S (Char* - (Char* '?>' Char*)))? '?>'
234
235static QString fixedPIData(const QString &data, bool *ok)
236{
238 *ok = true;
239 return data;
240 }
241
242 QString fixedData = fixedCharData(data, ok);
243 if (!*ok)
244 return QString();
245
246 for (;;) {
247 qsizetype idx = fixedData.indexOf("?>"_L1);
248 if (idx == -1)
249 break;
251 *ok = false;
252 return QString();
253 }
254 fixedData.remove(idx, 2);
255 }
256
257 *ok = true;
258 return fixedData;
259}
260
261// [12] PubidLiteral ::= '"' PubidChar* '"' | "'" (PubidChar - "'")* "'"
262// The correct quote will be chosen when writing
263
265{
267 *ok = true;
268 return data;
269 }
270
272
274 result = data;
276 *ok = false;
277 return QString();
278 }
279
280 if (result.indexOf(u'\'') != -1 && result.indexOf(u'"') != -1) {
282 *ok = false;
283 return QString();
284 } else {
285 result.remove(u'\'');
286 }
287 }
288
289 *ok = true;
290 return result;
291}
292
293// [11] SystemLiteral ::= ('"' [^"]* '"') | ("'" [^']* "'")
294// The correct quote will be chosen when writing
295
297{
299 *ok = true;
300 return data;
301 }
302
304
305 if (result.indexOf(u'\'') != -1 && result.indexOf(u'"') != -1) {
307 *ok = false;
308 return QString();
309 } else {
310 result.remove(u'\'');
311 }
312 }
313
314 *ok = true;
315 return result;
316}
317
318/**************************************************************
319 *
320 * QDomImplementationPrivate
321 *
322 **************************************************************/
323
325{
326 return new QDomImplementationPrivate;
327}
328
329/**************************************************************
330 *
331 * QDomImplementation
332 *
333 **************************************************************/
334
372{
373 impl = nullptr;
374}
375
380{
381 impl = x.impl;
382 if (impl)
383 impl->ref.ref();
384}
385
387{
388 // We want to be co-owners, so increase the reference count
389 impl = p;
390 if (impl)
391 impl->ref.ref();
392}
393
398{
399 if (x.impl)
400 x.impl->ref.ref();
401 if (impl && !impl->ref.deref())
402 delete impl;
403 impl = x.impl;
404 return *this;
405}
406
412{
413 return (impl == x.impl);
414}
415
421{
422 return (impl != x.impl);
423}
424
429{
430 if (impl && !impl->ref.deref())
431 delete impl;
432}
433
444bool QDomImplementation::hasFeature(const QString& feature, const QString& version) const
445{
446 if (feature == "XML"_L1) {
447 if (version.isEmpty() || version == "1.0"_L1)
448 return true;
449 }
450 // ### add DOM level 2 features
451 return false;
452}
453
487{
488 bool ok;
489 QString fixedName = fixedXmlName(qName, &ok, true);
490 if (!ok)
491 return QDomDocumentType();
492
493 QString fixedPublicId = fixedPubidLiteral(publicId, &ok);
494 if (!ok)
495 return QDomDocumentType();
496
497 QString fixedSystemId = fixedSystemLiteral(systemId, &ok);
498 if (!ok)
499 return QDomDocumentType();
500
502 dt->name = fixedName;
503 if (systemId.isNull()) {
504 dt->publicId.clear();
505 dt->systemId.clear();
506 } else {
507 dt->publicId = fixedPublicId;
508 dt->systemId = fixedSystemId;
509 }
510 dt->ref.deref();
511 return QDomDocumentType(dt);
512}
513
520{
521 QDomDocument doc(doctype);
522 QDomElement root = doc.createElementNS(nsURI, qName);
523 if (root.isNull())
524 return QDomDocument();
525 doc.appendChild(root);
526 return doc;
527}
528
534{
535 return (impl == nullptr);
536}
537
577{
579}
580
597{
599}
600
601/**************************************************************
602 *
603 * QDomNodeListPrivate
604 *
605 **************************************************************/
606
608{
609 node_impl = n_impl;
610 if (node_impl)
611 node_impl->ref.ref();
612 timestamp = 0;
613}
614
616 ref(1)
617{
618 node_impl = n_impl;
619 if (node_impl)
620 node_impl->ref.ref();
621 tagname = name;
622 timestamp = 0;
623}
624
626 ref(1)
627{
628 node_impl = n_impl;
629 if (node_impl)
630 node_impl->ref.ref();
631 tagname = localName;
632 nsURI = _nsURI;
633 timestamp = 0;
634}
635
637{
638 if (node_impl && !node_impl->ref.deref())
639 delete node_impl;
640}
641
643{
644 return (node_impl == other.node_impl) && (tagname == other.tagname);
645}
646
648{
649 return (node_impl != other.node_impl) || (tagname != other.tagname);
650}
651
653{
654 if (!node_impl)
655 return;
656
657 const QDomDocumentPrivate *const doc = node_impl->ownerDocument();
658 if (doc && timestamp != doc->nodeListTime)
659 timestamp = doc->nodeListTime;
660
662
663 list.clear();
664 if (tagname.isNull()) {
665 while (p) {
666 list.append(p);
667 p = p->next;
668 }
669 } else if (nsURI.isNull()) {
670 while (p && p != node_impl) {
671 if (p->isElement() && p->nodeName() == tagname) {
672 list.append(p);
673 }
674 if (p->first)
675 p = p->first;
676 else if (p->next)
677 p = p->next;
678 else {
679 p = p->parent();
680 while (p && p != node_impl && !p->next)
681 p = p->parent();
682 if (p && p != node_impl)
683 p = p->next;
684 }
685 }
686 } else {
687 while (p && p != node_impl) {
688 if (p->isElement() && p->name==tagname && p->namespaceURI==nsURI) {
689 list.append(p);
690 }
691 if (p->first)
692 p = p->first;
693 else if (p->next)
694 p = p->next;
695 else {
696 p = p->parent();
697 while (p && p != node_impl && !p->next)
698 p = p->parent();
699 if (p && p != node_impl)
700 p = p->next;
701 }
702 }
703 }
704}
705
707{
708 if (!node_impl)
709 return nullptr;
710
711 const QDomDocumentPrivate *const doc = node_impl->ownerDocument();
712 if (!doc || timestamp != doc->nodeListTime)
713 createList();
714
715 if (index >= list.size())
716 return nullptr;
717
718 return list.at(index);
719}
720
722{
723 if (!node_impl)
724 return 0;
725
726 const QDomDocumentPrivate *const doc = node_impl->ownerDocument();
727 if (!doc || timestamp != doc->nodeListTime) {
728 QDomNodeListPrivate *that = const_cast<QDomNodeListPrivate *>(this);
729 that->createList();
730 }
731
732 return list.size();
733}
734
735/**************************************************************
736 *
737 * QDomNodeList
738 *
739 **************************************************************/
740
770 : impl(nullptr)
771{
772}
773
775 : impl(p)
776{
777}
778
783{
784 impl = n.impl;
785 if (impl)
786 impl->ref.ref();
787}
788
793{
794 if (n.impl)
795 n.impl->ref.ref();
796 if (impl && !impl->ref.deref())
797 delete impl;
798 impl = n.impl;
799 return *this;
800}
801
807{
808 if (impl == n.impl)
809 return true;
810 if (!impl || !n.impl)
811 return false;
812 return (*impl == *n.impl);
813}
814
820{
821 return !operator==(n);
822}
823
828{
829 if (impl && !impl->ref.deref())
830 delete impl;
831}
832
843{
844 if (!impl)
845 return QDomNode();
846
847 return QDomNode(impl->item(index));
848}
849
854{
855 if (!impl)
856 return 0;
857 return impl->length();
858}
859
890/**************************************************************
891 *
892 * QDomNodePrivate
893 *
894 **************************************************************/
895
897{
898 ownerNode = doc;
899 hasParent = false;
900}
901
903{
904 if (par)
905 setParent(par);
906 else
907 setOwnerDocument(doc);
908 prev = nullptr;
909 next = nullptr;
910 first = nullptr;
911 last = nullptr;
913 lineNumber = -1;
914 columnNumber = -1;
915}
916
918{
919 setOwnerDocument(n->ownerDocument());
920 prev = nullptr;
921 next = nullptr;
922 first = nullptr;
923 last = nullptr;
924
925 name = n->name;
926 value = n->value;
927 prefix = n->prefix;
928 namespaceURI = n->namespaceURI;
929 createdWithDom1Interface = n->createdWithDom1Interface;
930 lineNumber = -1;
931 columnNumber = -1;
932
933 if (!deep)
934 return;
935
936 for (QDomNodePrivate* x = n->first; x; x = x->next)
937 appendChild(x->cloneNode(true));
938}
939
941{
944
945 while (p) {
946 n = p->next;
947 if (!p->ref.deref())
948 delete p;
949 else
950 p->setNoParent();
951 p = n;
952 }
953 first = nullptr;
954 last = nullptr;
955}
956
958{
961
962 while (p) {
963 n = p->next;
964 if (!p->ref.deref())
965 delete p;
966 p = n;
967 }
968 first = nullptr;
969 last = nullptr;
970}
971
973{
975 while (p) {
976 if (p->nodeName() == n)
977 return p;
978 p = p->next;
979 }
980 return nullptr;
981}
982
983
985{
986 // Error check
987 if (!newChild)
988 return nullptr;
989
990 // Error check
991 if (newChild == refChild)
992 return nullptr;
993
994 // Error check
995 if (refChild && refChild->parent() != this)
996 return nullptr;
997
998 // "mark lists as dirty"
999 QDomDocumentPrivate *const doc = ownerDocument();
1000 if (doc)
1001 doc->nodeListTime++;
1002
1003 // Special handling for inserting a fragment. We just insert
1004 // all elements of the fragment instead of the fragment itself.
1005 if (newChild->isDocumentFragment()) {
1006 // Fragment is empty ?
1007 if (newChild->first == nullptr)
1008 return newChild;
1009
1010 // New parent
1011 QDomNodePrivate* n = newChild->first;
1012 while (n) {
1013 n->setParent(this);
1014 n = n->next;
1015 }
1016
1017 // Insert at the beginning ?
1018 if (!refChild || refChild->prev == nullptr) {
1019 if (first)
1020 first->prev = newChild->last;
1021 newChild->last->next = first;
1022 if (!last)
1023 last = newChild->last;
1024 first = newChild->first;
1025 } else {
1026 // Insert in the middle
1027 newChild->last->next = refChild;
1028 newChild->first->prev = refChild->prev;
1029 refChild->prev->next = newChild->first;
1030 refChild->prev = newChild->last;
1031 }
1032
1033 // No need to increase the reference since QDomDocumentFragment
1034 // does not decrease the reference.
1035
1036 // Remove the nodes from the fragment
1037 newChild->first = nullptr;
1038 newChild->last = nullptr;
1039 return newChild;
1040 }
1041
1042 // No more errors can occur now, so we take
1043 // ownership of the node.
1044 newChild->ref.ref();
1045
1046 if (newChild->parent())
1047 newChild->parent()->removeChild(newChild);
1048
1049 newChild->setParent(this);
1050
1051 if (!refChild) {
1052 if (first)
1053 first->prev = newChild;
1054 newChild->next = first;
1055 if (!last)
1056 last = newChild;
1057 first = newChild;
1058 return newChild;
1059 }
1060
1061 if (refChild->prev == nullptr) {
1062 if (first)
1063 first->prev = newChild;
1064 newChild->next = first;
1065 if (!last)
1066 last = newChild;
1067 first = newChild;
1068 return newChild;
1069 }
1070
1071 newChild->next = refChild;
1072 newChild->prev = refChild->prev;
1073 refChild->prev->next = newChild;
1074 refChild->prev = newChild;
1075
1076 return newChild;
1077}
1078
1080{
1081 // Error check
1082 if (!newChild)
1083 return nullptr;
1084
1085 // Error check
1086 if (newChild == refChild)
1087 return nullptr;
1088
1089 // Error check
1090 if (refChild && refChild->parent() != this)
1091 return nullptr;
1092
1093 // "mark lists as dirty"
1094 QDomDocumentPrivate *const doc = ownerDocument();
1095 if (doc)
1096 doc->nodeListTime++;
1097
1098 // Special handling for inserting a fragment. We just insert
1099 // all elements of the fragment instead of the fragment itself.
1100 if (newChild->isDocumentFragment()) {
1101 // Fragment is empty ?
1102 if (newChild->first == nullptr)
1103 return newChild;
1104
1105 // New parent
1106 QDomNodePrivate* n = newChild->first;
1107 while (n) {
1108 n->setParent(this);
1109 n = n->next;
1110 }
1111
1112 // Insert at the end
1113 if (!refChild || refChild->next == nullptr) {
1114 if (last)
1115 last->next = newChild->first;
1116 newChild->first->prev = last;
1117 if (!first)
1118 first = newChild->first;
1119 last = newChild->last;
1120 } else { // Insert in the middle
1121 newChild->first->prev = refChild;
1122 newChild->last->next = refChild->next;
1123 refChild->next->prev = newChild->last;
1124 refChild->next = newChild->first;
1125 }
1126
1127 // No need to increase the reference since QDomDocumentFragment
1128 // does not decrease the reference.
1129
1130 // Remove the nodes from the fragment
1131 newChild->first = nullptr;
1132 newChild->last = nullptr;
1133 return newChild;
1134 }
1135
1136 // Release new node from its current parent
1137 if (newChild->parent())
1138 newChild->parent()->removeChild(newChild);
1139
1140 // No more errors can occur now, so we take
1141 // ownership of the node
1142 newChild->ref.ref();
1143
1144 newChild->setParent(this);
1145
1146 // Insert at the end
1147 if (!refChild) {
1148 if (last)
1149 last->next = newChild;
1150 newChild->prev = last;
1151 if (!first)
1152 first = newChild;
1153 last = newChild;
1154 return newChild;
1155 }
1156
1157 if (refChild->next == nullptr) {
1158 if (last)
1159 last->next = newChild;
1160 newChild->prev = last;
1161 if (!first)
1162 first = newChild;
1163 last = newChild;
1164 return newChild;
1165 }
1166
1167 newChild->prev = refChild;
1168 newChild->next = refChild->next;
1169 refChild->next->prev = newChild;
1170 refChild->next = newChild;
1171
1172 return newChild;
1173}
1174
1176{
1177 if (!newChild || !oldChild)
1178 return nullptr;
1179 if (oldChild->parent() != this)
1180 return nullptr;
1181 if (newChild == oldChild)
1182 return nullptr;
1183
1184 // mark lists as dirty
1185 QDomDocumentPrivate *const doc = ownerDocument();
1186 if (doc)
1187 doc->nodeListTime++;
1188
1189 // Special handling for inserting a fragment. We just insert
1190 // all elements of the fragment instead of the fragment itself.
1191 if (newChild->isDocumentFragment()) {
1192 // Fragment is empty ?
1193 if (newChild->first == nullptr)
1194 return newChild;
1195
1196 // New parent
1197 QDomNodePrivate* n = newChild->first;
1198 while (n) {
1199 n->setParent(this);
1200 n = n->next;
1201 }
1202
1203
1204 if (oldChild->next)
1205 oldChild->next->prev = newChild->last;
1206 if (oldChild->prev)
1207 oldChild->prev->next = newChild->first;
1208
1209 newChild->last->next = oldChild->next;
1210 newChild->first->prev = oldChild->prev;
1211
1212 if (first == oldChild)
1213 first = newChild->first;
1214 if (last == oldChild)
1215 last = newChild->last;
1216
1217 oldChild->setNoParent();
1218 oldChild->next = nullptr;
1219 oldChild->prev = nullptr;
1220
1221 // No need to increase the reference since QDomDocumentFragment
1222 // does not decrease the reference.
1223
1224 // Remove the nodes from the fragment
1225 newChild->first = nullptr;
1226 newChild->last = nullptr;
1227
1228 // We are no longer interested in the old node
1229 oldChild->ref.deref();
1230
1231 return oldChild;
1232 }
1233
1234 // No more errors can occur now, so we take
1235 // ownership of the node
1236 newChild->ref.ref();
1237
1238 // Release new node from its current parent
1239 if (newChild->parent())
1240 newChild->parent()->removeChild(newChild);
1241
1242 newChild->setParent(this);
1243
1244 if (oldChild->next)
1245 oldChild->next->prev = newChild;
1246 if (oldChild->prev)
1247 oldChild->prev->next = newChild;
1248
1249 newChild->next = oldChild->next;
1250 newChild->prev = oldChild->prev;
1251
1252 if (first == oldChild)
1253 first = newChild;
1254 if (last == oldChild)
1255 last = newChild;
1256
1257 oldChild->setNoParent();
1258 oldChild->next = nullptr;
1259 oldChild->prev = nullptr;
1260
1261 // We are no longer interested in the old node
1262 oldChild->ref.deref();
1263
1264 return oldChild;
1265}
1266
1268{
1269 // Error check
1270 if (oldChild->parent() != this)
1271 return nullptr;
1272
1273 // "mark lists as dirty"
1274 QDomDocumentPrivate *const doc = ownerDocument();
1275 if (doc)
1276 doc->nodeListTime++;
1277
1278 // Perhaps oldChild was just created with "createElement" or that. In this case
1279 // its parent is QDomDocument but it is not part of the documents child list.
1280 if (oldChild->next == nullptr && oldChild->prev == nullptr && first != oldChild)
1281 return nullptr;
1282
1283 if (oldChild->next)
1284 oldChild->next->prev = oldChild->prev;
1285 if (oldChild->prev)
1286 oldChild->prev->next = oldChild->next;
1287
1288 if (last == oldChild)
1289 last = oldChild->prev;
1290 if (first == oldChild)
1291 first = oldChild->next;
1292
1293 oldChild->setNoParent();
1294 oldChild->next = nullptr;
1295 oldChild->prev = nullptr;
1296
1297 // We are no longer interested in the old node
1298 oldChild->ref.deref();
1299
1300 return oldChild;
1301}
1302
1304{
1305 // No reference manipulation needed. Done in insertAfter.
1306 return insertAfter(newChild, nullptr);
1307}
1308
1310{
1311 QDomNodePrivate* p = this;
1312 while (p && !p->isDocument()) {
1313 if (!p->hasParent)
1314 return static_cast<QDomDocumentPrivate *>(p->ownerNode);
1315 p = p->parent();
1316 }
1317
1318 return static_cast<QDomDocumentPrivate *>(p);
1319}
1320
1322{
1323 QDomNodePrivate* p = new QDomNodePrivate(this, deep);
1324 // We are not interested in this node
1325 p->ref.deref();
1326 return p;
1327}
1328
1330{
1332 QDomTextPrivate* t = nullptr;
1333
1334 while (p) {
1335 if (p->isText()) {
1336 if (t) {
1337 QDomNodePrivate* tmp = p->next;
1338 t->appendData(p->nodeValue());
1339 n->removeChild(p);
1340 p = tmp;
1341 } else {
1342 t = static_cast<QDomTextPrivate *>(p);
1343 p = p->next;
1344 }
1345 } else {
1346 p = p->next;
1347 t = nullptr;
1348 }
1349 }
1350}
1352{
1353 // ### This one has moved from QDomElementPrivate to this position. It is
1354 // not tested.
1355 qNormalizeNode(this);
1356}
1357
1361void QDomNodePrivate::save(QTextStream& s, int depth, int indent) const
1362{
1363 const QDomNodePrivate* n = first;
1364 while (n) {
1365 n->save(s, depth, indent);
1366 n = n->next;
1367 }
1368}
1369
1370void QDomNodePrivate::setLocation(int lineNumber, int columnNumber)
1371{
1372 this->lineNumber = lineNumber;
1373 this->columnNumber = columnNumber;
1374}
1375
1376/**************************************************************
1377 *
1378 * QDomNode
1379 *
1380 **************************************************************/
1381
1382#define IMPL static_cast<QDomNodePrivate *>(impl)
1383
1472 : impl(nullptr)
1473{
1474}
1475
1484{
1485 impl = n.impl;
1486 if (impl)
1487 impl->ref.ref();
1488}
1489
1494{
1495 impl = n;
1496 if (impl)
1497 impl->ref.ref();
1498}
1499
1508{
1509 if (n.impl)
1510 n.impl->ref.ref();
1511 if (impl && !impl->ref.deref())
1512 delete impl;
1513 impl = n.impl;
1514 return *this;
1515}
1516
1538{
1539 return (impl == n.impl);
1540}
1541
1547{
1548 return (impl != n.impl);
1549}
1550
1555{
1556 if (impl && !impl->ref.deref())
1557 delete impl;
1558}
1559
1590{
1591 if (!impl)
1592 return QString();
1593
1594 if (!IMPL->prefix.isEmpty())
1595 return IMPL->prefix + u':' + IMPL->name;
1596 return IMPL->name;
1597}
1598
1618{
1619 if (!impl)
1620 return QString();
1621 return IMPL->value;
1622}
1623
1630{
1631 if (!impl)
1632 return;
1633 IMPL->setNodeValue(v);
1634}
1635
1665{
1666 if (!impl)
1667 return QDomNode::BaseNode;
1668 return IMPL->nodeType();
1669}
1670
1676{
1677 if (!impl)
1678 return QDomNode();
1679 return QDomNode(IMPL->parent());
1680}
1681
1701{
1702 if (!impl)
1703 return QDomNodeList();
1705}
1706
1715{
1716 if (!impl)
1717 return QDomNode();
1718 return QDomNode(IMPL->first);
1719}
1720
1729{
1730 if (!impl)
1731 return QDomNode();
1732 return QDomNode(IMPL->last);
1733}
1734
1749{
1750 if (!impl)
1751 return QDomNode();
1752 return QDomNode(IMPL->prev);
1753}
1754
1769{
1770 if (!impl)
1771 return QDomNode();
1772 return QDomNode(IMPL->next);
1773}
1774
1775
1776// ###### don't think this is part of the DOM and
1785{
1786 if (!impl || !impl->isElement())
1787 return QDomNamedNodeMap();
1788
1789 return QDomNamedNodeMap(static_cast<QDomElementPrivate *>(impl)->attributes());
1790}
1791
1796{
1797 if (!impl)
1798 return QDomDocument();
1799 return QDomDocument(IMPL->ownerDocument());
1800}
1801
1811{
1812 if (!impl)
1813 return QDomNode();
1814 return QDomNode(IMPL->cloneNode(deep));
1815}
1816
1824{
1825 if (!impl)
1826 return;
1827 IMPL->normalize();
1828}
1829
1837bool QDomNode::isSupported(const QString& feature, const QString& version) const
1838{
1840 return i.hasFeature(feature, version);
1841}
1842
1856{
1857 if (!impl)
1858 return QString();
1859 return IMPL->namespaceURI;
1860}
1861
1885{
1886 if (!impl)
1887 return QString();
1888 return IMPL->prefix;
1889}
1890
1906{
1907 if (!impl || IMPL->prefix.isNull())
1908 return;
1909 if (isAttr() || isElement())
1910 IMPL->prefix = pre;
1911}
1912
1926{
1927 if (!impl || IMPL->createdWithDom1Interface)
1928 return QString();
1929 return IMPL->name;
1930}
1931
1938{
1939 if (!impl || !impl->isElement())
1940 return false;
1941 return static_cast<QDomElementPrivate *>(impl)->hasAttributes();
1942}
1943
1965QDomNode QDomNode::insertBefore(const QDomNode& newChild, const QDomNode& refChild)
1966{
1967 if (!impl)
1968 return QDomNode();
1969 return QDomNode(IMPL->insertBefore(newChild.impl, refChild.impl));
1970}
1971
1993QDomNode QDomNode::insertAfter(const QDomNode& newChild, const QDomNode& refChild)
1994{
1995 if (!impl)
1996 return QDomNode();
1997 return QDomNode(IMPL->insertAfter(newChild.impl, refChild.impl));
1998}
1999
2015QDomNode QDomNode::replaceChild(const QDomNode& newChild, const QDomNode& oldChild)
2016{
2017 if (!impl || !newChild.impl || !oldChild.impl)
2018 return QDomNode();
2019 return QDomNode(IMPL->replaceChild(newChild.impl, oldChild.impl));
2020}
2021
2031{
2032 if (!impl)
2033 return QDomNode();
2034
2035 if (oldChild.isNull())
2036 return QDomNode();
2037
2038 return QDomNode(IMPL->removeChild(oldChild.impl));
2039}
2040
2066{
2067 if (!impl) {
2068 qWarning("Calling appendChild() on a null node does nothing.");
2069 return QDomNode();
2070 }
2071 return QDomNode(IMPL->appendChild(newChild.impl));
2072}
2073
2079{
2080 if (!impl)
2081 return false;
2082 return IMPL->first != nullptr;
2083}
2084
2090{
2091 return (impl == nullptr);
2092}
2093
2101{
2102 if (impl && !impl->ref.deref())
2103 delete impl;
2104 impl = nullptr;
2105}
2106
2117{
2118 if (!impl)
2119 return QDomNode();
2120 return QDomNode(impl->namedItem(name));
2121}
2122
2148void QDomNode::save(QTextStream& stream, int indent, EncodingPolicy encodingPolicy) const
2149{
2150 if (!impl)
2151 return;
2152
2153 if (isDocument())
2154 static_cast<const QDomDocumentPrivate *>(impl)->saveDocument(stream, indent, encodingPolicy);
2155 else
2156 IMPL->save(stream, 1, indent);
2157}
2158
2166{
2167 node.save(str, 1);
2168
2169 return str;
2170}
2171
2182{
2183 if (impl)
2184 return impl->isAttr();
2185 return false;
2186}
2187
2199{
2200 if (impl)
2201 return impl->isCDATASection();
2202 return false;
2203}
2204
2216{
2217 if (impl)
2218 return impl->isDocumentFragment();
2219 return false;
2220}
2221
2231{
2232 if (impl)
2233 return impl->isDocument();
2234 return false;
2235}
2236
2248{
2249 if (impl)
2250 return impl->isDocumentType();
2251 return false;
2252}
2253
2263{
2264 if (impl)
2265 return impl->isElement();
2266 return false;
2267}
2268
2280{
2281 if (impl)
2282 return impl->isEntityReference();
2283 return false;
2284}
2285
2295{
2296 if (impl)
2297 return impl->isText();
2298 return false;
2299}
2300
2310{
2311 if (impl)
2312 return impl->isEntity();
2313 return false;
2314}
2315
2325{
2326 if (impl)
2327 return impl->isNotation();
2328 return false;
2329}
2330
2342{
2343 if (impl)
2344 return impl->isProcessingInstruction();
2345 return false;
2346}
2347
2359{
2360 if (impl)
2361 return impl->isCharacterData();
2362 return false;
2363}
2364
2374{
2375 if (impl)
2376 return impl->isComment();
2377 return false;
2378}
2379
2380#undef IMPL
2381
2392QDomElement QDomNode::firstChildElement(const QString &tagName, const QString &namespaceURI) const
2393{
2394 for (QDomNode child = firstChild(); !child.isNull(); child = child.nextSibling()) {
2395 if (child.isElement() && (namespaceURI.isEmpty() || child.namespaceURI() == namespaceURI)) {
2396 QDomElement elt = child.toElement();
2397 if (tagName.isEmpty() || elt.tagName() == tagName)
2398 return elt;
2399 }
2400 }
2401 return QDomElement();
2402}
2403
2414QDomElement QDomNode::lastChildElement(const QString &tagName, const QString &namespaceURI) const
2415{
2416 for (QDomNode child = lastChild(); !child.isNull(); child = child.previousSibling()) {
2417 if (child.isElement() && (namespaceURI.isEmpty() || child.namespaceURI() == namespaceURI)) {
2418 QDomElement elt = child.toElement();
2419 if (tagName.isEmpty() || elt.tagName() == tagName)
2420 return elt;
2421 }
2422 }
2423 return QDomElement();
2424}
2425
2437QDomElement QDomNode::nextSiblingElement(const QString &tagName, const QString &namespaceURI) const
2438{
2439 for (QDomNode sib = nextSibling(); !sib.isNull(); sib = sib.nextSibling()) {
2440 if (sib.isElement() && (namespaceURI.isEmpty() || sib.namespaceURI() == namespaceURI)) {
2441 QDomElement elt = sib.toElement();
2442 if (tagName.isEmpty() || elt.tagName() == tagName)
2443 return elt;
2444 }
2445 }
2446 return QDomElement();
2447}
2448
2460QDomElement QDomNode::previousSiblingElement(const QString &tagName, const QString &namespaceURI) const
2461{
2462 for (QDomNode sib = previousSibling(); !sib.isNull(); sib = sib.previousSibling()) {
2463 if (sib.isElement() && (namespaceURI.isEmpty() || sib.namespaceURI() == namespaceURI)) {
2464 QDomElement elt = sib.toElement();
2465 if (tagName.isEmpty() || elt.tagName() == tagName)
2466 return elt;
2467 }
2468 }
2469 return QDomElement();
2470}
2471
2482{
2483 return impl ? impl->lineNumber : -1;
2484}
2485
2496{
2497 return impl ? impl->columnNumber : -1;
2498}
2499
2500
2501/**************************************************************
2502 *
2503 * QDomNamedNodeMapPrivate
2504 *
2505 **************************************************************/
2506
2508{
2509 readonly = false;
2510 parent = n;
2511 appendToParent = false;
2512}
2513
2515{
2516 clearMap();
2517}
2518
2520{
2521 std::unique_ptr<QDomNamedNodeMapPrivate> m(new QDomNamedNodeMapPrivate(p));
2522 m->readonly = readonly;
2523 m->appendToParent = appendToParent;
2524
2525 auto it = map.constBegin();
2526 for (; it != map.constEnd(); ++it) {
2527 QDomNodePrivate *new_node = it.value()->cloneNode();
2528 new_node->setParent(p);
2529 m->setNamedItem(new_node);
2530 }
2531
2532 // we are no longer interested in ownership
2533 m->ref.deref();
2534 return m.release();
2535}
2536
2538{
2539 // Dereference all of our children if we took references
2540 if (!appendToParent) {
2541 auto it = map.constBegin();
2542 for (; it != map.constEnd(); ++it)
2543 if (!it.value()->ref.deref())
2544 delete it.value();
2545 }
2546 map.clear();
2547}
2548
2550{
2551 auto it = map.find(name);
2552 return it == map.end() ? nullptr : it.value();
2553}
2554
2556{
2557 auto it = map.constBegin();
2559 for (; it != map.constEnd(); ++it) {
2560 n = it.value();
2561 if (!n->prefix.isNull()) {
2562 // node has a namespace
2563 if (n->namespaceURI == nsURI && n->name == localName)
2564 return n;
2565 }
2566 }
2567 return nullptr;
2568}
2569
2571{
2572 if (readonly || !arg)
2573 return nullptr;
2574
2575 if (appendToParent)
2576 return parent->appendChild(arg);
2577
2578 QDomNodePrivate *n = map.value(arg->nodeName());
2579 // We take a reference
2580 arg->ref.ref();
2581 map.insert(arg->nodeName(), arg);
2582 return n;
2583}
2584
2586{
2587 if (readonly || !arg)
2588 return nullptr;
2589
2590 if (appendToParent)
2591 return parent->appendChild(arg);
2592
2593 if (!arg->prefix.isNull()) {
2594 // node has a namespace
2595 QDomNodePrivate *n = namedItemNS(arg->namespaceURI, arg->name);
2596 // We take a reference
2597 arg->ref.ref();
2598 map.insert(arg->nodeName(), arg);
2599 return n;
2600 } else {
2601 // ### check the following code if it is ok
2602 return setNamedItem(arg);
2603 }
2604}
2605
2607{
2608 if (readonly)
2609 return nullptr;
2610
2612 if (p == nullptr)
2613 return nullptr;
2614 if (appendToParent)
2615 return parent->removeChild(p);
2616
2617 map.remove(p->nodeName());
2618 // We took a reference, so we have to free one here
2619 p->ref.deref();
2620 return p;
2621}
2622
2624{
2625 if (index >= length() || index < 0)
2626 return nullptr;
2627 return std::next(map.begin(), index).value();
2628}
2629
2631{
2632 return map.size();
2633}
2634
2636{
2637 return map.contains(name);
2638}
2639
2640bool QDomNamedNodeMapPrivate::containsNS(const QString& nsURI, const QString & localName) const
2641{
2642 return namedItemNS(nsURI, localName) != nullptr;
2643}
2644
2645/**************************************************************
2646 *
2647 * QDomNamedNodeMap
2648 *
2649 **************************************************************/
2650
2651#define IMPL static_cast<QDomNamedNodeMapPrivate *>(impl)
2652
2695 : impl(nullptr)
2696{
2697}
2698
2703{
2704 impl = n.impl;
2705 if (impl)
2706 impl->ref.ref();
2707}
2708
2710{
2711 impl = n;
2712 if (impl)
2713 impl->ref.ref();
2714}
2715
2720{
2721 if (n.impl)
2722 n.impl->ref.ref();
2723 if (impl && !impl->ref.deref())
2724 delete impl;
2725 impl = n.impl;
2726 return *this;
2727}
2728
2734{
2735 return (impl == n.impl);
2736}
2737
2743{
2744 return (impl != n.impl);
2745}
2746
2751{
2752 if (impl && !impl->ref.deref())
2753 delete impl;
2754}
2755
2766{
2767 if (!impl)
2768 return QDomNode();
2769 return QDomNode(IMPL->namedItem(name));
2770}
2771
2783{
2784 if (!impl)
2785 return QDomNode();
2786 return QDomNode(IMPL->setNamedItem(static_cast<QDomNodePrivate *>(newNode.impl)));
2787}
2788
2799{
2800 if (!impl)
2801 return QDomNode();
2802 return QDomNode(IMPL->removeNamedItem(name));
2803}
2804
2814{
2815 if (!impl)
2816 return QDomNode();
2817 return QDomNode(IMPL->item(index));
2818}
2819
2829QDomNode QDomNamedNodeMap::namedItemNS(const QString& nsURI, const QString& localName) const
2830{
2831 if (!impl)
2832 return QDomNode();
2833 return QDomNode(IMPL->namedItemNS(nsURI, localName));
2834}
2835
2845{
2846 if (!impl)
2847 return QDomNode();
2848 return QDomNode(IMPL->setNamedItemNS(static_cast<QDomNodePrivate *>(newNode.impl)));
2849}
2850
2863{
2864 if (!impl)
2865 return QDomNode();
2866 QDomNodePrivate *n = IMPL->namedItemNS(nsURI, localName);
2867 if (!n)
2868 return QDomNode();
2869 return QDomNode(IMPL->removeNamedItem(n->name));
2870}
2871
2878{
2879 if (!impl)
2880 return 0;
2881 return IMPL->length();
2882}
2883
2912{
2913 if (!impl)
2914 return false;
2915 return IMPL->contains(name);
2916}
2917
2918#undef IMPL
2919
2920/**************************************************************
2921 *
2922 * QDomDocumentTypePrivate
2923 *
2924 **************************************************************/
2925
2927 : QDomNodePrivate(doc, parent)
2928{
2929 init();
2930}
2931
2933 : QDomNodePrivate(n, deep)
2934{
2935 init();
2936 // Refill the maps with our new children
2938 while (p) {
2939 if (p->isEntity())
2940 // Don't use normal insert function since we would create infinite recursion
2941 entities->map.insert(p->nodeName(), p);
2942 if (p->isNotation())
2943 // Don't use normal insert function since we would create infinite recursion
2944 notations->map.insert(p->nodeName(), p);
2945 p = p->next;
2946 }
2947}
2948
2950{
2951 if (!entities->ref.deref())
2952 delete entities;
2953 if (!notations->ref.deref())
2954 delete notations;
2955}
2956
2958{
2960 QT_TRY {
2962 publicId.clear();
2963 systemId.clear();
2965
2968 } QT_CATCH(...) {
2969 delete entities;
2970 QT_RETHROW;
2971 }
2972}
2973
2975{
2976 QDomNodePrivate* p = new QDomDocumentTypePrivate(this, deep);
2977 // We are not interested in this node
2978 p->ref.deref();
2979 return p;
2980}
2981
2983{
2984 // Call the original implementation
2985 QDomNodePrivate* p = QDomNodePrivate::insertBefore(newChild, refChild);
2986 // Update the maps
2987 if (p && p->isEntity())
2988 entities->map.insert(p->nodeName(), p);
2989 else if (p && p->isNotation())
2990 notations->map.insert(p->nodeName(), p);
2991
2992 return p;
2993}
2994
2996{
2997 // Call the original implementation
2998 QDomNodePrivate* p = QDomNodePrivate::insertAfter(newChild, refChild);
2999 // Update the maps
3000 if (p && p->isEntity())
3001 entities->map.insert(p->nodeName(), p);
3002 else if (p && p->isNotation())
3003 notations->map.insert(p->nodeName(), p);
3004
3005 return p;
3006}
3007
3009{
3010 // Call the original implementation
3011 QDomNodePrivate* p = QDomNodePrivate::replaceChild(newChild, oldChild);
3012 // Update the maps
3013 if (p) {
3014 if (oldChild && oldChild->isEntity())
3015 entities->map.remove(oldChild->nodeName());
3016 else if (oldChild && oldChild->isNotation())
3017 notations->map.remove(oldChild->nodeName());
3018
3019 if (p->isEntity())
3020 entities->map.insert(p->nodeName(), p);
3021 else if (p->isNotation())
3022 notations->map.insert(p->nodeName(), p);
3023 }
3024
3025 return p;
3026}
3027
3029{
3030 // Call the original implementation
3032 // Update the maps
3033 if (p && p->isEntity())
3034 entities->map.remove(p->nodeName());
3035 else if (p && p->isNotation())
3037
3038 return p;
3039}
3040
3042{
3043 return insertAfter(newChild, nullptr);
3044}
3045
3047{
3048 QChar quote = data.indexOf(u'\'') == -1 ? u'\'' : u'"';
3049 return quote + data + quote;
3050}
3051
3052void QDomDocumentTypePrivate::save(QTextStream& s, int, int indent) const
3053{
3054 if (name.isEmpty())
3055 return;
3056
3057 s << "<!DOCTYPE " << name;
3058
3059 if (!publicId.isNull()) {
3060 s << " PUBLIC " << quotedValue(publicId);
3061 if (!systemId.isNull()) {
3062 s << ' ' << quotedValue(systemId);
3063 }
3064 } else if (!systemId.isNull()) {
3065 s << " SYSTEM " << quotedValue(systemId);
3066 }
3067
3068 if (entities->length()>0 || notations->length()>0) {
3069 s << " [" << Qt::endl;
3070
3071 auto it2 = notations->map.constBegin();
3072 for (; it2 != notations->map.constEnd(); ++it2)
3073 it2.value()->save(s, 0, indent);
3074
3075 auto it = entities->map.constBegin();
3076 for (; it != entities->map.constEnd(); ++it)
3077 it.value()->save(s, 0, indent);
3078
3079 s << ']';
3080 }
3081
3082 s << '>' << Qt::endl;
3083}
3084
3085/**************************************************************
3086 *
3087 * QDomDocumentType
3088 *
3089 **************************************************************/
3090
3091#define IMPL static_cast<QDomDocumentTypePrivate *>(impl)
3092
3116{
3117}
3118
3127 : QDomNode(n)
3128{
3129}
3130
3132 : QDomNode(n)
3133{
3134}
3135
3151{
3152 if (!impl)
3153 return QString();
3154 return IMPL->nodeName();
3155}
3156
3161{
3162 if (!impl)
3163 return QDomNamedNodeMap();
3164 return QDomNamedNodeMap(IMPL->entities);
3165}
3166
3171{
3172 if (!impl)
3173 return QDomNamedNodeMap();
3174 return QDomNamedNodeMap(IMPL->notations);
3175}
3176
3184{
3185 if (!impl)
3186 return QString();
3187 return IMPL->publicId;
3188}
3189
3197{
3198 if (!impl)
3199 return QString();
3200 return IMPL->systemId;
3201}
3202
3210{
3211 if (!impl)
3212 return QString();
3213 return IMPL->internalSubset;
3214}
3215
3216/*
3217 Are these needed at all? The only difference when removing these
3218 two methods in all subclasses is that we'd get a different type
3219 for null nodes.
3220*/
3221
3230#undef IMPL
3231
3232/**************************************************************
3233 *
3234 * QDomDocumentFragmentPrivate
3235 *
3236 **************************************************************/
3237
3239 : QDomNodePrivate(doc, parent)
3240{
3241 name = u"#document-fragment"_s;
3242}
3243
3245 : QDomNodePrivate(n, deep)
3246{
3247}
3248
3250{
3252 // We are not interested in this node
3253 p->ref.deref();
3254 return p;
3255}
3256
3257/**************************************************************
3258 *
3259 * QDomDocumentFragment
3260 *
3261 **************************************************************/
3262
3292{
3293}
3294
3296 : QDomNode(n)
3297{
3298}
3299
3308 : QDomNode(x)
3309{
3310}
3311
3320
3329/**************************************************************
3330 *
3331 * QDomCharacterDataPrivate
3332 *
3333 **************************************************************/
3334
3336 const QString& data)
3337 : QDomNodePrivate(d, p)
3338{
3339 value = data;
3340 name = u"#character-data"_s;
3341}
3342
3344 : QDomNodePrivate(n, deep)
3345{
3346}
3347
3349{
3350 QDomNodePrivate* p = new QDomCharacterDataPrivate(this, deep);
3351 // We are not interested in this node
3352 p->ref.deref();
3353 return p;
3354}
3355
3357{
3358 return value.size();
3359}
3360
3361QString QDomCharacterDataPrivate::substringData(unsigned long offset, unsigned long n) const
3362{
3363 return value.mid(offset, n);
3364}
3365
3367{
3368 value.insert(offset, arg);
3369}
3370
3371void QDomCharacterDataPrivate::deleteData(unsigned long offset, unsigned long n)
3372{
3373 value.remove(offset, n);
3374}
3375
3376void QDomCharacterDataPrivate::replaceData(unsigned long offset, unsigned long n, const QString& arg)
3377{
3378 value.replace(offset, n, arg);
3379}
3380
3382{
3383 value += arg;
3384}
3385
3386/**************************************************************
3387 *
3388 * QDomCharacterData
3389 *
3390 **************************************************************/
3391
3392#define IMPL static_cast<QDomCharacterDataPrivate *>(impl)
3393
3423{
3424}
3425
3434 : QDomNode(x)
3435{
3436}
3437
3439 : QDomNode(n)
3440{
3441}
3442
3451
3459{
3460 if (!impl)
3461 return QString();
3462 return impl->nodeValue();
3463}
3464
3469{
3470 if (impl)
3472}
3473
3478{
3479 if (impl)
3480 return IMPL->dataLength();
3481 return 0;
3482}
3483
3488{
3489 if (!impl)
3490 return QString();
3491 return IMPL->substringData(offset, count);
3492}
3493
3498{
3499 if (impl)
3500 IMPL->appendData(arg);
3501}
3502
3507{
3508 if (impl)
3509 IMPL->insertData(offset, arg);
3510}
3511
3515void QDomCharacterData::deleteData(unsigned long offset, unsigned long count)
3516{
3517 if (impl)
3518 IMPL->deleteData(offset, count);
3519}
3520
3525void QDomCharacterData::replaceData(unsigned long offset, unsigned long count, const QString& arg)
3526{
3527 if (impl)
3528 IMPL->replaceData(offset, count, arg);
3529}
3530
3537{
3538 if (!impl)
3539 return CharacterDataNode;
3540 return QDomNode::nodeType();
3541}
3542
3543#undef IMPL
3544
3545/**************************************************************
3546 *
3547 * QDomAttrPrivate
3548 *
3549 **************************************************************/
3550
3553{
3554 name = name_;
3555 m_specified = false;
3556}
3557
3559 : QDomNodePrivate(d, p)
3560{
3561 qt_split_namespace(prefix, name, qName, !nsURI.isNull());
3562 namespaceURI = nsURI;
3564 m_specified = false;
3565}
3566
3568 : QDomNodePrivate(n, deep)
3569{
3570 m_specified = n->specified();
3571}
3572
3574{
3575 value = v;
3576 QDomTextPrivate *t = new QDomTextPrivate(nullptr, this, v);
3577 // keep the refcount balanced: appendChild() does a ref anyway.
3578 t->ref.deref();
3579 if (first) {
3580 auto removed = removeChild(first);
3581 if (removed && !removed->ref.loadRelaxed()) // removeChild() already deref()ed
3582 delete removed;
3583 }
3584 appendChild(t);
3585}
3586
3588{
3589 QDomNodePrivate* p = new QDomAttrPrivate(this, deep);
3590 // We are not interested in this node
3591 p->ref.deref();
3592 return p;
3593}
3594
3596{
3597 return m_specified;
3598}
3599
3600/* \internal
3601 Encode & escape \a str. Yes, it makes no sense to return a QString,
3602 but is so for legacy reasons.
3603
3604 Remember that content produced should be able to roundtrip with 2.11 End-of-Line Handling
3605 and 3.3.3 Attribute-Value Normalization.
3606
3607 If \a performAVN is true, characters will be escaped to survive Attribute Value Normalization.
3608 If \a encodeEOLs is true, characters will be escaped to survive End-of-Line Handling.
3609*/
3611 const bool encodeQuotes = true,
3612 const bool performAVN = false,
3613 const bool encodeEOLs = false)
3614{
3615 QString retval(str);
3616 int len = retval.size();
3617 int i = 0;
3618
3619 while (i < len) {
3620 const QChar ati(retval.at(i));
3621
3622 if (ati == u'<') {
3623 retval.replace(i, 1, "&lt;"_L1);
3624 len += 3;
3625 i += 4;
3626 } else if (encodeQuotes && (ati == u'"')) {
3627 retval.replace(i, 1, "&quot;"_L1);
3628 len += 5;
3629 i += 6;
3630 } else if (ati == u'&') {
3631 retval.replace(i, 1, "&amp;"_L1);
3632 len += 4;
3633 i += 5;
3634 } else if (ati == u'>' && i >= 2 && retval[i - 1] == u']' && retval[i - 2] == u']') {
3635 retval.replace(i, 1, "&gt;"_L1);
3636 len += 3;
3637 i += 4;
3638 } else if (performAVN &&
3639 (ati == QChar(0xA) ||
3640 ati == QChar(0xD) ||
3641 ati == QChar(0x9))) {
3642 const QString replacement(u"&#x"_s + QString::number(ati.unicode(), 16) + u';');
3643 retval.replace(i, 1, replacement);
3644 i += replacement.size();
3645 len += replacement.size() - 1;
3646 } else if (encodeEOLs && ati == QChar(0xD)) {
3647 retval.replace(i, 1, "&#xd;"_L1); // Replace a single 0xD with a ref for 0xD
3648 len += 4;
3649 i += 5;
3650 } else {
3651 ++i;
3652 }
3653 }
3654
3655 return retval;
3656}
3657
3659{
3660 if (namespaceURI.isNull()) {
3661 s << name << "=\"" << encodeText(value, true, true) << '\"';
3662 } else {
3663 s << prefix << ':' << name << "=\"" << encodeText(value, true, true) << '\"';
3664 /* This is a fix for 138243, as good as it gets.
3665 *
3666 * QDomElementPrivate::save() output a namespace declaration if
3667 * the element is in a namespace, no matter what. This function do as well, meaning
3668 * that we get two identical namespace declaration if we don't have the if-
3669 * statement below.
3670 *
3671 * This doesn't work when the parent element has the same prefix as us but
3672 * a different namespace. However, this can only occur by the user modifying the element,
3673 * and we don't do fixups by that anyway, and hence it's the user responsibility to not
3674 * arrive in those situations. */
3675 if (!ownerNode ||
3676 ownerNode->prefix != prefix) {
3677 s << " xmlns:" << prefix << "=\"" << encodeText(namespaceURI, true, true) << '\"';
3678 }
3679 }
3680}
3681
3682/**************************************************************
3683 *
3684 * QDomAttr
3685 *
3686 **************************************************************/
3687
3688#define IMPL static_cast<QDomAttrPrivate *>(impl)
3689
3729{
3730}
3731
3740 : QDomNode(x)
3741{
3742}
3743
3745 : QDomNode(n)
3746{
3747}
3748
3756QDomAttr &QDomAttr::operator=(const QDomAttr &x) = default;
3757
3762{
3763 if (!impl)
3764 return QString();
3765 return impl->nodeName();
3766}
3767
3775{
3776 if (!impl)
3777 return false;
3778 return IMPL->specified();
3779}
3780
3787{
3788 Q_ASSERT(impl->parent());
3789 if (!impl->parent()->isElement())
3790 return QDomElement();
3791 return QDomElement(static_cast<QDomElementPrivate *>(impl->parent()));
3792}
3793
3801{
3802 if (!impl)
3803 return QString();
3804 return impl->nodeValue();
3805}
3806
3813{
3814 if (!impl)
3815 return;
3817 IMPL->m_specified = true;
3818}
3819
3826#undef IMPL
3827
3828/**************************************************************
3829 *
3830 * QDomElementPrivate
3831 *
3832 **************************************************************/
3833
3835 const QString& tagname)
3836 : QDomNodePrivate(d, p)
3837{
3838 name = tagname;
3839 m_attr = new QDomNamedNodeMapPrivate(this);
3840}
3841
3843 const QString& nsURI, const QString& qName)
3844 : QDomNodePrivate(d, p)
3845{
3846 qt_split_namespace(prefix, name, qName, !nsURI.isNull());
3847 namespaceURI = nsURI;
3849 m_attr = new QDomNamedNodeMapPrivate(this);
3850}
3851
3853 QDomNodePrivate(n, deep)
3854{
3855 m_attr = n->m_attr->clone(this);
3856 // Reference is down to 0, so we set it to 1 here.
3857 m_attr->ref.ref();
3858}
3859
3861{
3862 if (!m_attr->ref.deref())
3863 delete m_attr;
3864}
3865
3867{
3868 QDomNodePrivate* p = new QDomElementPrivate(this, deep);
3869 // We are not interested in this node
3870 p->ref.deref();
3871 return p;
3872}
3873
3874QString QDomElementPrivate::attribute(const QString& name_, const QString& defValue) const
3875{
3876 QDomNodePrivate* n = m_attr->namedItem(name_);
3877 if (!n)
3878 return defValue;
3879
3880 return n->nodeValue();
3881}
3882
3883QString QDomElementPrivate::attributeNS(const QString& nsURI, const QString& localName, const QString& defValue) const
3884{
3885 QDomNodePrivate* n = m_attr->namedItemNS(nsURI, localName);
3886 if (!n)
3887 return defValue;
3888
3889 return n->nodeValue();
3890}
3891
3892void QDomElementPrivate::setAttribute(const QString& aname, const QString& newValue)
3893{
3894 QDomNodePrivate* n = m_attr->namedItem(aname);
3895 if (!n) {
3896 n = new QDomAttrPrivate(ownerDocument(), this, aname);
3897 n->setNodeValue(newValue);
3898
3899 // Referencing is done by the map, so we set the reference counter back
3900 // to 0 here. This is ok since we created the QDomAttrPrivate.
3901 n->ref.deref();
3903 } else {
3904 n->setNodeValue(newValue);
3905 }
3906}
3907
3908void QDomElementPrivate::setAttributeNS(const QString& nsURI, const QString& qName, const QString& newValue)
3909{
3910 QString prefix, localName;
3911 qt_split_namespace(prefix, localName, qName, true);
3912 QDomNodePrivate* n = m_attr->namedItemNS(nsURI, localName);
3913 if (!n) {
3914 n = new QDomAttrPrivate(ownerDocument(), this, nsURI, qName);
3915 n->setNodeValue(newValue);
3916
3917 // Referencing is done by the map, so we set the reference counter back
3918 // to 0 here. This is ok since we created the QDomAttrPrivate.
3919 n->ref.deref();
3921 } else {
3922 n->setNodeValue(newValue);
3923 n->prefix = prefix;
3924 }
3925}
3926
3928{
3930 if (p && p->ref.loadRelaxed() == 0)
3931 delete p;
3932}
3933
3935{
3936 return static_cast<QDomAttrPrivate *>(m_attr->namedItem(aname));
3937}
3938
3940{
3941 return static_cast<QDomAttrPrivate *>(m_attr->namedItemNS(nsURI, localName));
3942}
3943
3945{
3946 QDomNodePrivate* n = m_attr->namedItem(newAttr->nodeName());
3947
3948 // Referencing is done by the maps
3949 m_attr->setNamedItem(newAttr);
3950
3951 newAttr->setParent(this);
3952
3953 return static_cast<QDomAttrPrivate *>(n);
3954}
3955
3957{
3958 QDomNodePrivate* n = nullptr;
3959 if (!newAttr->prefix.isNull())
3960 n = m_attr->namedItemNS(newAttr->namespaceURI, newAttr->name);
3961
3962 // Referencing is done by the maps
3963 m_attr->setNamedItem(newAttr);
3964
3965 return static_cast<QDomAttrPrivate *>(n);
3966}
3967
3969{
3970 return static_cast<QDomAttrPrivate *>(m_attr->removeNamedItem(oldAttr->nodeName()));
3971}
3972
3974{
3975 return m_attr->contains(aname);
3976}
3977
3978bool QDomElementPrivate::hasAttributeNS(const QString& nsURI, const QString& localName)
3979{
3980 return m_attr->containsNS(nsURI, localName);
3981}
3982
3984{
3985 QString t(u""_s);
3986
3988 while (p) {
3989 if (p->isText() || p->isCDATASection())
3990 t += p->nodeValue();
3991 else if (p->isElement())
3992 t += static_cast<QDomElementPrivate *>(p)->text();
3993 p = p->next;
3994 }
3995
3996 return t;
3997}
3998
3999void QDomElementPrivate::save(QTextStream& s, int depth, int indent) const
4000{
4001 if (!(prev && prev->isText()))
4002 s << QString(indent < 1 ? 0 : depth * indent, u' ');
4003
4004 QString qName(name);
4005 QString nsDecl(u""_s);
4006 if (!namespaceURI.isNull()) {
4017 if (prefix.isEmpty()) {
4018 nsDecl = u" xmlns"_s;
4019 } else {
4020 qName = prefix + u':' + name;
4021 nsDecl = u" xmlns:"_s + prefix;
4022 }
4023 nsDecl += u"=\""_s + encodeText(namespaceURI) + u'\"';
4024 }
4025 s << '<' << qName << nsDecl;
4026
4027
4028 /* Write out attributes. */
4029 if (!m_attr->map.isEmpty()) {
4030 /*
4031 * To ensure that we always output attributes in a consistent
4032 * order, sort the attributes before writing them into the
4033 * stream. (Note that the order may be different than the one
4034 * that e.g. we've read from a file, or the program order in
4035 * which these attributes have been populated. We just want to
4036 * guarantee reproducibile outputs.)
4037 */
4038 struct SavedAttribute {
4039 QString prefix;
4040 QString name;
4041 QString encodedValue;
4042 };
4043
4044 /* Gather all the attributes to save. */
4045 QVarLengthArray<SavedAttribute, 8> attributesToSave;
4046 attributesToSave.reserve(m_attr->map.size());
4047
4048 QDuplicateTracker<QString> outputtedPrefixes;
4049 for (const auto &[key, value] : std::as_const(m_attr->map).asKeyValueRange()) {
4050 Q_UNUSED(key); /* We extract the attribute name from the value. */
4051 bool mayNeedXmlNS = false;
4052
4053 SavedAttribute attr;
4054 attr.name = value->name;
4055 attr.encodedValue = encodeText(value->value, true, true);
4056 if (!value->namespaceURI.isNull()) {
4057 attr.prefix = value->prefix;
4058 mayNeedXmlNS = true;
4059 }
4060
4061 attributesToSave.push_back(std::move(attr));
4062
4063 /*
4064 * This is a fix for 138243, as good as it gets.
4065 *
4066 * QDomElementPrivate::save() output a namespace
4067 * declaration if the element is in a namespace, no matter
4068 * what. This function do as well, meaning that we get two
4069 * identical namespace declaration if we don't have the if-
4070 * statement below.
4071 *
4072 * This doesn't work when the parent element has the same
4073 * prefix as us but a different namespace. However, this
4074 * can only occur by the user modifying the element, and we
4075 * don't do fixups by that anyway, and hence it's the user
4076 * responsibility to avoid those situations.
4077 */
4078
4079 if (mayNeedXmlNS
4080 && ((!value->ownerNode || value->ownerNode->prefix != value->prefix)
4081 && !outputtedPrefixes.hasSeen(value->prefix)))
4082 {
4083 SavedAttribute nsAttr;
4084 nsAttr.prefix = QStringLiteral("xmlns");
4085 nsAttr.name = value->prefix;
4086 nsAttr.encodedValue = encodeText(value->namespaceURI, true, true);
4087 attributesToSave.push_back(std::move(nsAttr));
4088 }
4089 }
4090
4091 /* Sort the attributes by prefix and name. */
4092 const auto savedAttributeComparator = [](const SavedAttribute &lhs, const SavedAttribute &rhs)
4093 {
4094 const int cmp = QString::compare(lhs.prefix, rhs.prefix);
4095 return (cmp < 0) || ((cmp == 0) && (lhs.name < rhs.name));
4096 };
4097
4098 std::sort(attributesToSave.begin(), attributesToSave.end(), savedAttributeComparator);
4099
4100 /* Actually stream the sorted attributes. */
4101 for (const auto &attr : attributesToSave) {
4102 s << ' ';
4103 if (!attr.prefix.isEmpty())
4104 s << attr.prefix << ':';
4105 s << attr.name << "=\"" << attr.encodedValue << '\"';
4106 }
4107 }
4108
4109 if (last) {
4110 // has child nodes
4111 if (first->isText())
4112 s << '>';
4113 else {
4114 s << '>';
4115
4116 /* -1 disables new lines. */
4117 if (indent != -1)
4118 s << Qt::endl;
4119 }
4120 QDomNodePrivate::save(s, depth + 1, indent); if (!last->isText())
4121 s << QString(indent < 1 ? 0 : depth * indent, u' ');
4122
4123 s << "</" << qName << '>';
4124 } else {
4125 s << "/>";
4126 }
4127 if (!(next && next->isText())) {
4128 /* -1 disables new lines. */
4129 if (indent != -1)
4130 s << Qt::endl;
4131 }
4132}
4133
4134/**************************************************************
4135 *
4136 * QDomElement
4137 *
4138 **************************************************************/
4139
4140#define IMPL static_cast<QDomElementPrivate *>(impl)
4141
4199 : QDomNode()
4200{
4201}
4202
4211 : QDomNode(x)
4212{
4213}
4214
4216 : QDomNode(n)
4217{
4218}
4219
4228
4241{
4242 if (impl)
4243 impl->name = name;
4244}
4245
4256{
4257 if (!impl)
4258 return QString();
4259 return impl->nodeName();
4260}
4261
4262
4269{
4270 if (!impl)
4271 return QDomNamedNodeMap();
4272 return QDomNamedNodeMap(IMPL->attributes());
4273}
4274
4281QString QDomElement::attribute(const QString& name, const QString& defValue) const
4282{
4283 if (!impl)
4284 return defValue;
4285 return IMPL->attribute(name, defValue);
4286}
4287
4296{
4297 if (!impl)
4298 return;
4299 IMPL->setAttribute(name, value);
4300}
4301
4322{
4323 if (!impl)
4324 return;
4325 QString x;
4326 x.setNum(value);
4327 IMPL->setAttribute(name, x);
4328}
4329
4336{
4337 if (!impl)
4338 return;
4339 QString x;
4340 x.setNum(value);
4341 IMPL->setAttribute(name, x);
4342}
4343
4350{
4351 if (!impl)
4352 return;
4353 QString x;
4354 x.setNum(value, 'g', 8);
4355 IMPL->setAttribute(name, x);
4356}
4357
4364{
4365 if (!impl)
4366 return;
4367 QString x;
4368 x.setNum(value, 'g', 17);
4369 IMPL->setAttribute(name, x);
4370}
4371
4378{
4379 if (!impl)
4380 return;
4381 IMPL->removeAttribute(name);
4382}
4383
4392{
4393 if (!impl)
4394 return QDomAttr();
4395 return QDomAttr(IMPL->attributeNode(name));
4396}
4397
4409{
4410 if (!impl)
4411 return QDomAttr();
4412 return QDomAttr(IMPL->setAttributeNode(static_cast<QDomAttrPrivate *>(newAttr.impl)));
4413}
4414
4421{
4422 if (!impl)
4423 return QDomAttr(); // ### should this return oldAttr?
4424 return QDomAttr(IMPL->removeAttributeNode(static_cast<QDomAttrPrivate *>(oldAttr.impl)));
4425}
4426
4437{
4438 return QDomNodeList(new QDomNodeListPrivate(impl, tagname));
4439}
4440
4454{
4455 if (!impl)
4456 return false;
4457 return IMPL->hasAttribute(name);
4458}
4459
4467QString QDomElement::attributeNS(const QString& nsURI, const QString& localName, const QString& defValue) const
4468{
4469 if (!impl)
4470 return defValue;
4471 return IMPL->attributeNS(nsURI, localName, defValue);
4472}
4473
4486void QDomElement::setAttributeNS(const QString& nsURI, const QString& qName, const QString& value)
4487{
4488 if (!impl)
4489 return;
4490 IMPL->setAttributeNS(nsURI, qName, value);
4491}
4492
4509{
4510 if (!impl)
4511 return;
4512 QString x;
4513 x.setNum(value);
4514 IMPL->setAttributeNS(nsURI, qName, x);
4515}
4516
4521{
4522 if (!impl)
4523 return;
4524 QString x;
4525 x.setNum(value);
4526 IMPL->setAttributeNS(nsURI, qName, x);
4527}
4528
4532void QDomElement::setAttributeNS(const QString& nsURI, const QString& qName, double value)
4533{
4534 if (!impl)
4535 return;
4536 QString x;
4537 x.setNum(value, 'g', 17);
4538 IMPL->setAttributeNS(nsURI, qName, x);
4539}
4540
4547void QDomElement::removeAttributeNS(const QString& nsURI, const QString& localName)
4548{
4549 if (!impl)
4550 return;
4551 QDomNodePrivate *n = IMPL->attributeNodeNS(nsURI, localName);
4552 if (!n)
4553 return;
4554 IMPL->removeAttribute(n->nodeName());
4555}
4556
4566{
4567 if (!impl)
4568 return QDomAttr();
4569 return QDomAttr(IMPL->attributeNodeNS(nsURI, localName));
4570}
4571
4583{
4584 if (!impl)
4585 return QDomAttr();
4586 return QDomAttr(IMPL->setAttributeNodeNS(static_cast<QDomAttrPrivate *>(newAttr.impl)));
4587}
4588
4599{
4600 return QDomNodeList(new QDomNodeListPrivate(impl, nsURI, localName));
4601}
4602
4608bool QDomElement::hasAttributeNS(const QString& nsURI, const QString& localName) const
4609{
4610 if (!impl)
4611 return false;
4612 return IMPL->hasAttributeNS(nsURI, localName);
4613}
4614
4630{
4631 if (!impl)
4632 return QString();
4633 return IMPL->text();
4634}
4635
4636#undef IMPL
4637
4638/**************************************************************
4639 *
4640 * QDomTextPrivate
4641 *
4642 **************************************************************/
4643
4646{
4647 name = u"#text"_s;
4648}
4649
4652{
4653}
4654
4656{
4657 QDomNodePrivate* p = new QDomTextPrivate(this, deep);
4658 // We are not interested in this node
4659 p->ref.deref();
4660 return p;
4661}
4662
4664{
4665 if (!parent()) {
4666 qWarning("QDomText::splitText The node has no parent. So I cannot split");
4667 return nullptr;
4668 }
4669
4670 QDomTextPrivate* t = new QDomTextPrivate(ownerDocument(), nullptr, value.mid(offset));
4671 value.truncate(offset);
4672
4673 parent()->insertAfter(t, this);
4674
4675 return t;
4676}
4677
4679{
4680 QDomTextPrivate *that = const_cast<QDomTextPrivate*>(this);
4681 s << encodeText(value, !(that->parent() && that->parent()->isElement()), false, true);
4682}
4683
4684/**************************************************************
4685 *
4686 * QDomText
4687 *
4688 **************************************************************/
4689
4690#define IMPL static_cast<QDomTextPrivate *>(impl)
4691
4717{
4718}
4719
4729{
4730}
4731
4734{
4735}
4736
4744QDomText &QDomText::operator=(const QDomText &x) = default;
4745
4763{
4764 if (!impl)
4765 return QDomText();
4766 return QDomText(IMPL->splitText(offset));
4767}
4768
4769#undef IMPL
4770
4771/**************************************************************
4772 *
4773 * QDomCommentPrivate
4774 *
4775 **************************************************************/
4776
4779{
4780 name = u"#comment"_s;
4781}
4782
4785{
4786}
4787
4788
4790{
4791 QDomNodePrivate* p = new QDomCommentPrivate(this, deep);
4792 // We are not interested in this node
4793 p->ref.deref();
4794 return p;
4795}
4796
4797void QDomCommentPrivate::save(QTextStream& s, int depth, int indent) const
4798{
4799 /* We don't output whitespace if we would pollute a text node. */
4800 if (!(prev && prev->isText()))
4801 s << QString(indent < 1 ? 0 : depth * indent, u' ');
4802
4803 s << "<!--" << value;
4804 if (value.endsWith(u'-'))
4805 s << ' '; // Ensures that XML comment doesn't end with --->
4806 s << "-->";
4807
4808 if (!(next && next->isText()))
4809 s << Qt::endl;
4810}
4811
4812/**************************************************************
4813 *
4814 * QDomComment
4815 *
4816 **************************************************************/
4817
4845{
4846}
4847
4857{
4858}
4859
4862{
4863}
4864
4873
4880/**************************************************************
4881 *
4882 * QDomCDATASectionPrivate
4883 *
4884 **************************************************************/
4885
4887 const QString& val)
4889{
4890 name = u"#cdata-section"_s;
4891}
4892
4894 : QDomTextPrivate(n, deep)
4895{
4896}
4897
4899{
4900 QDomNodePrivate* p = new QDomCDATASectionPrivate(this, deep);
4901 // We are not interested in this node
4902 p->ref.deref();
4903 return p;
4904}
4905
4907{
4908 // ### How do we escape "]]>" ?
4909 // "]]>" is not allowed; so there should be none in value anyway
4910 s << "<![CDATA[" << value << "]]>";
4911}
4912
4913/**************************************************************
4914 *
4915 * QDomCDATASection
4916 *
4917 **************************************************************/
4918
4949 : QDomText()
4950{
4951}
4952
4961 : QDomText(x)
4962{
4963}
4964
4966 : QDomText(n)
4967{
4968}
4969
4978
4985/**************************************************************
4986 *
4987 * QDomNotationPrivate
4988 *
4989 **************************************************************/
4990
4992 const QString& aname,
4993 const QString& pub, const QString& sys)
4995{
4996 name = aname;
4997 m_pub = pub;
4998 m_sys = sys;
4999}
5000
5002 : QDomNodePrivate(n, deep)
5003{
5004 m_sys = n->m_sys;
5005 m_pub = n->m_pub;
5006}
5007
5009{
5010 QDomNodePrivate* p = new QDomNotationPrivate(this, deep);
5011 // We are not interested in this node
5012 p->ref.deref();
5013 return p;
5014}
5015
5017{
5018 s << "<!NOTATION " << name << ' ';
5019 if (!m_pub.isNull()) {
5020 s << "PUBLIC " << quotedValue(m_pub);
5021 if (!m_sys.isNull())
5022 s << ' ' << quotedValue(m_sys);
5023 } else {
5024 s << "SYSTEM " << quotedValue(m_sys);
5025 }
5026 s << '>' << Qt::endl;
5027}
5028
5029/**************************************************************
5030 *
5031 * QDomNotation
5032 *
5033 **************************************************************/
5034
5035#define IMPL static_cast<QDomNotationPrivate *>(impl)
5036
5070 : QDomNode()
5071{
5072}
5073
5082 : QDomNode(x)
5083{
5084}
5085
5087 : QDomNode(n)
5088{
5089}
5090
5099
5110{
5111 if (!impl)
5112 return QString();
5113 return IMPL->m_pub;
5114}
5115
5120{
5121 if (!impl)
5122 return QString();
5123 return IMPL->m_sys;
5124}
5125
5126#undef IMPL
5127
5128/**************************************************************
5129 *
5130 * QDomEntityPrivate
5131 *
5132 **************************************************************/
5133
5135 const QString& aname,
5136 const QString& pub, const QString& sys, const QString& notation)
5138{
5139 name = aname;
5140 m_pub = pub;
5141 m_sys = sys;
5142 m_notationName = notation;
5143}
5144
5146 : QDomNodePrivate(n, deep)
5147{
5148 m_sys = n->m_sys;
5149 m_pub = n->m_pub;
5150 m_notationName = n->m_notationName;
5151}
5152
5154{
5155 QDomNodePrivate* p = new QDomEntityPrivate(this, deep);
5156 // We are not interested in this node
5157 p->ref.deref();
5158 return p;
5159}
5160
5161/*
5162 Encode an entity value upon saving.
5163*/
5165{
5166 QByteArray tmp(str);
5167 int len = tmp.size();
5168 int i = 0;
5169 const char* d = tmp.constData();
5170 while (i < len) {
5171 if (d[i] == '%'){
5172 tmp.replace(i, 1, "&#60;");
5173 d = tmp.constData();
5174 len += 4;
5175 i += 5;
5176 }
5177 else if (d[i] == '"') {
5178 tmp.replace(i, 1, "&#34;");
5179 d = tmp.constData();
5180 len += 4;
5181 i += 5;
5182 } else if (d[i] == '&' && i + 1 < len && d[i+1] == '#') {
5183 // Don't encode &lt; or &quot; or &custom;.
5184 // Only encode character references
5185 tmp.replace(i, 1, "&#38;");
5186 d = tmp.constData();
5187 len += 4;
5188 i += 5;
5189 } else {
5190 ++i;
5191 }
5192 }
5193
5194 return tmp;
5195}
5196
5198{
5199 QString _name = name;
5200 if (_name.startsWith(u'%'))
5201 _name = u"% "_s + _name.mid(1);
5202
5203 if (m_sys.isNull() && m_pub.isNull()) {
5204 s << "<!ENTITY " << _name << " \"" << encodeEntity(value.toUtf8()) << "\">" << Qt::endl;
5205 } else {
5206 s << "<!ENTITY " << _name << ' ';
5207 if (m_pub.isNull()) {
5208 s << "SYSTEM " << quotedValue(m_sys);
5209 } else {
5210 s << "PUBLIC " << quotedValue(m_pub) << ' ' << quotedValue(m_sys);
5211 }
5212 if (! m_notationName.isNull()) {
5213 s << " NDATA " << m_notationName;
5214 }
5215 s << '>' << Qt::endl;
5216 }
5217}
5218
5219/**************************************************************
5220 *
5221 * QDomEntity
5222 *
5223 **************************************************************/
5224
5225#define IMPL static_cast<QDomEntityPrivate *>(impl)
5226
5263 : QDomNode()
5264{
5265}
5266
5267
5276 : QDomNode(x)
5277{
5278}
5279
5281 : QDomNode(n)
5282{
5283}
5284
5292QDomEntity &QDomEntity::operator=(const QDomEntity &x) = default;
5293
5305{
5306 if (!impl)
5307 return QString();
5308 return IMPL->m_pub;
5309}
5310
5316{
5317 if (!impl)
5318 return QString();
5319 return IMPL->m_sys;
5320}
5321
5328{
5329 if (!impl)
5330 return QString();
5331 return IMPL->m_notationName;
5332}
5333
5334#undef IMPL
5335
5336/**************************************************************
5337 *
5338 * QDomEntityReferencePrivate
5339 *
5340 **************************************************************/
5341
5344{
5345 name = aname;
5346}
5347
5349 : QDomNodePrivate(n, deep)
5350{
5351}
5352
5354{
5355 QDomNodePrivate* p = new QDomEntityReferencePrivate(this, deep);
5356 // We are not interested in this node
5357 p->ref.deref();
5358 return p;
5359}
5360
5362{
5363 s << '&' << name << ';';
5364}
5365
5366/**************************************************************
5367 *
5368 * QDomEntityReference
5369 *
5370 **************************************************************/
5371
5413 : QDomNode()
5414{
5415}
5416
5425 : QDomNode(x)
5426{
5427}
5428
5430 : QDomNode(n)
5431{
5432}
5433
5442
5449/**************************************************************
5450 *
5451 * QDomProcessingInstructionPrivate
5452 *
5453 **************************************************************/
5454
5458{
5459 name = target;
5460 value = data;
5461}
5462
5464 : QDomNodePrivate(n, deep)
5465{
5466}
5467
5468
5470{
5472 // We are not interested in this node
5473 p->ref.deref();
5474 return p;
5475}
5476
5478{
5479 s << "<?" << name << ' ' << value << "?>" << Qt::endl;
5480}
5481
5482/**************************************************************
5483 *
5484 * QDomProcessingInstruction
5485 *
5486 **************************************************************/
5487
5527 : QDomNode()
5528{
5529}
5530
5539 : QDomNode(x)
5540{
5541}
5542
5544 : QDomNode(n)
5545{
5546}
5547
5557
5570{
5571 if (!impl)
5572 return QString();
5573 return impl->nodeName();
5574}
5575
5582{
5583 if (!impl)
5584 return QString();
5585 return impl->nodeValue();
5586}
5587
5594{
5595 if (!impl)
5596 return;
5598}
5599
5600/**************************************************************
5601 *
5602 * QDomDocumentPrivate
5603 *
5604 **************************************************************/
5605
5608 impl(new QDomImplementationPrivate),
5609 nodeListTime(1)
5610{
5611 type = new QDomDocumentTypePrivate(this, this);
5612 type->ref.deref();
5613
5614 name = u"#document"_s;
5615}
5616
5619 impl(new QDomImplementationPrivate),
5620 nodeListTime(1)
5621{
5622 type = new QDomDocumentTypePrivate(this, this);
5623 type->ref.deref();
5624 type->name = aname;
5625
5626 name = u"#document"_s;
5627}
5628
5631 impl(new QDomImplementationPrivate),
5632 nodeListTime(1)
5633{
5634 if (dt != nullptr) {
5635 type = dt;
5636 } else {
5637 type = new QDomDocumentTypePrivate(this, this);
5638 type->ref.deref();
5639 }
5640
5641 name = u"#document"_s;
5642}
5643
5645 : QDomNodePrivate(n, deep),
5646 impl(n->impl->clone()),
5647 nodeListTime(1)
5648{
5649 type = static_cast<QDomDocumentTypePrivate*>(n->type->cloneNode());
5650 type->setParent(this);
5651}
5652
5654{
5655}
5656
5658{
5659 impl.reset();
5660 type.reset();
5662}
5663
5665 QDomDocument::ParseOptions options)
5666{
5667 clear();
5669 type = new QDomDocumentTypePrivate(this, this);
5670 type->ref.deref();
5671
5672 if (!reader) {
5673 const auto error = u"Failed to set content, XML reader is not initialized"_s;
5674 qWarning("%s", qPrintable(error));
5675 return { error };
5676 }
5677
5678 QDomParser domParser(this, reader, options);
5679
5680 if (!domParser.parse())
5681 return domParser.result();
5682 return {};
5683}
5684
5686{
5687 QDomNodePrivate *p = new QDomDocumentPrivate(this, deep);
5688 // We are not interested in this node
5689 p->ref.deref();
5690 return p;
5691}
5692
5694{
5696 while (p && !p->isElement())
5697 p = p->next;
5698
5699 return static_cast<QDomElementPrivate *>(p);
5700}
5701
5703{
5704 bool ok;
5705 QString fixedName = fixedXmlName(tagName, &ok);
5706 if (!ok)
5707 return nullptr;
5708
5709 QDomElementPrivate *e = new QDomElementPrivate(this, nullptr, fixedName);
5710 e->ref.deref();
5711 return e;
5712}
5713
5715{
5716 bool ok;
5717 QString fixedName = fixedXmlName(qName, &ok, true);
5718 if (!ok)
5719 return nullptr;
5720
5721 QDomElementPrivate *e = new QDomElementPrivate(this, nullptr, nsURI, fixedName);
5722 e->ref.deref();
5723 return e;
5724}
5725
5727{
5729 f->ref.deref();
5730 return f;
5731}
5732
5734{
5735 bool ok;
5736 QString fixedData = fixedCharData(data, &ok);
5737 if (!ok)
5738 return nullptr;
5739
5740 QDomTextPrivate *t = new QDomTextPrivate(this, nullptr, fixedData);
5741 t->ref.deref();
5742 return t;
5743}
5744
5746{
5747 bool ok;
5748 QString fixedData = fixedComment(data, &ok);
5749 if (!ok)
5750 return nullptr;
5751
5752 QDomCommentPrivate *c = new QDomCommentPrivate(this, nullptr, fixedData);
5753 c->ref.deref();
5754 return c;
5755}
5756
5758{
5759 bool ok;
5760 QString fixedData = fixedCDataSection(data, &ok);
5761 if (!ok)
5762 return nullptr;
5763
5764 QDomCDATASectionPrivate *c = new QDomCDATASectionPrivate(this, nullptr, fixedData);
5765 c->ref.deref();
5766 return c;
5767}
5768
5770 const QString &data)
5771{
5772 bool ok;
5773 QString fixedData = fixedPIData(data, &ok);
5774 if (!ok)
5775 return nullptr;
5776 // [17] PITarget ::= Name - (('X' | 'x') ('M' | 'm') ('L' | 'l'))
5777 QString fixedTarget = fixedXmlName(target, &ok);
5778 if (!ok)
5779 return nullptr;
5780
5781 QDomProcessingInstructionPrivate *p = new QDomProcessingInstructionPrivate(this, nullptr, fixedTarget, fixedData);
5782 p->ref.deref();
5783 return p;
5784}
5786{
5787 bool ok;
5788 QString fixedName = fixedXmlName(aname, &ok);
5789 if (!ok)
5790 return nullptr;
5791
5792 QDomAttrPrivate *a = new QDomAttrPrivate(this, nullptr, fixedName);
5793 a->ref.deref();
5794 return a;
5795}
5796
5798{
5799 bool ok;
5800 QString fixedName = fixedXmlName(qName, &ok, true);
5801 if (!ok)
5802 return nullptr;
5803
5804 QDomAttrPrivate *a = new QDomAttrPrivate(this, nullptr, nsURI, fixedName);
5805 a->ref.deref();
5806 return a;
5807}
5808
5810{
5811 bool ok;
5812 QString fixedName = fixedXmlName(aname, &ok);
5813 if (!ok)
5814 return nullptr;
5815
5816 QDomEntityReferencePrivate *e = new QDomEntityReferencePrivate(this, nullptr, fixedName);
5817 e->ref.deref();
5818 return e;
5819}
5820
5822{
5823 QDomNodePrivate *node = nullptr;
5824 switch (importedNode->nodeType()) {
5826 node = new QDomAttrPrivate(static_cast<QDomAttrPrivate *>(importedNode), true);
5827 break;
5829 node = new QDomDocumentFragmentPrivate(
5830 static_cast<QDomDocumentFragmentPrivate *>(importedNode), deep);
5831 break;
5833 node = new QDomElementPrivate(static_cast<QDomElementPrivate *>(importedNode), deep);
5834 break;
5836 node = new QDomEntityPrivate(static_cast<QDomEntityPrivate *>(importedNode), deep);
5837 break;
5839 node = new QDomEntityReferencePrivate(
5840 static_cast<QDomEntityReferencePrivate *>(importedNode), false);
5841 break;
5843 node = new QDomNotationPrivate(static_cast<QDomNotationPrivate *>(importedNode), deep);
5844 break;
5847 static_cast<QDomProcessingInstructionPrivate *>(importedNode), deep);
5848 break;
5849 case QDomNode::TextNode:
5850 node = new QDomTextPrivate(static_cast<QDomTextPrivate *>(importedNode), deep);
5851 break;
5853 node = new QDomCDATASectionPrivate(static_cast<QDomCDATASectionPrivate *>(importedNode),
5854 deep);
5855 break;
5857 node = new QDomCommentPrivate(static_cast<QDomCommentPrivate *>(importedNode), deep);
5858 break;
5859 default:
5860 break;
5861 }
5862 if (node) {
5863 node->setOwnerDocument(this);
5864 // The QDomNode constructor increases the refcount, so deref first to
5865 // keep refcount balanced.
5866 node->ref.deref();
5867 }
5868 return node;
5869}
5870
5872{
5873 const QDomNodePrivate* n = first;
5874
5875 if (encUsed == QDomNode::EncodingFromDocument) {
5876#if QT_CONFIG(regularexpression)
5877 const QDomNodePrivate* n = first;
5878
5879 if (n && n->isProcessingInstruction() && n->nodeName() == "xml"_L1) {
5880 // we have an XML declaration
5881 QString data = n->nodeValue();
5882 QRegularExpression encoding(QString::fromLatin1("encoding\\s*=\\s*((\"([^\"]*)\")|('([^']*)'))"));
5883 auto match = encoding.match(data);
5884 QString enc = match.captured(3);
5885 if (enc.isEmpty())
5886 enc = match.captured(5);
5887 if (!enc.isEmpty()) {
5888 auto encoding = QStringConverter::encodingForName(enc.toUtf8().constData());
5889 if (!encoding)
5890 qWarning() << "QDomDocument::save(): Unsupported encoding" << enc << "specified.";
5891 else
5892 s.setEncoding(encoding.value());
5893 }
5894 }
5895#endif
5896 bool doc = false;
5897
5898 while (n) {
5899 if (!doc && !(n->isProcessingInstruction() && n->nodeName() == "xml"_L1)) {
5900 // save doctype after XML declaration
5901 type->save(s, 0, indent);
5902 doc = true;
5903 }
5904 n->save(s, 0, indent);
5905 n = n->next;
5906 }
5907 }
5908 else {
5909
5910 // Write out the XML declaration.
5911 const QByteArray codecName = QStringConverter::nameForEncoding(s.encoding());
5912
5913 s << "<?xml version=\"1.0\" encoding=\""
5914 << codecName
5915 << "\"?>\n";
5916
5917 // Skip the first processing instruction by name "xml", if any such exists.
5918 const QDomNodePrivate* startNode = n;
5919
5920 // First, we try to find the PI and sets the startNode to the one appearing after it.
5921 while (n) {
5922 if (n->isProcessingInstruction() && n->nodeName() == "xml"_L1) {
5923 startNode = n->next;
5924 break;
5925 }
5926 else
5927 n = n->next;
5928 }
5929
5930 // Now we serialize all the nodes after the faked XML declaration(the PI).
5931 while(startNode) {
5932 startNode->save(s, 0, indent);
5933 startNode = startNode->next;
5934 }
5935 }
5936}
5937
5938/**************************************************************
5939 *
5940 * QDomDocument
5941 *
5942 **************************************************************/
5943
5944#define IMPL static_cast<QDomDocumentPrivate *>(impl)
5945
6028{
6029 impl = nullptr;
6030}
6031
6037{
6038 // We take over ownership
6040}
6041
6048{
6050}
6051
6060 : QDomNode(x)
6061{
6062}
6063
6065 : QDomNode(x)
6066{
6067}
6068
6077
6082{
6083}
6084
6085#if QT_DEPRECATED_SINCE(6, 8)
6097bool QDomDocument::setContent(const QString& text, bool namespaceProcessing,
6098 QString *errorMsg, int *errorLine, int *errorColumn)
6099{
6100 QXmlStreamReader reader(text);
6101 reader.setNamespaceProcessing(namespaceProcessing);
6102 return setContent(&reader, namespaceProcessing, errorMsg, errorLine, errorColumn);
6103}
6104
6138
6153
6157bool QDomDocument::setContent(const QByteArray &data, bool namespaceProcessing,
6158 QString *errorMsg, int *errorLine, int *errorColumn)
6159{
6160 QXmlStreamReader reader(data);
6161 reader.setNamespaceProcessing(namespaceProcessing);
6162 return setContent(&reader, namespaceProcessing, errorMsg, errorLine, errorColumn);
6163}
6164
6165static inline QDomDocument::ParseOptions toParseOptions(bool namespaceProcessing)
6166{
6167 return namespaceProcessing ? QDomDocument::ParseOption::UseNamespaceProcessing
6169}
6170
6171static inline void unpackParseResult(const QDomDocument::ParseResult &parseResult,
6172 QString *errorMsg, int *errorLine, int *errorColumn)
6173{
6174 if (!parseResult) {
6175 if (errorMsg)
6176 *errorMsg = parseResult.errorMessage;
6177 if (errorLine)
6178 *errorLine = static_cast<int>(parseResult.errorLine);
6179 if (errorColumn)
6180 *errorColumn = static_cast<int>(parseResult.errorLine);
6181 }
6182}
6183
6196bool QDomDocument::setContent(QIODevice* dev, bool namespaceProcessing,
6197 QString *errorMsg, int *errorLine, int *errorColumn)
6198{
6199 ParseResult result = setContent(dev, toParseOptions(namespaceProcessing));
6200 unpackParseResult(result, errorMsg, errorLine, errorColumn);
6201 return bool(result);
6202}
6203
6215bool QDomDocument::setContent(const QString& text, QString *errorMsg, int *errorLine, int *errorColumn)
6216{
6217 return setContent(text, false, errorMsg, errorLine, errorColumn);
6218}
6219
6230bool QDomDocument::setContent(const QByteArray& buffer, QString *errorMsg, int *errorLine, int *errorColumn )
6231{
6232 return setContent(buffer, false, errorMsg, errorLine, errorColumn);
6233}
6234
6244bool QDomDocument::setContent(QIODevice* dev, QString *errorMsg, int *errorLine, int *errorColumn )
6245{
6246 return setContent(dev, false, errorMsg, errorLine, errorColumn);
6247}
6248
6269bool QDomDocument::setContent(QXmlStreamReader *reader, bool namespaceProcessing,
6270 QString *errorMsg, int *errorLine, int *errorColumn)
6271{
6272 ParseResult result = setContent(reader, toParseOptions(namespaceProcessing));
6273 unpackParseResult(result, errorMsg, errorLine, errorColumn);
6274 return bool(result);
6275}
6277#endif // QT_DEPRECATED_SINCE(6, 8)
6278
6390QDomDocument::ParseResult QDomDocument::setContentImpl(const QByteArray &data, ParseOptions options)
6391{
6392 QXmlStreamReader reader(data);
6393 reader.setNamespaceProcessing(options.testFlag(ParseOption::UseNamespaceProcessing));
6394 return setContent(&reader, options);
6395}
6396
6398{
6399 QXmlStreamReader reader(data);
6400 reader.setNamespaceProcessing(options.testFlag(ParseOption::UseNamespaceProcessing));
6401 return setContent(&reader, options);
6402}
6403
6405{
6406#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
6407 if (!device->isOpen()) {
6408 qWarning("QDomDocument called with unopened QIODevice. "
6409 "This will not be supported in future Qt versions.");
6410 if (!device->open(QIODevice::ReadOnly)) {
6411 const auto error = u"QDomDocument::setContent: Failed to open device."_s;
6412 qWarning("%s", qPrintable(error));
6413 return { error };
6414 }
6415 }
6416#endif
6417
6418 QXmlStreamReader reader(device);
6419 reader.setNamespaceProcessing(options.testFlag(ParseOption::UseNamespaceProcessing));
6420 return setContent(&reader, options);
6421}
6422
6423QDomDocument::ParseResult QDomDocument::setContent(QXmlStreamReader *reader, ParseOptions options)
6424{
6425 if (!impl)
6426 impl = new QDomDocumentPrivate();
6427 return IMPL->setContent(reader, options);
6428}
6429
6439{
6440 QString str;
6442 save(s, indent);
6443 return str;
6444}
6445
6456{
6457 // ### if there is an encoding specified in the xml declaration, this
6458 // encoding declaration should be changed to utf8
6459 return toString(indent).toUtf8();
6460}
6461
6462
6467{
6468 if (!impl)
6469 return QDomDocumentType();
6470 return QDomDocumentType(IMPL->doctype());
6471}
6472
6477{
6478 if (!impl)
6479 return QDomImplementation();
6480 return QDomImplementation(IMPL->implementation());
6481}
6482
6487{
6488 if (!impl)
6489 return QDomElement();
6490 return QDomElement(IMPL->documentElement());
6491}
6492
6504{
6505 if (!impl)
6506 impl = new QDomDocumentPrivate();
6507 return QDomElement(IMPL->createElement(tagName));
6508}
6509
6516{
6517 if (!impl)
6518 impl = new QDomDocumentPrivate();
6519 return QDomDocumentFragment(IMPL->createDocumentFragment());
6520}
6521
6533{
6534 if (!impl)
6535 impl = new QDomDocumentPrivate();
6536 return QDomText(IMPL->createTextNode(value));
6537}
6538
6549{
6550 if (!impl)
6551 impl = new QDomDocumentPrivate();
6552 return QDomComment(IMPL->createComment(value));
6553}
6554
6566{
6567 if (!impl)
6568 impl = new QDomDocumentPrivate();
6569 return QDomCDATASection(IMPL->createCDATASection(value));
6570}
6571
6585 const QString& data)
6586{
6587 if (!impl)
6588 impl = new QDomDocumentPrivate();
6589 return QDomProcessingInstruction(IMPL->createProcessingInstruction(target, data));
6590}
6591
6592
6603{
6604 if (!impl)
6605 impl = new QDomDocumentPrivate();
6606 return QDomAttr(IMPL->createAttribute(name));
6607}
6608
6619{
6620 if (!impl)
6621 impl = new QDomDocumentPrivate();
6622 return QDomEntityReference(IMPL->createEntityReference(name));
6623}
6624
6634{
6635 return QDomNodeList(new QDomNodeListPrivate(impl, tagname));
6636}
6637
6707QDomNode QDomDocument::importNode(const QDomNode& importedNode, bool deep)
6708{
6709 if (importedNode.isNull())
6710 return QDomNode();
6711 if (!impl)
6712 impl = new QDomDocumentPrivate();
6713 return QDomNode(IMPL->importNode(importedNode.impl, deep));
6714}
6715
6729{
6730 if (!impl)
6731 impl = new QDomDocumentPrivate();
6732 return QDomElement(IMPL->createElementNS(nsURI, qName));
6733}
6734
6748{
6749 if (!impl)
6750 impl = new QDomDocumentPrivate();
6751 return QDomAttr(IMPL->createAttributeNS(nsURI, qName));
6752}
6753
6763{
6764 return QDomNodeList(new QDomNodeListPrivate(impl, nsURI, localName));
6765}
6766
6778{
6779 qWarning("elementById() is not implemented and will always return a null node.");
6780 return QDomElement();
6781}
6782
6789#undef IMPL
6790
6791/**************************************************************
6792 *
6793 * Node casting functions
6794 *
6795 **************************************************************/
6796
6804{
6805 if (impl && impl->isAttr())
6806 return QDomAttr(static_cast<QDomAttrPrivate *>(impl));
6807 return QDomAttr();
6808}
6809
6817{
6818 if (impl && impl->isCDATASection())
6819 return QDomCDATASection(static_cast<QDomCDATASectionPrivate *>(impl));
6820 return QDomCDATASection();
6821}
6822
6830{
6831 if (impl && impl->isDocumentFragment())
6833 return QDomDocumentFragment();
6834}
6835
6843{
6844 if (impl && impl->isDocument())
6845 return QDomDocument(static_cast<QDomDocumentPrivate *>(impl));
6846 return QDomDocument();
6847}
6848
6856{
6857 if (impl && impl->isDocumentType())
6858 return QDomDocumentType(static_cast<QDomDocumentTypePrivate *>(impl));
6859 return QDomDocumentType();
6860}
6861
6869{
6870 if (impl && impl->isElement())
6871 return QDomElement(static_cast<QDomElementPrivate *>(impl));
6872 return QDomElement();
6873}
6874
6882{
6883 if (impl && impl->isEntityReference())
6884 return QDomEntityReference(static_cast<QDomEntityReferencePrivate *>(impl));
6885 return QDomEntityReference();
6886}
6887
6895{
6896 if (impl && impl->isText())
6897 return QDomText(static_cast<QDomTextPrivate *>(impl));
6898 return QDomText();
6899}
6900
6908{
6909 if (impl && impl->isEntity())
6910 return QDomEntity(static_cast<QDomEntityPrivate *>(impl));
6911 return QDomEntity();
6912}
6913
6921{
6922 if (impl && impl->isNotation())
6923 return QDomNotation(static_cast<QDomNotationPrivate *>(impl));
6924 return QDomNotation();
6925}
6926
6934{
6938}
6939
6947{
6948 if (impl && impl->isCharacterData())
6949 return QDomCharacterData(static_cast<QDomCharacterDataPrivate *>(impl));
6950 return QDomCharacterData();
6951}
6952
6960{
6961 if (impl && impl->isComment())
6962 return QDomComment(static_cast<QDomCommentPrivate *>(impl));
6963 return QDomComment();
6964}
6965
6973
6974#endif // QT_NO_DOM
IOBluetoothDevice * device
\inmodule QtCore
bool ref() noexcept
bool deref() noexcept
\inmodule QtCore
Definition qbytearray.h:57
qsizetype size() const noexcept
Returns the number of bytes in this byte array.
Definition qbytearray.h:474
const char * constData() const noexcept
Returns a pointer to the const data stored in the byte array.
Definition qbytearray.h:122
QByteArray & replace(qsizetype index, qsizetype len, const char *s, qsizetype alen)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qbytearray.h:275
\inmodule QtCore
Definition qchar.h:48
@ Null
Definition qchar.h:51
static constexpr auto fromUcs4(char32_t c) noexcept
constexpr char16_t unicode() const noexcept
Returns the numeric Unicode value of the QChar.
Definition qchar.h:458
QDomAttrPrivate(QDomDocumentPrivate *, QDomNodePrivate *, const QString &name)
Definition qdom.cpp:3551
QDomNodePrivate * cloneNode(bool deep=true) override
Definition qdom.cpp:3587
virtual void save(QTextStream &s, int, int) const override
Definition qdom.cpp:3658
bool m_specified
Definition qdom_p.h:296
bool specified() const
Definition qdom.cpp:3595
void setNodeValue(const QString &v) override
Definition qdom.cpp:3573
\reentrant
Definition qdom.h:441
friend class QDomElement
Definition qdom.h:463
QDomAttr()
Constructs an empty attribute.
Definition qdom.cpp:3728
QDomAttr & operator=(const QDomAttr &)
Assigns x to this DOM attribute.
QString name() const
Returns the attribute's name.
Definition qdom.cpp:3761
QString value() const
Returns the value of the attribute or an empty string if the attribute has not been specified.
Definition qdom.cpp:3800
bool specified() const
Returns true if the attribute has been set by the user with setValue().
Definition qdom.cpp:3774
void setValue(const QString &)
Sets the attribute's value to v.
Definition qdom.cpp:3812
QDomElement ownerElement() const
Returns the element node this attribute is attached to or a \l{QDomNode::isNull()}{null node} if this...
Definition qdom.cpp:3786
QDomCDATASectionPrivate(QDomDocumentPrivate *, QDomNodePrivate *parent, const QString &val)
Definition qdom.cpp:4886
virtual void save(QTextStream &s, int, int) const override
Definition qdom.cpp:4906
QDomNodePrivate * cloneNode(bool deep=true) override
Definition qdom.cpp:4898
\reentrant
Definition qdom.h:564
QDomCDATASection()
Constructs an empty CDATA section.
Definition qdom.cpp:4948
QDomCDATASection & operator=(const QDomCDATASection &)
Assigns x to this CDATA section.
QDomNodePrivate * cloneNode(bool deep=true) override
Definition qdom.cpp:3348
QDomCharacterDataPrivate(QDomDocumentPrivate *, QDomNodePrivate *parent, const QString &data)
Definition qdom.cpp:3335
void appendData(const QString &arg)
Definition qdom.cpp:3381
void insertData(unsigned long offset, const QString &arg)
Definition qdom.cpp:3366
int dataLength() const
Definition qdom.cpp:3356
QString substringData(unsigned long offset, unsigned long count) const
Definition qdom.cpp:3361
void deleteData(unsigned long offset, unsigned long count)
Definition qdom.cpp:3371
void replaceData(unsigned long offset, unsigned long count, const QString &arg)
Definition qdom.cpp:3376
\reentrant
Definition qdom.h:408
int length() const
Returns the length of the stored string.
Definition qdom.cpp:3477
QString data() const
Returns the string stored in this object.
Definition qdom.cpp:3458
QDomCharacterData()
Constructs an empty character data object.
Definition qdom.cpp:3422
void replaceData(unsigned long offset, unsigned long count, const QString &arg)
Replaces the substring of length count starting at position offset with the string arg.
Definition qdom.cpp:3525
void deleteData(unsigned long offset, unsigned long count)
Deletes a substring of length count from position offset.
Definition qdom.cpp:3515
QString substringData(unsigned long offset, unsigned long count)
Returns the substring of length count from position offset.
Definition qdom.cpp:3487
void appendData(const QString &arg)
Appends the string arg to the stored string.
Definition qdom.cpp:3497
void setData(const QString &)
Sets this object's string to v.
Definition qdom.cpp:3468
void insertData(unsigned long offset, const QString &arg)
Inserts the string arg into the stored string at position offset.
Definition qdom.cpp:3506
QDomNode::NodeType nodeType() const
Returns the type of node this object refers to (i.e.
Definition qdom.cpp:3536
QDomCharacterData & operator=(const QDomCharacterData &)
Assigns x to this character data.
QDomNodePrivate * cloneNode(bool deep=true) override
Definition qdom.cpp:4789
virtual void save(QTextStream &s, int, int) const override
Definition qdom.cpp:4797
QDomCommentPrivate(QDomDocumentPrivate *, QDomNodePrivate *parent, const QString &val)
Definition qdom.cpp:4777
\reentrant
Definition qdom.h:547
QDomComment()
Constructs an empty comment.
Definition qdom.cpp:4843
QDomComment & operator=(const QDomComment &)
Assigns x to this DOM comment.
QDomDocumentFragmentPrivate(QDomDocumentPrivate *, QDomNodePrivate *parent=nullptr)
Definition qdom.cpp:3238
virtual QDomNodePrivate * cloneNode(bool deep=true) override
Definition qdom.cpp:3249
\reentrant
Definition qdom.h:391
QDomDocumentFragment & operator=(const QDomDocumentFragment &)
Assigns x to this DOM document fragment.
QDomDocumentFragment()
Constructs an empty document fragment.
Definition qdom.cpp:3291
QDomDocument::ParseResult setContent(QXmlStreamReader *reader, QDomDocument::ParseOptions options)
Definition qdom.cpp:5664
QDomNodePrivate * cloneNode(bool deep=true) override
Definition qdom.cpp:5685
QDomElementPrivate * createElement(const QString &tagName)
Definition qdom.cpp:5702
QDomAttrPrivate * createAttribute(const QString &name)
Definition qdom.cpp:5785
QDomCDATASectionPrivate * createCDATASection(const QString &data)
Definition qdom.cpp:5757
QDomProcessingInstructionPrivate * createProcessingInstruction(const QString &target, const QString &data)
Definition qdom.cpp:5769
QDomTextPrivate * createTextNode(const QString &data)
Definition qdom.cpp:5733
QDomDocumentFragmentPrivate * createDocumentFragment()
Definition qdom.cpp:5726
void saveDocument(QTextStream &stream, const int indent, QDomNode::EncodingPolicy encUsed) const
Definition qdom.cpp:5871
void clear() override
Definition qdom.cpp:5657
QDomAttrPrivate * createAttributeNS(const QString &nsURI, const QString &qName)
Definition qdom.cpp:5797
QDomNodePrivate * importNode(QDomNodePrivate *importedNode, bool deep)
Definition qdom.cpp:5821
QDomElementPrivate * documentElement()
Definition qdom.cpp:5693
QExplicitlySharedDataPointer< QDomImplementationPrivate > impl
Definition qdom_p.h:457
QDomEntityReferencePrivate * createEntityReference(const QString &name)
Definition qdom.cpp:5809
QDomElementPrivate * createElementNS(const QString &nsURI, const QString &qName)
Definition qdom.cpp:5714
QDomCommentPrivate * createComment(const QString &data)
Definition qdom.cpp:5745
QDomNodePrivate * insertAfter(QDomNodePrivate *newChild, QDomNodePrivate *refChild) override
Definition qdom.cpp:2995
QDomDocumentTypePrivate(QDomDocumentPrivate *, QDomNodePrivate *parent=nullptr)
Definition qdom.cpp:2926
void save(QTextStream &s, int, int) const override
Definition qdom.cpp:3052
QDomNodePrivate * removeChild(QDomNodePrivate *oldChild) override
Definition qdom.cpp:3028
QDomNodePrivate * cloneNode(bool deep=true) override
Definition qdom.cpp:2974
QDomNodePrivate * appendChild(QDomNodePrivate *newChild) override
Definition qdom.cpp:3041
QDomNodePrivate * replaceChild(QDomNodePrivate *newChild, QDomNodePrivate *oldChild) override
Definition qdom.cpp:3008
QDomNodePrivate * insertBefore(QDomNodePrivate *newChild, QDomNodePrivate *refChild) override
Definition qdom.cpp:2982
QDomNamedNodeMapPrivate * entities
Definition qdom_p.h:229
QDomNamedNodeMapPrivate * notations
Definition qdom_p.h:230
\reentrant
Definition qdom.h:240
QString publicId() const
Returns the public identifier of the external DTD subset or an empty string if there is no public ide...
Definition qdom.cpp:3183
QDomDocumentType()
Creates an empty QDomDocumentType object.
Definition qdom.cpp:3115
QDomNamedNodeMap notations() const
Returns a map of all notations described in the DTD.
Definition qdom.cpp:3170
QDomDocumentType & operator=(const QDomDocumentType &)
Assigns n to this document type.
QString name() const
Returns the name of the document type as specified in the <!DOCTYPE name> tag.
Definition qdom.cpp:3150
QString internalSubset() const
Returns the internal subset of the document type or an empty string if there is no internal subset.
Definition qdom.cpp:3209
QString systemId() const
Returns the system identifier of the external DTD subset or an empty string if there is no system ide...
Definition qdom.cpp:3196
QDomNamedNodeMap entities() const
Returns a map of all entities described in the DTD.
Definition qdom.cpp:3160
\reentrant
Definition qdom.h:266
QDomText createTextNode(const QString &data)
Creates a text node for the string value that can be inserted into the document tree,...
Definition qdom.cpp:6532
QDomProcessingInstruction createProcessingInstruction(const QString &target, const QString &data)
Creates a new processing instruction that can be inserted into the document, e.g.
Definition qdom.cpp:6584
Q_WEAK_OVERLOAD ParseResult setContent(const QByteArray &data, ParseOptions options=ParseOption::Default)
Definition qdom.h:335
QByteArray toByteArray(int=1) const
Converts the parsed document back to its textual representation and returns a QByteArray containing t...
Definition qdom.cpp:6455
friend class QDomNode
Definition qdom.h:350
QDomAttr createAttribute(const QString &name)
Creates a new attribute called name that can be inserted into an element, e.g.
Definition qdom.cpp:6602
QDomDocument & operator=(const QDomDocument &)
Assigns x to this DOM document.
QDomNode importNode(const QDomNode &importedNode, bool deep)
Imports the node importedNode from another document to this document.
Definition qdom.cpp:6707
QDomElement documentElement() const
Returns the root element of the document.
Definition qdom.cpp:6486
QDomCDATASection createCDATASection(const QString &data)
Creates a new CDATA section for the string value that can be inserted into the document,...
Definition qdom.cpp:6565
QDomElement createElement(const QString &tagName)
Creates a new element called tagName that can be inserted into the DOM tree, e.g.
Definition qdom.cpp:6503
QDomDocument()
Constructs an empty document.
Definition qdom.cpp:6027
~QDomDocument()
Destroys the object and frees its resources.
Definition qdom.cpp:6081
QString toString(int=1) const
Converts the parsed document back to its textual representation.
Definition qdom.cpp:6438
QDomImplementation implementation() const
Returns a QDomImplementation object.
Definition qdom.cpp:6476
QDomNodeList elementsByTagName(const QString &tagname) const
Returns a QDomNodeList, that contains all the elements in the document with the name tagname.
Definition qdom.cpp:6633
QDomNodeList elementsByTagNameNS(const QString &nsURI, const QString &localName)
Returns a QDomNodeList that contains all the elements in the document with the local name localName a...
Definition qdom.cpp:6762
QDomDocumentFragment createDocumentFragment()
Creates a new document fragment, that can be used to hold parts of the document, e....
Definition qdom.cpp:6515
QDomAttr createAttributeNS(const QString &nsURI, const QString &qName)
Creates a new attribute with namespace support that can be inserted into an element.
Definition qdom.cpp:6747
QDomEntityReference createEntityReference(const QString &name)
Creates a new entity reference called name that can be inserted into the document,...
Definition qdom.cpp:6618
QDomElement elementById(const QString &elementId)
Returns the element whose ID is equal to elementId.
Definition qdom.cpp:6777
QDomComment createComment(const QString &data)
Creates a new comment for the string value that can be inserted into the document,...
Definition qdom.cpp:6548
QDomDocumentType doctype() const
Returns the document type of this document.
Definition qdom.cpp:6466
QDomElement createElementNS(const QString &nsURI, const QString &qName)
Creates a new element with namespace support that can be inserted into the DOM tree.
Definition qdom.cpp:6728
bool hasAttribute(const QString &name)
Definition qdom.cpp:3973
QDomElementPrivate(QDomDocumentPrivate *, QDomNodePrivate *parent, const QString &name)
Definition qdom.cpp:3834
QString attributeNS(const QString &nsURI, const QString &localName, const QString &defValue) const
Definition qdom.cpp:3883
QDomNamedNodeMapPrivate * m_attr
Definition qdom_p.h:332
QString attribute(const QString &name, const QString &defValue) const
Definition qdom.cpp:3874
virtual void save(QTextStream &s, int, int) const override
Definition qdom.cpp:3999
void setAttribute(const QString &name, const QString &value)
Definition qdom.cpp:3892
void removeAttribute(const QString &name)
Definition qdom.cpp:3927
QDomAttrPrivate * removeAttributeNode(QDomAttrPrivate *oldAttr)
Definition qdom.cpp:3968
QDomNodePrivate * cloneNode(bool deep=true) override
Definition qdom.cpp:3866
bool hasAttributeNS(const QString &nsURI, const QString &localName)
Definition qdom.cpp:3978
QDomAttrPrivate * attributeNode(const QString &name)
Definition qdom.cpp:3934
QString text()
Definition qdom.cpp:3983
QDomAttrPrivate * setAttributeNodeNS(QDomAttrPrivate *newAttr)
Definition qdom.cpp:3956
QDomAttrPrivate * setAttributeNode(QDomAttrPrivate *newAttr)
Definition qdom.cpp:3944
void setAttributeNS(const QString &nsURI, const QString &qName, const QString &newValue)
Definition qdom.cpp:3908
QDomAttrPrivate * attributeNodeNS(const QString &nsURI, const QString &localName)
Definition qdom.cpp:3939
\reentrant
Definition qdom.h:468
void removeAttributeNS(const QString &nsURI, const QString &localName)
Removes the attribute with the local name localName and the namespace URI nsURI from this element.
Definition qdom.cpp:4547
QDomAttr setAttributeNodeNS(const QDomAttr &newAttr)
Adds the attribute newAttr to this element.
Definition qdom.cpp:4582
bool hasAttributeNS(const QString &nsURI, const QString &localName) const
Returns true if this element has an attribute with the local name localName and the namespace URI nsU...
Definition qdom.cpp:4608
void removeAttribute(const QString &name)
Removes the attribute called name name from this element.
Definition qdom.cpp:4377
bool hasAttribute(const QString &name) const
Returns true if this element has an attribute called name; otherwise returns false.
Definition qdom.cpp:4453
QDomAttr attributeNode(const QString &name)
Returns the QDomAttr object that corresponds to the attribute called name.
Definition qdom.cpp:4391
QDomAttr attributeNodeNS(const QString &nsURI, const QString &localName)
Returns the QDomAttr object that corresponds to the attribute with the local name localName and the n...
Definition qdom.cpp:4565
void setAttribute(const QString &name, const QString &value)
Adds an attribute called name with value value.
Definition qdom.cpp:4295
QString tagName() const
Returns the tag name of this element.
Definition qdom.cpp:4255
QDomAttr setAttributeNode(const QDomAttr &newAttr)
Adds the attribute newAttr to this element.
Definition qdom.cpp:4408
friend class QDomAttr
Definition qdom.h:522
void setAttributeNS(const QString &nsURI, const QString &qName, const QString &value)
Adds an attribute with the qualified name qName and the namespace URI nsURI with the value value.
Definition qdom.cpp:4486
QDomNamedNodeMap attributes() const
Returns a QDomNamedNodeMap containing all this element's attributes.
Definition qdom.cpp:4268
QString text() const
Returns the element's text or an empty string.
Definition qdom.cpp:4629
QDomNodeList elementsByTagNameNS(const QString &nsURI, const QString &localName) const
Returns a QDomNodeList containing all descendants of this element with local name localName and names...
Definition qdom.cpp:4598
QDomAttr removeAttributeNode(const QDomAttr &oldAttr)
Removes the attribute oldAttr from the element and returns it.
Definition qdom.cpp:4420
void setTagName(const QString &name)
Sets this element's tag name to name.
Definition qdom.cpp:4240
QDomElement()
Constructs an empty element.
Definition qdom.cpp:4198
QString attributeNS(const QString &nsURI, const QString &localName, const QString &defValue=QString()) const
Returns the attribute with the local name localName and the namespace URI nsURI.
Definition qdom.cpp:4467
QDomElement & operator=(const QDomElement &)
Assigns x to this DOM element.
QDomNodeList elementsByTagName(const QString &tagname) const
Returns a QDomNodeList containing all descendants of this element named tagname encountered during a ...
Definition qdom.cpp:4436
QString attribute(const QString &name, const QString &defValue=QString()) const
Returns the attribute called name.
Definition qdom.cpp:4281
QString m_sys
Definition qdom_p.h:389
QString m_notationName
Definition qdom_p.h:391
virtual void save(QTextStream &s, int, int) const override
Definition qdom.cpp:5197
QDomEntityPrivate(QDomDocumentPrivate *, QDomNodePrivate *parent, const QString &name, const QString &pub, const QString &sys, const QString &notation)
Definition qdom.cpp:5134
QString m_pub
Definition qdom_p.h:390
QDomNodePrivate * cloneNode(bool deep=true) override
Definition qdom.cpp:5153
QDomNodePrivate * cloneNode(bool deep=true) override
Definition qdom.cpp:5353
QDomEntityReferencePrivate(QDomDocumentPrivate *, QDomNodePrivate *parent, const QString &name)
Definition qdom.cpp:5342
virtual void save(QTextStream &s, int, int) const override
Definition qdom.cpp:5361
\reentrant
Definition qdom.h:623
QDomEntityReference & operator=(const QDomEntityReference &)
Assigns x to this entity reference.
QDomEntityReference()
Constructs an empty entity reference.
Definition qdom.cpp:5412
\reentrant
Definition qdom.h:602
QDomEntity & operator=(const QDomEntity &)
Assigns x to this DOM entity.
QString publicId() const
Returns the public identifier associated with this entity.
Definition qdom.cpp:5304
QString systemId() const
Returns the system identifier associated with this entity.
Definition qdom.cpp:5315
QString notationName() const
For unparsed entities this function returns the name of the notation for the entity.
Definition qdom.cpp:5327
QDomEntity()
Constructs an empty entity.
Definition qdom.cpp:5262
static QDomImplementation::InvalidDataPolicy invalidDataPolicy
Definition qdom_p.h:40
QDomImplementationPrivate * clone()
Definition qdom.cpp:324
\reentrant
Definition qdom.h:58
bool operator!=(const QDomImplementation &) const
Returns true if x and this DOM implementation object were created from different QDomDocuments; other...
Definition qdom.cpp:420
bool operator==(const QDomImplementation &) const
Returns true if x and this DOM implementation object were created from the same QDomDocument; otherwi...
Definition qdom.cpp:411
QDomDocument createDocument(const QString &nsURI, const QString &qName, const QDomDocumentType &doctype)
Creates a DOM document with the document type doctype.
Definition qdom.cpp:519
QDomImplementation()
Constructs a QDomImplementation object.
Definition qdom.cpp:371
QDomDocumentType createDocumentType(const QString &qName, const QString &publicId, const QString &systemId)
Creates a document type node for the name qName.
Definition qdom.cpp:486
friend class QDomDocument
Definition qdom.h:83
InvalidDataPolicy
This enum specifies what should be done when a factory function in QDomDocument is called with invali...
Definition qdom.h:72
bool isNull()
Returns false if the object was created by QDomDocument::implementation(); otherwise returns true.
Definition qdom.cpp:533
bool hasFeature(const QString &feature, const QString &version) const
The function returns true if QDom implements the requested version of a feature; otherwise returns fa...
Definition qdom.cpp:444
static void setInvalidDataPolicy(InvalidDataPolicy policy)
Definition qdom.cpp:596
static InvalidDataPolicy invalidDataPolicy()
Definition qdom.cpp:576
~QDomImplementation()
Destroys the object and frees its resources.
Definition qdom.cpp:428
QDomImplementation & operator=(const QDomImplementation &)
Assigns x to this DOM implementation.
Definition qdom.cpp:397
bool contains(const QString &name) const
Definition qdom.cpp:2635
void setAppendToParent(bool b)
Definition qdom_p.h:192
QDomNamedNodeMapPrivate * clone(QDomNodePrivate *parent)
Definition qdom.cpp:2519
QDomNodePrivate * namedItemNS(const QString &nsURI, const QString &localName) const
Definition qdom.cpp:2555
QDomNodePrivate * item(int index) const
Definition qdom.cpp:2623
QDomNamedNodeMapPrivate(QDomNodePrivate *)
Definition qdom.cpp:2507
QDomNodePrivate * setNamedItem(QDomNodePrivate *arg)
Definition qdom.cpp:2570
QMultiHash< QString, QDomNodePrivate * > map
Definition qdom_p.h:202
bool containsNS(const QString &nsURI, const QString &localName) const
Definition qdom.cpp:2640
QDomNodePrivate * namedItem(const QString &name) const
Definition qdom.cpp:2549
QDomNodePrivate * removeNamedItem(const QString &name)
Definition qdom.cpp:2606
QDomNodePrivate * parent
Definition qdom_p.h:203
QDomNodePrivate * setNamedItemNS(QDomNodePrivate *arg)
Definition qdom.cpp:2585
\reentrant
Definition qdom.h:354
~QDomNamedNodeMap()
Destroys the object and frees its resources.
Definition qdom.cpp:2750
QDomNode namedItemNS(const QString &nsURI, const QString &localName) const
Returns the node associated with the local name localName and the namespace URI nsURI.
Definition qdom.cpp:2829
QDomNode removeNamedItem(const QString &name)
Removes the node called name from the map.
Definition qdom.cpp:2798
friend class QDomNode
Definition qdom.h:385
QDomNamedNodeMap()
Constructs an empty named node map.
Definition qdom.cpp:2694
QDomNode removeNamedItemNS(const QString &nsURI, const QString &localName)
Removes the node with the local name localName and the namespace URI nsURI from the map.
Definition qdom.cpp:2862
bool operator==(const QDomNamedNodeMap &) const
Returns true if n and this named node map are equal; otherwise returns false.
Definition qdom.cpp:2733
QDomNode namedItem(const QString &name) const
Returns the node called name.
Definition qdom.cpp:2765
QDomNode setNamedItem(const QDomNode &newNode)
Inserts the node newNode into the named node map.
Definition qdom.cpp:2782
int length() const
Returns the number of nodes in the map.
Definition qdom.cpp:2877
bool contains(const QString &name) const
Returns true if the map contains a node called name; otherwise returns false.
Definition qdom.cpp:2911
QDomNode setNamedItemNS(const QDomNode &newNode)
Inserts the node newNode in the map.
Definition qdom.cpp:2844
QDomNode item(int index) const
Retrieves the node at position index.
Definition qdom.cpp:2813
QDomNamedNodeMap & operator=(const QDomNamedNodeMap &)
Assigns n to this named node map.
Definition qdom.cpp:2719
bool operator!=(const QDomNamedNodeMap &) const
Returns true if n and this named node map are not equal; otherwise returns false.
Definition qdom.cpp:2742
QAtomicInt ref
Definition qdom_p.h:149
QList< QDomNodePrivate * > list
Definition qdom_p.h:156
int length() const
Definition qdom.cpp:721
bool operator==(const QDomNodeListPrivate &) const
Definition qdom.cpp:642
QDomNodePrivate * node_impl
Definition qdom_p.h:153
QDomNodePrivate * item(int index)
Definition qdom.cpp:706
QDomNodeListPrivate(QDomNodePrivate *)
Definition qdom.cpp:607
bool operator!=(const QDomNodeListPrivate &) const
Definition qdom.cpp:647
\reentrant
Definition qdom.h:211
bool operator==(const QDomNodeList &) const
Returns true if the node list n and this node list are equal; otherwise returns false.
Definition qdom.cpp:806
friend class QDomNode
Definition qdom.h:234
QDomNode item(int index) const
Returns the node at position index.
Definition qdom.cpp:842
int length() const
Returns the number of nodes in the list.
Definition qdom.cpp:853
~QDomNodeList()
Destroys the object and frees its resources.
Definition qdom.cpp:827
QDomNodeList & operator=(const QDomNodeList &)
Assigns n to this node list.
Definition qdom.cpp:792
bool operator!=(const QDomNodeList &) const
Returns true the node list n and this node list are not equal; otherwise returns false.
Definition qdom.cpp:819
QDomNodeList()
Creates an empty node list.
Definition qdom.cpp:769
QDomDocumentPrivate * ownerDocument()
Definition qdom.cpp:1309
bool isComment() const
Definition qdom_p.h:107
QDomNodePrivate * next
Definition qdom_p.h:118
void setOwnerDocument(QDomDocumentPrivate *doc)
Definition qdom.cpp:896
bool isAttr() const
Definition qdom_p.h:83
void setNoParent()
Definition qdom_p.h:76
bool isElement() const
Definition qdom_p.h:88
virtual void clear()
Definition qdom.cpp:957
bool isDocumentFragment() const
Definition qdom_p.h:85
virtual void setNodeValue(const QString &v)
Definition qdom_p.h:52
QString nodeName() const
Definition qdom_p.h:50
QString nodeValue() const
Definition qdom_p.h:51
QString value
Definition qdom_p.h:124
virtual QDomNodePrivate * insertAfter(QDomNodePrivate *newChild, QDomNodePrivate *refChild)
Definition qdom.cpp:1079
QAtomicInt ref
Definition qdom_p.h:116
bool isNotation() const
Definition qdom_p.h:96
virtual ~QDomNodePrivate()
Definition qdom.cpp:940
QDomNodePrivate * first
Definition qdom_p.h:120
QDomNodePrivate(QDomDocumentPrivate *, QDomNodePrivate *parent=nullptr)
Definition qdom.cpp:902
QString namespaceURI
Definition qdom_p.h:126
QDomNodePrivate * last
Definition qdom_p.h:121
QDomNodePrivate * ownerNode
Definition qdom_p.h:119
QDomNodePrivate * prev
Definition qdom_p.h:117
bool isCDATASection() const
Definition qdom_p.h:84
bool isEntityReference() const
Definition qdom_p.h:89
virtual QDomNodePrivate * appendChild(QDomNodePrivate *newChild)
Definition qdom.cpp:1303
virtual void normalize()
Definition qdom.cpp:1351
virtual void save(QTextStream &, int, int) const
Definition qdom.cpp:1361
QString name
Definition qdom_p.h:123
QDomNodePrivate * namedItem(const QString &name)
Definition qdom.cpp:972
bool isText() const
Definition qdom_p.h:90
bool isDocument() const
Definition qdom_p.h:86
void setParent(QDomNodePrivate *p)
Definition qdom_p.h:70
virtual QDomNodePrivate * removeChild(QDomNodePrivate *oldChild)
Definition qdom.cpp:1267
bool isEntity() const
Definition qdom_p.h:95
void setLocation(int lineNumber, int columnNumber)
Definition qdom.cpp:1370
QString prefix
Definition qdom_p.h:125
bool createdWithDom1Interface
Definition qdom_p.h:127
QDomNodePrivate * parent() const
Definition qdom_p.h:69
bool isDocumentType() const
Definition qdom_p.h:87
virtual QDomNodePrivate * replaceChild(QDomNodePrivate *newChild, QDomNodePrivate *oldChild)
Definition qdom.cpp:1175
virtual QDomNodePrivate * cloneNode(bool deep=true)
Definition qdom.cpp:1321
virtual QDomNode::NodeType nodeType() const
Definition qdom_p.h:109
bool isCharacterData() const
Definition qdom_p.h:101
bool isProcessingInstruction() const
Definition qdom_p.h:97
virtual QDomNodePrivate * insertBefore(QDomNodePrivate *newChild, QDomNodePrivate *refChild)
Definition qdom.cpp:984
\reentrant
Definition qdom.h:87
QString nodeName() const
Returns the name of the node.
Definition qdom.cpp:1589
EncodingPolicy
Definition qdom.h:107
@ EncodingFromDocument
Definition qdom.h:108
bool isCharacterData() const
Returns true if the node is a character data node; otherwise returns false.
Definition qdom.cpp:2358
void save(QTextStream &, int, EncodingPolicy=QDomNode::EncodingFromDocument) const
Writes the XML representation of the node and all its children to the stream stream.
Definition qdom.cpp:2148
int columnNumber() const
Definition qdom.cpp:2495
QDomDocument toDocument() const
Converts a QDomNode into a QDomDocument.
Definition qdom.cpp:6842
QDomEntityReference toEntityReference() const
Converts a QDomNode into a QDomEntityReference.
Definition qdom.cpp:6881
QDomNode()
Constructs a \l{isNull()}{null} node.
Definition qdom.cpp:1471
friend class QDomDocumentType
Definition qdom.h:205
QDomNode replaceChild(const QDomNode &newChild, const QDomNode &oldChild)
Replaces oldChild with newChild.
Definition qdom.cpp:2015
QDomNode parentNode() const
Returns the parent node.
Definition qdom.cpp:1675
QDomNodeList childNodes() const
Returns a list of all direct child nodes.
Definition qdom.cpp:1700
QDomDocumentType toDocumentType() const
Converts a QDomNode into a QDomDocumentType.
Definition qdom.cpp:6855
QDomNodePrivate * impl
Definition qdom.h:200
friend class QDomNodeList
Definition qdom.h:206
friend class QDomDocument
Definition qdom.h:204
QString prefix() const
Returns the namespace prefix of the node or an empty string if the node has no namespace prefix.
Definition qdom.cpp:1884
QDomElement lastChildElement(const QString &tagName=QString(), const QString &namespaceURI=QString()) const
Returns the last child element with tag name tagName and namespace URI namespaceURI.
Definition qdom.cpp:2414
bool hasChildNodes() const
Returns true if the node has one or more children; otherwise returns false.
Definition qdom.cpp:2078
QDomEntity toEntity() const
Converts a QDomNode into a QDomEntity.
Definition qdom.cpp:6907
QDomNode insertAfter(const QDomNode &newChild, const QDomNode &refChild)
Inserts the node newChild after the child node refChild.
Definition qdom.cpp:1993
int lineNumber() const
Definition qdom.cpp:2481
QDomElement nextSiblingElement(const QString &taName=QString(), const QString &namespaceURI=QString()) const
Returns the next sibling element with tag name tagName and namespace URI namespaceURI.
Definition qdom.cpp:2437
QDomDocumentFragment toDocumentFragment() const
Converts a QDomNode into a QDomDocumentFragment.
Definition qdom.cpp:6829
QDomAttr toAttr() const
Converts a QDomNode into a QDomAttr.
Definition qdom.cpp:6803
friend class QDomNamedNodeMap
Definition qdom.h:207
QDomNode lastChild() const
Returns the last child of the node.
Definition qdom.cpp:1728
bool isAttr() const
Returns true if the node is an attribute; otherwise returns false.
Definition qdom.cpp:2181
bool isProcessingInstruction() const
Returns true if the node is a processing instruction; otherwise returns false.
Definition qdom.cpp:2341
QDomCDATASection toCDATASection() const
Converts a QDomNode into a QDomCDATASection.
Definition qdom.cpp:6816
QDomCharacterData toCharacterData() const
Converts a QDomNode into a QDomCharacterData.
Definition qdom.cpp:6946
void clear()
Converts the node into a null node; if it was not a null node before, its type and contents are delet...
Definition qdom.cpp:2100
QDomNode firstChild() const
Returns the first child of the node.
Definition qdom.cpp:1714
QDomNotation toNotation() const
Converts a QDomNode into a QDomNotation.
Definition qdom.cpp:6920
QDomElement toElement() const
Converts a QDomNode into a QDomElement.
Definition qdom.cpp:6868
bool isEntity() const
Returns true if the node is an entity; otherwise returns false.
Definition qdom.cpp:2309
void setNodeValue(const QString &)
Sets the node's value to v.
Definition qdom.cpp:1629
QDomNode nextSibling() const
Returns the next sibling in the document tree.
Definition qdom.cpp:1768
QString namespaceURI() const
Returns the namespace URI of this node or an empty string if the node has no namespace URI.
Definition qdom.cpp:1855
QDomDocument ownerDocument() const
Returns the document to which this node belongs.
Definition qdom.cpp:1795
bool isEntityReference() const
Returns true if the node is an entity reference; otherwise returns false.
Definition qdom.cpp:2279
bool operator!=(const QDomNode &) const
Returns true if n and this DOM node are not equal; otherwise returns false.
Definition qdom.cpp:1546
QDomNode namedItem(const QString &name) const
Returns the first direct child node for which nodeName() equals name.
Definition qdom.cpp:2116
QDomNode cloneNode(bool deep=true) const
Creates a deep (not shallow) copy of the QDomNode.
Definition qdom.cpp:1810
bool isText() const
Returns true if the node is a text node; otherwise returns false.
Definition qdom.cpp:2294
bool isNotation() const
Returns true if the node is a notation; otherwise returns false.
Definition qdom.cpp:2324
void setPrefix(const QString &pre)
If the node has a namespace prefix, this function changes the namespace prefix of the node to pre.
Definition qdom.cpp:1905
bool isNull() const
Returns true if this node is null (i.e.
Definition qdom.cpp:2089
QDomProcessingInstruction toProcessingInstruction() const
Converts a QDomNode into a QDomProcessingInstruction.
Definition qdom.cpp:6933
void normalize()
Calling normalize() on an element converts all its children into a standard form.
Definition qdom.cpp:1823
QString localName() const
If the node uses namespaces, this function returns the local name of the node; otherwise it returns a...
Definition qdom.cpp:1925
QTextStream & operator<<(QTextStream &str, const QDomNode &node)
Writes the XML representation of the node node and all its children to the stream str.
Definition qdom.cpp:2165
QDomText toText() const
Converts a QDomNode into a QDomText.
Definition qdom.cpp:6894
bool isComment() const
Returns true if the node is a comment; otherwise returns false.
Definition qdom.cpp:2373
bool isDocumentFragment() const
Returns true if the node is a document fragment; otherwise returns false.
Definition qdom.cpp:2215
QDomNamedNodeMap attributes() const
Returns a named node map of all attributes.
Definition qdom.cpp:1784
bool hasAttributes() const
Returns true if the node has attributes; otherwise returns false.
Definition qdom.cpp:1937
QDomElement previousSiblingElement(const QString &tagName=QString(), const QString &namespaceURI=QString()) const
Returns the previous sibling element with tag name tagName and namespace URI namespaceURI.
Definition qdom.cpp:2460
bool isElement() const
Returns true if the node is an element; otherwise returns false.
Definition qdom.cpp:2262
QDomNode & operator=(const QDomNode &)
Assigns a copy of n to this DOM node.
Definition qdom.cpp:1507
bool isCDATASection() const
Returns true if the node is a CDATA section; otherwise returns false.
Definition qdom.cpp:2198
NodeType
This enum defines the type of the node: \value ElementNode \value AttributeNode \value TextNode \valu...
Definition qdom.h:89
@ EntityReferenceNode
Definition qdom.h:94
@ CommentNode
Definition qdom.h:97
@ DocumentFragmentNode
Definition qdom.h:100
@ CDATASectionNode
Definition qdom.h:93
@ EntityNode
Definition qdom.h:95
@ TextNode
Definition qdom.h:92
@ ElementNode
Definition qdom.h:90
@ CharacterDataNode
Definition qdom.h:103
@ BaseNode
Definition qdom.h:102
@ NotationNode
Definition qdom.h:101
@ ProcessingInstructionNode
Definition qdom.h:96
@ AttributeNode
Definition qdom.h:91
bool isSupported(const QString &feature, const QString &version) const
Returns true if the DOM implementation implements the feature feature and this feature is supported b...
Definition qdom.cpp:1837
QDomNode insertBefore(const QDomNode &newChild, const QDomNode &refChild)
Inserts the node newChild before the child node refChild.
Definition qdom.cpp:1965
bool operator==(const QDomNode &) const
Returns true if n and this DOM node are equal; otherwise returns false.
Definition qdom.cpp:1537
QString nodeValue() const
Returns the value of the node.
Definition qdom.cpp:1617
QDomNode removeChild(const QDomNode &oldChild)
Removes oldChild from the list of children.
Definition qdom.cpp:2030
bool isDocument() const
Returns true if the node is a document; otherwise returns false.
Definition qdom.cpp:2230
QDomElement firstChildElement(const QString &tagName=QString(), const QString &namespaceURI=QString()) const
Returns the first child element with tag name tagName and namespace URI namespaceURI.
Definition qdom.cpp:2392
QDomComment toComment() const
Converts a QDomNode into a QDomComment.
Definition qdom.cpp:6959
QDomNode previousSibling() const
Returns the previous sibling in the document tree.
Definition qdom.cpp:1748
QDomNode appendChild(const QDomNode &newChild)
Appends newChild as the node's last child.
Definition qdom.cpp:2065
bool isDocumentType() const
Returns true if the node is a document type; otherwise returns false.
Definition qdom.cpp:2247
NodeType nodeType() const
Returns the type of the node.
Definition qdom.cpp:1664
~QDomNode()
Destroys the object and frees its resources.
Definition qdom.cpp:1554
virtual void save(QTextStream &s, int, int) const override
Definition qdom.cpp:5016
QDomNotationPrivate(QDomDocumentPrivate *, QDomNodePrivate *parent, const QString &name, const QString &pub, const QString &sys)
Definition qdom.cpp:4991
QDomNodePrivate * cloneNode(bool deep=true) override
Definition qdom.cpp:5008
\reentrant
Definition qdom.h:581
QDomNotation()
Constructor.
Definition qdom.cpp:5069
QDomNotation & operator=(const QDomNotation &)
Assigns x to this DOM notation.
QString publicId() const
Returns the public identifier of this notation.
Definition qdom.cpp:5109
QString systemId() const
Returns the system identifier of this notation.
Definition qdom.cpp:5119
QDomDocument::ParseResult result() const
QDomNodePrivate * cloneNode(bool deep=true) override
Definition qdom.cpp:5469
virtual void save(QTextStream &s, int, int) const override
Definition qdom.cpp:5477
QDomProcessingInstructionPrivate(QDomDocumentPrivate *, QDomNodePrivate *parent, const QString &target, const QString &data)
Definition qdom.cpp:5455
QDomProcessingInstruction()
Constructs an empty processing instruction.
Definition qdom.cpp:5526
QDomProcessingInstruction & operator=(const QDomProcessingInstruction &)
Assigns x to this processing instruction.
QString target() const
Returns the target of this processing instruction.
Definition qdom.cpp:5569
void setData(const QString &d)
Sets the data contained in the processing instruction to d.
Definition qdom.cpp:5593
QString data() const
Returns the content of this processing instruction.
Definition qdom.cpp:5581
QDomNodePrivate * cloneNode(bool deep=true) override
Definition qdom.cpp:4655
QDomTextPrivate(QDomDocumentPrivate *, QDomNodePrivate *parent, const QString &val)
Definition qdom.cpp:4644
QDomTextPrivate * splitText(int offset)
Definition qdom.cpp:4663
virtual void save(QTextStream &s, int, int) const override
Definition qdom.cpp:4678
\reentrant
Definition qdom.h:526
QDomText()
Constructs an empty QDomText object.
Definition qdom.cpp:4715
QDomText splitText(int offset)
Splits this DOM text object into two QDomText objects.
Definition qdom.cpp:4762
QDomText & operator=(const QDomText &)
Assigns x to this DOM text.
bool hasSeen(const T &s)
void reset(T *ptr=nullptr) noexcept
\inmodule QtCore \reentrant
Definition qiodevice.h:34
qsizetype size() const noexcept
Definition qlist.h:386
const_reference at(qsizetype i) const noexcept
Definition qlist.h:429
void append(parameter_type t)
Definition qlist.h:441
void clear()
Definition qlist.h:417
iterator find(const Key &key)
Definition qhash.h:1904
const_iterator constBegin() const noexcept
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first item in the hash.
Definition qhash.h:1829
const_iterator constEnd() const noexcept
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item after the ...
Definition qhash.h:1833
T value(const Key &key) const noexcept
Definition qhash.h:1618
bool contains(const Key &key) const noexcept
Definition qhash.h:1567
qsizetype remove(const Key &key)
Definition qhash.h:1519
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition qhash.h:1930
bool isEmpty() const noexcept
Definition qhash.h:1492
iterator begin()
Returns an \l{STL-style iterators}{STL-style iterator} pointing to the first item in the hash.
Definition qhash.h:1826
qsizetype size() const noexcept
Definition qhash.h:1490
void clear() noexcept(std::is_nothrow_destructible< Node >::value)
Definition qhash.h:1511
iterator end() noexcept
Returns an \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item after the last ...
Definition qhash.h:1830
\inmodule QtCore \reentrant
QRegularExpressionMatch match(const QString &subject, qsizetype offset=0, MatchType matchType=NormalMatch, MatchOptions matchOptions=NoMatchOption) const
Attempts to match the regular expression against the given subject string, starting at the position o...
static Q_CORE_EXPORT const char * nameForEncoding(Encoding e)
Returns the canonical name for encoding e.
static Q_CORE_EXPORT std::optional< Encoding > encodingForName(const char *name) noexcept
Convert name to the corresponding \l Encoding member, if there is one.
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition qstring.cpp:5299
QString & replace(qsizetype i, qsizetype len, QChar after)
Definition qstring.cpp:3794
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:5710
void clear()
Clears the contents of the string and makes it null.
Definition qstring.h:1107
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition qstring.h:898
qsizetype size() const
Returns the number of characters in this string.
Definition qstring.h:182
QString mid(qsizetype position, qsizetype n=-1) const
Returns a string that contains n characters of this string, starting at the specified position index.
Definition qstring.cpp:5204
const QChar at(qsizetype i) const
Returns the character at the given index position in the string.
Definition qstring.h:1079
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition qstring.h:1083
int compare(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
Definition qstring.cpp:6498
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:7822
QString left(qsizetype n) const
Returns a substring that contains the n leftmost characters of the string.
Definition qstring.cpp:5161
static QString static QString qsizetype indexOf(QChar c, qsizetype from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition qstring.cpp:4420
QString & remove(qsizetype i, qsizetype len)
Removes n characters from the string, starting at the given position index, and returns a reference t...
Definition qstring.cpp:3435
QByteArray toUtf8() const &
Definition qstring.h:563
\inmodule QtCore
iterator end() noexcept
void push_back(const T &t)
void reserve(qsizetype sz)
iterator begin() noexcept
static bool isChar(const char32_t c)
static bool isPublicID(QStringView candidate)
static bool isLetter(const QChar c)
static bool isNameChar(const QChar c)
QString str
[2]
QString text
double e
QSet< QString >::iterator it
Combined button and popup list for selecting options.
QTextStream & endl(QTextStream &stream)
Writes '\n' to the stream and flushes the stream.
QImageReader reader("image.png")
[1]
#define QT_WARNING_POP
#define QT_WARNING_DISABLE_DEPRECATED
#define QT_WARNING_PUSH
DBusConnection const char DBusError * error
static QString fixedPIData(const QString &data, bool *ok)
Definition qdom.cpp:235
static QString fixedPubidLiteral(const QString &data, bool *ok)
Definition qdom.cpp:264
static QString fixedSystemLiteral(const QString &data, bool *ok)
Definition qdom.cpp:296
static QString fixedXmlName(const QString &_name, bool *ok, bool namespaces=false)
Definition qdom.cpp:98
static QString fixedCharData(const QString &data, bool *ok)
Definition qdom.cpp:152
#define IMPL
Definition qdom.cpp:1382
static QString quotedValue(const QString &data)
Definition qdom.cpp:3046
static void qt_split_namespace(QString &prefix, QString &name, const QString &qName, bool hasURI)
Definition qdom.cpp:73
static QString encodeText(const QString &str, const bool encodeQuotes=true, const bool performAVN=false, const bool encodeEOLs=false)
Definition qdom.cpp:3610
static QString fixedCDataSection(const QString &data, bool *ok)
Definition qdom.cpp:207
static QString fixedComment(const QString &data, bool *ok)
Definition qdom.cpp:178
static QByteArray encodeEntity(const QByteArray &str)
Definition qdom.cpp:5164
static void qNormalizeNode(QDomNodePrivate *n)
Definition qdom.cpp:1329
EGLStreamKHR stream
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
#define QT_RETHROW
#define QT_CATCH(A)
#define QT_TRY
#define qWarning
Definition qlogging.h:162
GLsizei const GLfloat * v
[13]
GLint GLint GLint GLint GLint x
[0]
GLint GLenum GLsizei GLsizei GLsizei depth
const GLfloat * m
GLuint64 key
GLboolean GLboolean GLboolean GLboolean a
[7]
GLuint index
[2]
GLenum GLenum GLsizei count
GLfloat GLfloat f
GLenum GLuint buffer
GLenum type
GLenum target
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum GLuint GLintptr offset
GLint ref
GLuint name
GLint first
GLfloat n
const GLubyte * c
GLuint GLfloat * val
GLenum GLsizei len
GLdouble GLdouble t
Definition qopenglext.h:243
GLuint64EXT * result
[6]
GLdouble s
[6]
Definition qopenglext.h:235
GLfloat GLfloat p
[1]
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
SSL_CTX int(*) void arg)
#define qPrintable(string)
Definition qstring.h:1391
#define QStringLiteral(str)
#define Q_UNUSED(x)
static bool match(const uchar *found, uint foundLen, const char *target, uint targetLen)
quint64 qulonglong
Definition qtypes.h:59
ptrdiff_t qsizetype
Definition qtypes.h:70
qint64 qlonglong
Definition qtypes.h:58
static QString quote(const QString &str)
QObject::connect nullptr
QSharedPointer< T > other(t)
[5]
QLayoutItem * child
[0]
QSizePolicy policy
The struct is used to store the result of QDomDocument::setContent().
Definition qdom.h:276
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent