Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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 methods 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
328
329/**************************************************************
330 *
331 * QDomImplementation
332 *
333 **************************************************************/
334
372{
373 impl = nullptr;
374}
375
380 : impl(implementation.impl)
381{
382 if (impl)
383 impl->ref.ref();
384}
385
387 : impl(pimpl)
388{
389 // We want to be co-owners, so increase the reference count
390 if (impl)
391 impl->ref.ref();
392}
393
398{
399 if (other.impl)
400 other.impl->ref.ref();
401 if (impl && !impl->ref.deref())
402 delete impl;
403 impl = other.impl;
404 return *this;
405}
406
412{
413 return impl == other.impl;
414}
415
421{
422 return !operator==(other);
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
580
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
641
643{
644 return (node_impl == other.node_impl) && (tagname == other.tagname);
645}
646
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 false;
710
711 const QDomDocumentPrivate *const doc = node_impl->ownerDocument();
712 if (!doc || timestamp != doc->nodeListTime)
713 createList();
714
715 return true;
716}
717
719{
720 if (!maybeCreateList() || index >= list.size() || index < 0)
721 return nullptr;
722
723 return list.at(index);
724}
725
727{
728 if (!maybeCreateList())
729 return 0;
730
731 return list.size();
732}
733
734/**************************************************************
735 *
736 * QDomNodeList
737 *
738 **************************************************************/
739
769 : impl(nullptr)
770{
771}
772
774 : impl(pimpl)
775{
776}
777
782 : impl(nodeList.impl)
783{
784 if (impl)
785 impl->ref.ref();
786}
787
792{
793 if (other.impl)
794 other.impl->ref.ref();
795 if (impl && !impl->ref.deref())
796 delete impl;
797 impl = other.impl;
798 return *this;
799}
800
806{
807 if (impl == other.impl)
808 return true;
809 if (!impl || !other.impl)
810 return false;
811 return (*impl == *other.impl);
812}
813
819{
820 return !operator==(other);
821}
822
827{
828 if (impl && !impl->ref.deref())
829 delete impl;
830}
831
842{
843 if (!impl)
844 return QDomNode();
845
846 return QDomNode(impl->item(index));
847}
848
853{
854 if (!impl)
855 return 0;
856 return impl->length();
857}
858
889/**************************************************************
890 *
891 * QDomNodePrivate
892 *
893 **************************************************************/
894
896{
897 ownerNode = doc;
898 hasParent = false;
899}
900
902{
903 if (par)
904 setParent(par);
905 else
906 setOwnerDocument(doc);
907 prev = nullptr;
908 next = nullptr;
909 first = nullptr;
910 last = nullptr;
912 lineNumber = -1;
913 columnNumber = -1;
914}
915
917{
918 setOwnerDocument(n->ownerDocument());
919 prev = nullptr;
920 next = nullptr;
921 first = nullptr;
922 last = nullptr;
923
924 name = n->name;
925 value = n->value;
926 prefix = n->prefix;
927 namespaceURI = n->namespaceURI;
928 createdWithDom1Interface = n->createdWithDom1Interface;
929 lineNumber = -1;
930 columnNumber = -1;
931
932 if (!deep)
933 return;
934
935 for (QDomNodePrivate* x = n->first; x; x = x->next)
936 appendChild(x->cloneNode(true));
937}
938
940{
943
944 while (p) {
945 n = p->next;
946 if (!p->ref.deref())
947 delete p;
948 else
949 p->setNoParent();
950 p = n;
951 }
952 first = nullptr;
953 last = nullptr;
954}
955
957{
960
961 while (p) {
962 n = p->next;
963 if (!p->ref.deref())
964 delete p;
965 p = n;
966 }
967 first = nullptr;
968 last = nullptr;
969}
970
972{
974 while (p) {
975 if (p->nodeName() == n)
976 return p;
977 p = p->next;
978 }
979 return nullptr;
980}
981
982
984{
985 // Error check
986 if (!newChild)
987 return nullptr;
988
989 // Error check
990 if (newChild == refChild)
991 return nullptr;
992
993 // Error check
994 if (refChild && refChild->parent() != this)
995 return nullptr;
996
997 // "mark lists as dirty"
998 QDomDocumentPrivate *const doc = ownerDocument();
999 if (doc)
1000 doc->nodeListTime++;
1001
1002 // Special handling for inserting a fragment. We just insert
1003 // all elements of the fragment instead of the fragment itself.
1004 if (newChild->isDocumentFragment()) {
1005 // Fragment is empty ?
1006 if (newChild->first == nullptr)
1007 return newChild;
1008
1009 // New parent
1010 QDomNodePrivate* n = newChild->first;
1011 while (n) {
1012 n->setParent(this);
1013 n = n->next;
1014 }
1015
1016 // Insert at the beginning ?
1017 if (!refChild || refChild->prev == nullptr) {
1018 if (first)
1019 first->prev = newChild->last;
1020 newChild->last->next = first;
1021 if (!last)
1022 last = newChild->last;
1023 first = newChild->first;
1024 } else {
1025 // Insert in the middle
1026 newChild->last->next = refChild;
1027 newChild->first->prev = refChild->prev;
1028 refChild->prev->next = newChild->first;
1029 refChild->prev = newChild->last;
1030 }
1031
1032 // No need to increase the reference since QDomDocumentFragment
1033 // does not decrease the reference.
1034
1035 // Remove the nodes from the fragment
1036 newChild->first = nullptr;
1037 newChild->last = nullptr;
1038 return newChild;
1039 }
1040
1041 // No more errors can occur now, so we take
1042 // ownership of the node.
1043 newChild->ref.ref();
1044
1045 if (newChild->parent())
1046 newChild->parent()->removeChild(newChild);
1047
1048 newChild->setParent(this);
1049
1050 if (!refChild) {
1051 if (first)
1052 first->prev = newChild;
1053 newChild->next = first;
1054 if (!last)
1055 last = newChild;
1056 first = newChild;
1057 return newChild;
1058 }
1059
1060 if (refChild->prev == nullptr) {
1061 if (first)
1062 first->prev = newChild;
1063 newChild->next = first;
1064 if (!last)
1065 last = newChild;
1066 first = newChild;
1067 return newChild;
1068 }
1069
1070 newChild->next = refChild;
1071 newChild->prev = refChild->prev;
1072 refChild->prev->next = newChild;
1073 refChild->prev = newChild;
1074
1075 return newChild;
1076}
1077
1079{
1080 // Error check
1081 if (!newChild)
1082 return nullptr;
1083
1084 // Error check
1085 if (newChild == refChild)
1086 return nullptr;
1087
1088 // Error check
1089 if (refChild && refChild->parent() != this)
1090 return nullptr;
1091
1092 // "mark lists as dirty"
1093 QDomDocumentPrivate *const doc = ownerDocument();
1094 if (doc)
1095 doc->nodeListTime++;
1096
1097 // Special handling for inserting a fragment. We just insert
1098 // all elements of the fragment instead of the fragment itself.
1099 if (newChild->isDocumentFragment()) {
1100 // Fragment is empty ?
1101 if (newChild->first == nullptr)
1102 return newChild;
1103
1104 // New parent
1105 QDomNodePrivate* n = newChild->first;
1106 while (n) {
1107 n->setParent(this);
1108 n = n->next;
1109 }
1110
1111 // Insert at the end
1112 if (!refChild || refChild->next == nullptr) {
1113 if (last)
1114 last->next = newChild->first;
1115 newChild->first->prev = last;
1116 if (!first)
1117 first = newChild->first;
1118 last = newChild->last;
1119 } else { // Insert in the middle
1120 newChild->first->prev = refChild;
1121 newChild->last->next = refChild->next;
1122 refChild->next->prev = newChild->last;
1123 refChild->next = newChild->first;
1124 }
1125
1126 // No need to increase the reference since QDomDocumentFragment
1127 // does not decrease the reference.
1128
1129 // Remove the nodes from the fragment
1130 newChild->first = nullptr;
1131 newChild->last = nullptr;
1132 return newChild;
1133 }
1134
1135 // Release new node from its current parent
1136 if (newChild->parent())
1137 newChild->parent()->removeChild(newChild);
1138
1139 // No more errors can occur now, so we take
1140 // ownership of the node
1141 newChild->ref.ref();
1142
1143 newChild->setParent(this);
1144
1145 // Insert at the end
1146 if (!refChild) {
1147 if (last)
1148 last->next = newChild;
1149 newChild->prev = last;
1150 if (!first)
1151 first = newChild;
1152 last = newChild;
1153 return newChild;
1154 }
1155
1156 if (refChild->next == nullptr) {
1157 if (last)
1158 last->next = newChild;
1159 newChild->prev = last;
1160 if (!first)
1161 first = newChild;
1162 last = newChild;
1163 return newChild;
1164 }
1165
1166 newChild->prev = refChild;
1167 newChild->next = refChild->next;
1168 refChild->next->prev = newChild;
1169 refChild->next = newChild;
1170
1171 return newChild;
1172}
1173
1175{
1176 if (!newChild || !oldChild)
1177 return nullptr;
1178 if (oldChild->parent() != this)
1179 return nullptr;
1180 if (newChild == oldChild)
1181 return nullptr;
1182
1183 // mark lists as dirty
1184 QDomDocumentPrivate *const doc = ownerDocument();
1185 if (doc)
1186 doc->nodeListTime++;
1187
1188 // Special handling for inserting a fragment. We just insert
1189 // all elements of the fragment instead of the fragment itself.
1190 if (newChild->isDocumentFragment()) {
1191 // Fragment is empty ?
1192 if (newChild->first == nullptr)
1193 return newChild;
1194
1195 // New parent
1196 QDomNodePrivate* n = newChild->first;
1197 while (n) {
1198 n->setParent(this);
1199 n = n->next;
1200 }
1201
1202
1203 if (oldChild->next)
1204 oldChild->next->prev = newChild->last;
1205 if (oldChild->prev)
1206 oldChild->prev->next = newChild->first;
1207
1208 newChild->last->next = oldChild->next;
1209 newChild->first->prev = oldChild->prev;
1210
1211 if (first == oldChild)
1212 first = newChild->first;
1213 if (last == oldChild)
1214 last = newChild->last;
1215
1216 oldChild->setNoParent();
1217 oldChild->next = nullptr;
1218 oldChild->prev = nullptr;
1219
1220 // No need to increase the reference since QDomDocumentFragment
1221 // does not decrease the reference.
1222
1223 // Remove the nodes from the fragment
1224 newChild->first = nullptr;
1225 newChild->last = nullptr;
1226
1227 // We are no longer interested in the old node
1228 oldChild->ref.deref();
1229
1230 return oldChild;
1231 }
1232
1233 // No more errors can occur now, so we take
1234 // ownership of the node
1235 newChild->ref.ref();
1236
1237 // Release new node from its current parent
1238 if (newChild->parent())
1239 newChild->parent()->removeChild(newChild);
1240
1241 newChild->setParent(this);
1242
1243 if (oldChild->next)
1244 oldChild->next->prev = newChild;
1245 if (oldChild->prev)
1246 oldChild->prev->next = newChild;
1247
1248 newChild->next = oldChild->next;
1249 newChild->prev = oldChild->prev;
1250
1251 if (first == oldChild)
1252 first = newChild;
1253 if (last == oldChild)
1254 last = newChild;
1255
1256 oldChild->setNoParent();
1257 oldChild->next = nullptr;
1258 oldChild->prev = nullptr;
1259
1260 // We are no longer interested in the old node
1261 oldChild->ref.deref();
1262
1263 return oldChild;
1264}
1265
1267{
1268 // Error check
1269 if (oldChild->parent() != this)
1270 return nullptr;
1271
1272 // "mark lists as dirty"
1273 QDomDocumentPrivate *const doc = ownerDocument();
1274 if (doc)
1275 doc->nodeListTime++;
1276
1277 // Perhaps oldChild was just created with "createElement" or that. In this case
1278 // its parent is QDomDocument but it is not part of the documents child list.
1279 if (oldChild->next == nullptr && oldChild->prev == nullptr && first != oldChild)
1280 return nullptr;
1281
1282 if (oldChild->next)
1283 oldChild->next->prev = oldChild->prev;
1284 if (oldChild->prev)
1285 oldChild->prev->next = oldChild->next;
1286
1287 if (last == oldChild)
1288 last = oldChild->prev;
1289 if (first == oldChild)
1290 first = oldChild->next;
1291
1292 oldChild->setNoParent();
1293 oldChild->next = nullptr;
1294 oldChild->prev = nullptr;
1295
1296 // We are no longer interested in the old node
1297 oldChild->ref.deref();
1298
1299 return oldChild;
1300}
1301
1303{
1304 // No reference manipulation needed. Done in insertAfter.
1305 return insertAfter(newChild, nullptr);
1306}
1307
1309{
1310 QDomNodePrivate* p = this;
1311 while (p && !p->isDocument()) {
1312 if (!p->hasParent)
1313 return static_cast<QDomDocumentPrivate *>(p->ownerNode);
1314 p = p->parent();
1315 }
1316
1317 return static_cast<QDomDocumentPrivate *>(p);
1318}
1319
1321{
1322 QDomNodePrivate* p = new QDomNodePrivate(this, deep);
1323 // We are not interested in this node
1324 p->ref.deref();
1325 return p;
1326}
1327
1329{
1331 QDomTextPrivate* t = nullptr;
1332
1333 while (p) {
1334 if (p->isText()) {
1335 if (t) {
1336 QDomNodePrivate* tmp = p->next;
1337 t->appendData(p->nodeValue());
1338 n->removeChild(p);
1339 p = tmp;
1340 } else {
1341 t = static_cast<QDomTextPrivate *>(p);
1342 p = p->next;
1343 }
1344 } else {
1345 p = p->next;
1346 t = nullptr;
1347 }
1348 }
1349}
1351{
1352 // ### This one has moved from QDomElementPrivate to this position. It is
1353 // not tested.
1354 qNormalizeNode(this);
1355}
1356
1360void QDomNodePrivate::save(QTextStream& s, int depth, int indent) const
1361{
1362 const QDomNodePrivate* n = first;
1363 while (n) {
1364 n->save(s, depth, indent);
1365 n = n->next;
1366 }
1367}
1368
1369void QDomNodePrivate::setLocation(int lineNumber, int columnNumber)
1370{
1371 this->lineNumber = lineNumber;
1372 this->columnNumber = columnNumber;
1373}
1374
1375/**************************************************************
1376 *
1377 * QDomNode
1378 *
1379 **************************************************************/
1380
1381#define IMPL static_cast<QDomNodePrivate *>(impl)
1382
1471 : impl(nullptr)
1472{
1473}
1474
1483 : impl(node.impl)
1484{
1485 if (impl)
1486 impl->ref.ref();
1487}
1488
1493 : impl(pimpl)
1494{
1495 if (impl)
1496 impl->ref.ref();
1497}
1498
1507{
1508 if (other.impl)
1509 other.impl->ref.ref();
1510 if (impl && !impl->ref.deref())
1511 delete impl;
1512 impl = other.impl;
1513 return *this;
1514}
1515
1537{
1538 return impl == other.impl;
1539}
1540
1546{
1547 return !operator==(other);
1548}
1549
1554{
1555 if (impl && !impl->ref.deref())
1556 delete impl;
1557}
1558
1589{
1590 if (!impl)
1591 return QString();
1592
1593 if (!IMPL->prefix.isEmpty())
1594 return IMPL->prefix + u':' + IMPL->name;
1595 return IMPL->name;
1596}
1597
1617{
1618 if (!impl)
1619 return QString();
1620 return IMPL->value;
1621}
1622
1629{
1630 if (impl)
1631 IMPL->setNodeValue(value);
1632}
1633
1663{
1664 if (!impl)
1665 return QDomNode::BaseNode;
1666 return IMPL->nodeType();
1667}
1668
1674{
1675 if (!impl)
1676 return QDomNode();
1677 return QDomNode(IMPL->parent());
1678}
1679
1699{
1700 if (!impl)
1701 return QDomNodeList();
1703}
1704
1713{
1714 if (!impl)
1715 return QDomNode();
1716 return QDomNode(IMPL->first);
1717}
1718
1727{
1728 if (!impl)
1729 return QDomNode();
1730 return QDomNode(IMPL->last);
1731}
1732
1747{
1748 if (!impl)
1749 return QDomNode();
1750 return QDomNode(IMPL->prev);
1751}
1752
1767{
1768 if (!impl)
1769 return QDomNode();
1770 return QDomNode(IMPL->next);
1771}
1772
1773
1774// ###### don't think this is part of the DOM and
1783{
1784 if (!impl || !impl->isElement())
1785 return QDomNamedNodeMap();
1786
1787 return QDomNamedNodeMap(static_cast<QDomElementPrivate *>(impl)->attributes());
1788}
1789
1794{
1795 if (!impl)
1796 return QDomDocument();
1797 return QDomDocument(IMPL->ownerDocument());
1798}
1799
1809{
1810 if (!impl)
1811 return QDomNode();
1812 return QDomNode(IMPL->cloneNode(deep));
1813}
1814
1822{
1823 if (!impl)
1824 return;
1825 IMPL->normalize();
1826}
1827
1835bool QDomNode::isSupported(const QString& feature, const QString& version) const
1836{
1838 return i.hasFeature(feature, version);
1839}
1840
1854{
1855 if (!impl)
1856 return QString();
1857 return IMPL->namespaceURI;
1858}
1859
1883{
1884 if (!impl)
1885 return QString();
1886 return IMPL->prefix;
1887}
1888
1904{
1905 if (!impl || IMPL->prefix.isNull())
1906 return;
1907 if (isAttr() || isElement())
1908 IMPL->prefix = pre;
1909}
1910
1924{
1925 if (!impl || IMPL->createdWithDom1Interface)
1926 return QString();
1927 return IMPL->name;
1928}
1929
1936{
1937 if (!impl || !impl->isElement())
1938 return false;
1939 return static_cast<QDomElementPrivate *>(impl)->hasAttributes();
1940}
1941
1963QDomNode QDomNode::insertBefore(const QDomNode& newChild, const QDomNode& refChild)
1964{
1965 if (!impl)
1966 return QDomNode();
1967 return QDomNode(IMPL->insertBefore(newChild.impl, refChild.impl));
1968}
1969
1991QDomNode QDomNode::insertAfter(const QDomNode& newChild, const QDomNode& refChild)
1992{
1993 if (!impl)
1994 return QDomNode();
1995 return QDomNode(IMPL->insertAfter(newChild.impl, refChild.impl));
1996}
1997
2013QDomNode QDomNode::replaceChild(const QDomNode& newChild, const QDomNode& oldChild)
2014{
2015 if (!impl || !newChild.impl || !oldChild.impl)
2016 return QDomNode();
2017 return QDomNode(IMPL->replaceChild(newChild.impl, oldChild.impl));
2018}
2019
2029{
2030 if (!impl)
2031 return QDomNode();
2032
2033 if (oldChild.isNull())
2034 return QDomNode();
2035
2036 return QDomNode(IMPL->removeChild(oldChild.impl));
2037}
2038
2064{
2065 if (!impl) {
2066 qWarning("Calling appendChild() on a null node does nothing.");
2067 return QDomNode();
2068 }
2069 return QDomNode(IMPL->appendChild(newChild.impl));
2070}
2071
2077{
2078 if (!impl)
2079 return false;
2080 return IMPL->first != nullptr;
2081}
2082
2088{
2089 return (impl == nullptr);
2090}
2091
2099{
2100 if (impl && !impl->ref.deref())
2101 delete impl;
2102 impl = nullptr;
2103}
2104
2115{
2116 if (!impl)
2117 return QDomNode();
2118 return QDomNode(impl->namedItem(name));
2119}
2120
2146void QDomNode::save(QTextStream& stream, int indent, EncodingPolicy encodingPolicy) const
2147{
2148 if (!impl)
2149 return;
2150
2151 if (isDocument())
2152 static_cast<const QDomDocumentPrivate *>(impl)->saveDocument(stream, indent, encodingPolicy);
2153 else
2154 IMPL->save(stream, 1, indent);
2155}
2156
2164{
2165 node.save(str, 1);
2166
2167 return str;
2168}
2169
2180{
2181 if (impl)
2182 return impl->isAttr();
2183 return false;
2184}
2185
2197{
2198 if (impl)
2199 return impl->isCDATASection();
2200 return false;
2201}
2202
2214{
2215 if (impl)
2216 return impl->isDocumentFragment();
2217 return false;
2218}
2219
2229{
2230 if (impl)
2231 return impl->isDocument();
2232 return false;
2233}
2234
2246{
2247 if (impl)
2248 return impl->isDocumentType();
2249 return false;
2250}
2251
2261{
2262 if (impl)
2263 return impl->isElement();
2264 return false;
2265}
2266
2278{
2279 if (impl)
2280 return impl->isEntityReference();
2281 return false;
2282}
2283
2293{
2294 if (impl)
2295 return impl->isText();
2296 return false;
2297}
2298
2308{
2309 if (impl)
2310 return impl->isEntity();
2311 return false;
2312}
2313
2323{
2324 if (impl)
2325 return impl->isNotation();
2326 return false;
2327}
2328
2340{
2341 if (impl)
2342 return impl->isProcessingInstruction();
2343 return false;
2344}
2345
2357{
2358 if (impl)
2359 return impl->isCharacterData();
2360 return false;
2361}
2362
2372{
2373 if (impl)
2374 return impl->isComment();
2375 return false;
2376}
2377
2378#undef IMPL
2379
2390QDomElement QDomNode::firstChildElement(const QString &tagName, const QString &namespaceURI) const
2391{
2392 for (QDomNode child = firstChild(); !child.isNull(); child = child.nextSibling()) {
2393 if (child.isElement() && (namespaceURI.isEmpty() || child.namespaceURI() == namespaceURI)) {
2394 QDomElement elt = child.toElement();
2395 if (tagName.isEmpty() || elt.tagName() == tagName)
2396 return elt;
2397 }
2398 }
2399 return QDomElement();
2400}
2401
2412QDomElement QDomNode::lastChildElement(const QString &tagName, const QString &namespaceURI) const
2413{
2414 for (QDomNode child = lastChild(); !child.isNull(); child = child.previousSibling()) {
2415 if (child.isElement() && (namespaceURI.isEmpty() || child.namespaceURI() == namespaceURI)) {
2416 QDomElement elt = child.toElement();
2417 if (tagName.isEmpty() || elt.tagName() == tagName)
2418 return elt;
2419 }
2420 }
2421 return QDomElement();
2422}
2423
2435QDomElement QDomNode::nextSiblingElement(const QString &tagName, const QString &namespaceURI) const
2436{
2437 for (QDomNode sib = nextSibling(); !sib.isNull(); sib = sib.nextSibling()) {
2438 if (sib.isElement() && (namespaceURI.isEmpty() || sib.namespaceURI() == namespaceURI)) {
2439 QDomElement elt = sib.toElement();
2440 if (tagName.isEmpty() || elt.tagName() == tagName)
2441 return elt;
2442 }
2443 }
2444 return QDomElement();
2445}
2446
2458QDomElement QDomNode::previousSiblingElement(const QString &tagName, const QString &namespaceURI) const
2459{
2460 for (QDomNode sib = previousSibling(); !sib.isNull(); sib = sib.previousSibling()) {
2461 if (sib.isElement() && (namespaceURI.isEmpty() || sib.namespaceURI() == namespaceURI)) {
2462 QDomElement elt = sib.toElement();
2463 if (tagName.isEmpty() || elt.tagName() == tagName)
2464 return elt;
2465 }
2466 }
2467 return QDomElement();
2468}
2469
2480{
2481 return impl ? impl->lineNumber : -1;
2482}
2483
2494{
2495 return impl ? impl->columnNumber : -1;
2496}
2497
2498
2499/**************************************************************
2500 *
2501 * QDomNamedNodeMapPrivate
2502 *
2503 **************************************************************/
2504
2506 : ref(1)
2507 , parent(pimpl)
2508 , readonly(false)
2509 , appendToParent(false)
2510{
2511}
2512
2517
2519{
2520 std::unique_ptr<QDomNamedNodeMapPrivate> m(new QDomNamedNodeMapPrivate(pimpl));
2521 m->readonly = readonly;
2522 m->appendToParent = appendToParent;
2523
2524 auto it = map.constBegin();
2525 for (; it != map.constEnd(); ++it) {
2526 QDomNodePrivate *new_node = it.value()->cloneNode();
2527 new_node->setParent(pimpl);
2528 m->setNamedItem(new_node);
2529 }
2530
2531 // we are no longer interested in ownership
2532 m->ref.deref();
2533 return m.release();
2534}
2535
2537{
2538 // Dereference all of our children if we took references
2539 if (!appendToParent) {
2540 auto it = map.constBegin();
2541 for (; it != map.constEnd(); ++it)
2542 if (!it.value()->ref.deref())
2543 delete it.value();
2544 }
2545 map.clear();
2546}
2547
2549{
2550 auto it = map.find(name);
2551 return it == map.end() ? nullptr : it.value();
2552}
2553
2555{
2556 auto it = map.constBegin();
2558 for (; it != map.constEnd(); ++it) {
2559 n = it.value();
2560 if (!n->prefix.isNull()) {
2561 // node has a namespace
2562 if (n->namespaceURI == nsURI && n->name == localName)
2563 return n;
2564 }
2565 }
2566 return nullptr;
2567}
2568
2570{
2571 if (readonly || !arg)
2572 return nullptr;
2573
2574 if (appendToParent)
2575 return parent->appendChild(arg);
2576
2577 QDomNodePrivate *n = map.value(arg->nodeName());
2578 // We take a reference
2579 arg->ref.ref();
2580 map.insert(arg->nodeName(), arg);
2581 return n;
2582}
2583
2585{
2586 if (readonly || !arg)
2587 return nullptr;
2588
2589 if (appendToParent)
2590 return parent->appendChild(arg);
2591
2592 if (!arg->prefix.isNull()) {
2593 // node has a namespace
2594 QDomNodePrivate *n = namedItemNS(arg->namespaceURI, arg->name);
2595 // We take a reference
2596 arg->ref.ref();
2597 map.insert(arg->nodeName(), arg);
2598 return n;
2599 } else {
2600 // ### check the following code if it is ok
2601 return setNamedItem(arg);
2602 }
2603}
2604
2606{
2607 if (readonly)
2608 return nullptr;
2609
2611 if (p == nullptr)
2612 return nullptr;
2613 if (appendToParent)
2614 return parent->removeChild(p);
2615
2616 map.remove(p->nodeName());
2617 // We took a reference, so we have to free one here
2618 p->ref.deref();
2619 return p;
2620}
2621
2623{
2624 if (index >= length() || index < 0)
2625 return nullptr;
2626 return std::next(map.begin(), index).value();
2627}
2628
2630{
2631 return map.size();
2632}
2633
2635{
2636 return map.contains(name);
2637}
2638
2639bool QDomNamedNodeMapPrivate::containsNS(const QString& nsURI, const QString & localName) const
2640{
2641 return namedItemNS(nsURI, localName) != nullptr;
2642}
2643
2644/**************************************************************
2645 *
2646 * QDomNamedNodeMap
2647 *
2648 **************************************************************/
2649
2650#define IMPL static_cast<QDomNamedNodeMapPrivate *>(impl)
2651
2697
2702 : impl(namedNodeMap.impl)
2703{
2704 if (impl)
2705 impl->ref.ref();
2706}
2707
2709 : impl(pimpl)
2710{
2711 if (impl)
2712 impl->ref.ref();
2713}
2714
2719{
2720 if (other.impl)
2721 other.impl->ref.ref();
2722 if (impl && !impl->ref.deref())
2723 delete impl;
2724 impl = other.impl;
2725 return *this;
2726}
2727
2733{
2734 return impl == other.impl;
2735}
2736
2742{
2743 return !operator==(other);
2744}
2745
2750{
2751 if (impl && !impl->ref.deref())
2752 delete impl;
2753}
2754
2765{
2766 if (!impl)
2767 return QDomNode();
2768 return QDomNode(IMPL->namedItem(name));
2769}
2770
2782{
2783 if (!impl)
2784 return QDomNode();
2785 return QDomNode(IMPL->setNamedItem(static_cast<QDomNodePrivate *>(newNode.impl)));
2786}
2787
2798{
2799 if (!impl)
2800 return QDomNode();
2801 return QDomNode(IMPL->removeNamedItem(name));
2802}
2803
2813{
2814 if (!impl)
2815 return QDomNode();
2816 return QDomNode(IMPL->item(index));
2817}
2818
2828QDomNode QDomNamedNodeMap::namedItemNS(const QString& nsURI, const QString& localName) const
2829{
2830 if (!impl)
2831 return QDomNode();
2832 return QDomNode(IMPL->namedItemNS(nsURI, localName));
2833}
2834
2844{
2845 if (!impl)
2846 return QDomNode();
2847 return QDomNode(IMPL->setNamedItemNS(static_cast<QDomNodePrivate *>(newNode.impl)));
2848}
2849
2862{
2863 if (!impl)
2864 return QDomNode();
2865 QDomNodePrivate *n = IMPL->namedItemNS(nsURI, localName);
2866 if (!n)
2867 return QDomNode();
2868 return QDomNode(IMPL->removeNamedItem(n->name));
2869}
2870
2877{
2878 if (!impl)
2879 return 0;
2880 return IMPL->length();
2881}
2882
2911{
2912 if (!impl)
2913 return false;
2914 return IMPL->contains(name);
2915}
2916
2917#undef IMPL
2918
2919/**************************************************************
2920 *
2921 * QDomDocumentTypePrivate
2922 *
2923 **************************************************************/
2924
2930
2932 : QDomNodePrivate(n, deep)
2933{
2934 init();
2935 // Refill the maps with our new children
2937 while (p) {
2938 if (p->isEntity())
2939 // Don't use normal insert function since we would create infinite recursion
2940 entities->map.insert(p->nodeName(), p);
2941 if (p->isNotation())
2942 // Don't use normal insert function since we would create infinite recursion
2943 notations->map.insert(p->nodeName(), p);
2944 p = p->next;
2945 }
2946}
2947
2949{
2950 if (!entities->ref.deref())
2951 delete entities;
2952 if (!notations->ref.deref())
2953 delete notations;
2954}
2955
2957{
2959 QT_TRY {
2961 publicId.clear();
2962 systemId.clear();
2964
2967 } QT_CATCH(...) {
2968 delete entities;
2969 QT_RETHROW;
2970 }
2971}
2972
2974{
2975 QDomNodePrivate* p = new QDomDocumentTypePrivate(this, deep);
2976 // We are not interested in this node
2977 p->ref.deref();
2978 return p;
2979}
2980
2982{
2983 // Call the original implementation
2984 QDomNodePrivate* p = QDomNodePrivate::insertBefore(newChild, refChild);
2985 // Update the maps
2986 if (p && p->isEntity())
2987 entities->map.insert(p->nodeName(), p);
2988 else if (p && p->isNotation())
2989 notations->map.insert(p->nodeName(), p);
2990
2991 return p;
2992}
2993
2995{
2996 // Call the original implementation
2997 QDomNodePrivate* p = QDomNodePrivate::insertAfter(newChild, refChild);
2998 // Update the maps
2999 if (p && p->isEntity())
3000 entities->map.insert(p->nodeName(), p);
3001 else if (p && p->isNotation())
3002 notations->map.insert(p->nodeName(), p);
3003
3004 return p;
3005}
3006
3008{
3009 // Call the original implementation
3010 QDomNodePrivate* p = QDomNodePrivate::replaceChild(newChild, oldChild);
3011 // Update the maps
3012 if (p) {
3013 if (oldChild && oldChild->isEntity())
3014 entities->map.remove(oldChild->nodeName());
3015 else if (oldChild && oldChild->isNotation())
3016 notations->map.remove(oldChild->nodeName());
3017
3018 if (p->isEntity())
3019 entities->map.insert(p->nodeName(), p);
3020 else if (p->isNotation())
3021 notations->map.insert(p->nodeName(), p);
3022 }
3023
3024 return p;
3025}
3026
3028{
3029 // Call the original implementation
3031 // Update the maps
3032 if (p && p->isEntity())
3033 entities->map.remove(p->nodeName());
3034 else if (p && p->isNotation())
3036
3037 return p;
3038}
3039
3041{
3042 return insertAfter(newChild, nullptr);
3043}
3044
3046{
3047 QChar quote = data.indexOf(u'\'') == -1 ? u'\'' : u'"';
3048 return quote + data + quote;
3049}
3050
3051void QDomDocumentTypePrivate::save(QTextStream& s, int, int indent) const
3052{
3053 if (name.isEmpty())
3054 return;
3055
3056 s << "<!DOCTYPE " << name;
3057
3058 if (!publicId.isNull()) {
3059 s << " PUBLIC " << quotedValue(publicId);
3060 if (!systemId.isNull()) {
3061 s << ' ' << quotedValue(systemId);
3062 }
3063 } else if (!systemId.isNull()) {
3064 s << " SYSTEM " << quotedValue(systemId);
3065 }
3066
3067 if (entities->length()>0 || notations->length()>0) {
3068 s << " [" << Qt::endl;
3069
3070 auto it2 = notations->map.constBegin();
3071 for (; it2 != notations->map.constEnd(); ++it2)
3072 it2.value()->save(s, 0, indent);
3073
3074 auto it = entities->map.constBegin();
3075 for (; it != entities->map.constEnd(); ++it)
3076 it.value()->save(s, 0, indent);
3077
3078 s << ']';
3079 }
3080
3081 s << '>' << Qt::endl;
3082}
3083
3084/**************************************************************
3085 *
3086 * QDomDocumentType
3087 *
3088 **************************************************************/
3089
3090#define IMPL static_cast<QDomDocumentTypePrivate *>(impl)
3091
3117
3126 : QDomNode(documentType)
3127{
3128}
3129
3131 : QDomNode(pimpl)
3132{
3133}
3134
3150{
3151 if (!impl)
3152 return QString();
3153 return IMPL->nodeName();
3154}
3155
3160{
3161 if (!impl)
3162 return QDomNamedNodeMap();
3163 return QDomNamedNodeMap(IMPL->entities);
3164}
3165
3170{
3171 if (!impl)
3172 return QDomNamedNodeMap();
3173 return QDomNamedNodeMap(IMPL->notations);
3174}
3175
3183{
3184 if (!impl)
3185 return QString();
3186 return IMPL->publicId;
3187}
3188
3196{
3197 if (!impl)
3198 return QString();
3199 return IMPL->systemId;
3200}
3201
3209{
3210 if (!impl)
3211 return QString();
3212 return IMPL->internalSubset;
3213}
3214
3215/*
3216 Are these needed at all? The only difference when removing these
3217 two methods in all subclasses is that we'd get a different type
3218 for null nodes.
3219*/
3220
3229#undef IMPL
3230
3231/**************************************************************
3232 *
3233 * QDomDocumentFragmentPrivate
3234 *
3235 **************************************************************/
3236
3238 : QDomNodePrivate(doc, parent)
3239{
3240 name = u"#document-fragment"_s;
3241}
3242
3247
3249{
3251 // We are not interested in this node
3252 p->ref.deref();
3253 return p;
3254}
3255
3256/**************************************************************
3257 *
3258 * QDomDocumentFragment
3259 *
3260 **************************************************************/
3261
3293
3295 : QDomNode(n)
3296{
3297}
3298
3307 : QDomNode(documentFragment)
3308{
3309}
3310
3319
3328/**************************************************************
3329 *
3330 * QDomCharacterDataPrivate
3331 *
3332 **************************************************************/
3333
3335 const QString& data)
3336 : QDomNodePrivate(d, p)
3337{
3338 value = data;
3339 name = u"#character-data"_s;
3340}
3341
3346
3348{
3349 QDomNodePrivate* p = new QDomCharacterDataPrivate(this, deep);
3350 // We are not interested in this node
3351 p->ref.deref();
3352 return p;
3353}
3354
3356{
3357 return value.size();
3358}
3359
3360QString QDomCharacterDataPrivate::substringData(unsigned long offset, unsigned long n) const
3361{
3362 return value.mid(offset, n);
3363}
3364
3366{
3368}
3369
3370void QDomCharacterDataPrivate::deleteData(unsigned long offset, unsigned long n)
3371{
3372 value.remove(offset, n);
3373}
3374
3375void QDomCharacterDataPrivate::replaceData(unsigned long offset, unsigned long n, const QString& arg)
3376{
3378}
3379
3384
3385/**************************************************************
3386 *
3387 * QDomCharacterData
3388 *
3389 **************************************************************/
3390
3391#define IMPL static_cast<QDomCharacterDataPrivate *>(impl)
3392
3424
3433 : QDomNode(characterData)
3434{
3435}
3436
3438 : QDomNode(n)
3439{
3440}
3441
3450
3458{
3459 if (!impl)
3460 return QString();
3461 return impl->nodeValue();
3462}
3463
3468{
3469 if (impl)
3471}
3472
3477{
3478 if (impl)
3479 return IMPL->dataLength();
3480 return 0;
3481}
3482
3487{
3488 if (!impl)
3489 return QString();
3490 return IMPL->substringData(offset, count);
3491}
3492
3497{
3498 if (impl)
3499 IMPL->appendData(arg);
3500}
3501
3506{
3507 if (impl)
3508 IMPL->insertData(offset, arg);
3509}
3510
3514void QDomCharacterData::deleteData(unsigned long offset, unsigned long count)
3515{
3516 if (impl)
3517 IMPL->deleteData(offset, count);
3518}
3519
3524void QDomCharacterData::replaceData(unsigned long offset, unsigned long count, const QString& arg)
3525{
3526 if (impl)
3527 IMPL->replaceData(offset, count, arg);
3528}
3529
3536{
3537 if (!impl)
3538 return CharacterDataNode;
3539 return QDomNode::nodeType();
3540}
3541
3542#undef IMPL
3543
3544/**************************************************************
3545 *
3546 * QDomAttrPrivate
3547 *
3548 **************************************************************/
3549
3551 : QDomNodePrivate(d, parent)
3552{
3553 name = name_;
3554 m_specified = false;
3555}
3556
3558 : QDomNodePrivate(d, p)
3559{
3560 qt_split_namespace(prefix, name, qName, !nsURI.isNull());
3561 namespaceURI = nsURI;
3563 m_specified = false;
3564}
3565
3567 : QDomNodePrivate(n, deep)
3568{
3569 m_specified = n->specified();
3570}
3571
3573{
3574 value = v;
3575 QDomTextPrivate *t = new QDomTextPrivate(nullptr, this, v);
3576 // keep the refcount balanced: appendChild() does a ref anyway.
3577 t->ref.deref();
3578 if (first) {
3579 auto removed = removeChild(first);
3580 if (removed && !removed->ref.loadRelaxed()) // removeChild() already deref()ed
3581 delete removed;
3582 }
3583 appendChild(t);
3584}
3585
3587{
3588 QDomNodePrivate* p = new QDomAttrPrivate(this, deep);
3589 // We are not interested in this node
3590 p->ref.deref();
3591 return p;
3592}
3593
3595{
3596 return m_specified;
3597}
3598
3599/* \internal
3600 Encode & escape \a str. Yes, it makes no sense to return a QString,
3601 but is so for legacy reasons.
3602
3603 Remember that content produced should be able to roundtrip with 2.11 End-of-Line Handling
3604 and 3.3.3 Attribute-Value Normalization.
3605
3606 If \a performAVN is true, characters will be escaped to survive Attribute Value Normalization.
3607 If \a encodeEOLs is true, characters will be escaped to survive End-of-Line Handling.
3608*/
3610 const bool encodeQuotes = true,
3611 const bool performAVN = false,
3612 const bool encodeEOLs = false)
3613{
3614 QString retval(str);
3615 int len = retval.size();
3616 int i = 0;
3617
3618 while (i < len) {
3619 const QChar ati(retval.at(i));
3620
3621 if (ati == u'<') {
3622 retval.replace(i, 1, "&lt;"_L1);
3623 len += 3;
3624 i += 4;
3625 } else if (encodeQuotes && (ati == u'"')) {
3626 retval.replace(i, 1, "&quot;"_L1);
3627 len += 5;
3628 i += 6;
3629 } else if (ati == u'&') {
3630 retval.replace(i, 1, "&amp;"_L1);
3631 len += 4;
3632 i += 5;
3633 } else if (ati == u'>' && i >= 2 && retval[i - 1] == u']' && retval[i - 2] == u']') {
3634 retval.replace(i, 1, "&gt;"_L1);
3635 len += 3;
3636 i += 4;
3637 } else if (performAVN &&
3638 (ati == QChar(0xA) ||
3639 ati == QChar(0xD) ||
3640 ati == QChar(0x9))) {
3641 const QString replacement(u"&#x"_s + QString::number(ati.unicode(), 16) + u';');
3642 retval.replace(i, 1, replacement);
3643 i += replacement.size();
3644 len += replacement.size() - 1;
3645 } else if (encodeEOLs && ati == QChar(0xD)) {
3646 retval.replace(i, 1, "&#xd;"_L1); // Replace a single 0xD with a ref for 0xD
3647 len += 4;
3648 i += 5;
3649 } else {
3650 ++i;
3651 }
3652 }
3653
3654 return retval;
3655}
3656
3658{
3659 if (namespaceURI.isNull()) {
3660 s << name << "=\"" << encodeText(value, true, true) << '\"';
3661 } else {
3662 s << prefix << ':' << name << "=\"" << encodeText(value, true, true) << '\"';
3663 /* This is a fix for 138243, as good as it gets.
3664 *
3665 * QDomElementPrivate::save() output a namespace declaration if
3666 * the element is in a namespace, no matter what. This function do as well, meaning
3667 * that we get two identical namespace declaration if we don't have the if-
3668 * statement below.
3669 *
3670 * This doesn't work when the parent element has the same prefix as us but
3671 * a different namespace. However, this can only occur by the user modifying the element,
3672 * and we don't do fixups by that anyway, and hence it's the user responsibility to not
3673 * arrive in those situations. */
3674 if (!ownerNode ||
3675 ownerNode->prefix != prefix) {
3676 s << " xmlns:" << prefix << "=\"" << encodeText(namespaceURI, true, true) << '\"';
3677 }
3678 }
3679}
3680
3681/**************************************************************
3682 *
3683 * QDomAttr
3684 *
3685 **************************************************************/
3686
3687#define IMPL static_cast<QDomAttrPrivate *>(impl)
3688
3730
3739 : QDomNode(attr)
3740{
3741}
3742
3744 : QDomNode(n)
3745{
3746}
3747
3755QDomAttr &QDomAttr::operator=(const QDomAttr &other) = default;
3756
3761{
3762 if (!impl)
3763 return QString();
3764 return impl->nodeName();
3765}
3766
3774{
3775 if (!impl)
3776 return false;
3777 return IMPL->specified();
3778}
3779
3786{
3787 Q_ASSERT(impl->parent());
3788 if (!impl->parent()->isElement())
3789 return QDomElement();
3790 return QDomElement(static_cast<QDomElementPrivate *>(impl->parent()));
3791}
3792
3800{
3801 if (!impl)
3802 return QString();
3803 return impl->nodeValue();
3804}
3805
3812{
3813 if (!impl)
3814 return;
3816 IMPL->m_specified = true;
3817}
3818
3825#undef IMPL
3826
3827/**************************************************************
3828 *
3829 * QDomElementPrivate
3830 *
3831 **************************************************************/
3832
3834 const QString& tagname)
3835 : QDomNodePrivate(d, p)
3836{
3837 name = tagname;
3838 m_attr = new QDomNamedNodeMapPrivate(this);
3839}
3840
3842 const QString& nsURI, const QString& qName)
3843 : QDomNodePrivate(d, p)
3844{
3845 qt_split_namespace(prefix, name, qName, !nsURI.isNull());
3846 namespaceURI = nsURI;
3848 m_attr = new QDomNamedNodeMapPrivate(this);
3849}
3850
3852 QDomNodePrivate(n, deep)
3853{
3854 m_attr = n->m_attr->clone(this);
3855 // Reference is down to 0, so we set it to 1 here.
3856 m_attr->ref.ref();
3857}
3858
3860{
3861 if (!m_attr->ref.deref())
3862 delete m_attr;
3863}
3864
3866{
3867 QDomNodePrivate* p = new QDomElementPrivate(this, deep);
3868 // We are not interested in this node
3869 p->ref.deref();
3870 return p;
3871}
3872
3873QString QDomElementPrivate::attribute(const QString& name_, const QString& defValue) const
3874{
3875 QDomNodePrivate* n = m_attr->namedItem(name_);
3876 if (!n)
3877 return defValue;
3878
3879 return n->nodeValue();
3880}
3881
3882QString QDomElementPrivate::attributeNS(const QString& nsURI, const QString& localName, const QString& defValue) const
3883{
3884 QDomNodePrivate* n = m_attr->namedItemNS(nsURI, localName);
3885 if (!n)
3886 return defValue;
3887
3888 return n->nodeValue();
3889}
3890
3891void QDomElementPrivate::setAttribute(const QString& aname, const QString& newValue)
3892{
3893 QDomNodePrivate* n = m_attr->namedItem(aname);
3894 if (!n) {
3895 n = new QDomAttrPrivate(ownerDocument(), this, aname);
3896 n->setNodeValue(newValue);
3897
3898 // Referencing is done by the map, so we set the reference counter back
3899 // to 0 here. This is ok since we created the QDomAttrPrivate.
3900 n->ref.deref();
3902 } else {
3903 n->setNodeValue(newValue);
3904 }
3905}
3906
3907void QDomElementPrivate::setAttributeNS(const QString& nsURI, const QString& qName, const QString& newValue)
3908{
3909 QString prefix, localName;
3910 qt_split_namespace(prefix, localName, qName, true);
3911 QDomNodePrivate* n = m_attr->namedItemNS(nsURI, localName);
3912 if (!n) {
3913 n = new QDomAttrPrivate(ownerDocument(), this, nsURI, qName);
3914 n->setNodeValue(newValue);
3915
3916 // Referencing is done by the map, so we set the reference counter back
3917 // to 0 here. This is ok since we created the QDomAttrPrivate.
3918 n->ref.deref();
3920 } else {
3921 n->setNodeValue(newValue);
3922 n->prefix = prefix;
3923 }
3924}
3925
3927{
3929 if (p && p->ref.loadRelaxed() == 0)
3930 delete p;
3931}
3932
3934{
3935 return static_cast<QDomAttrPrivate *>(m_attr->namedItem(aname));
3936}
3937
3939{
3940 return static_cast<QDomAttrPrivate *>(m_attr->namedItemNS(nsURI, localName));
3941}
3942
3944{
3945 QDomNodePrivate* n = m_attr->namedItem(newAttr->nodeName());
3946
3947 // Referencing is done by the maps
3948 m_attr->setNamedItem(newAttr);
3949
3950 newAttr->setParent(this);
3951
3952 return static_cast<QDomAttrPrivate *>(n);
3953}
3954
3956{
3957 QDomNodePrivate* n = nullptr;
3958 if (!newAttr->prefix.isNull())
3959 n = m_attr->namedItemNS(newAttr->namespaceURI, newAttr->name);
3960
3961 // Referencing is done by the maps
3962 m_attr->setNamedItem(newAttr);
3963
3964 return static_cast<QDomAttrPrivate *>(n);
3965}
3966
3968{
3969 return static_cast<QDomAttrPrivate *>(m_attr->removeNamedItem(oldAttr->nodeName()));
3970}
3971
3973{
3974 return m_attr->contains(aname);
3975}
3976
3977bool QDomElementPrivate::hasAttributeNS(const QString& nsURI, const QString& localName)
3978{
3979 return m_attr->containsNS(nsURI, localName);
3980}
3981
3983{
3984 QString t(u""_s);
3985
3987 while (p) {
3988 if (p->isText() || p->isCDATASection())
3989 t += p->nodeValue();
3990 else if (p->isElement())
3991 t += static_cast<QDomElementPrivate *>(p)->text();
3992 p = p->next;
3993 }
3994
3995 return t;
3996}
3997
3998void QDomElementPrivate::save(QTextStream& s, int depth, int indent) const
3999{
4000 if (!(prev && prev->isText()))
4001 s << QString(indent < 1 ? 0 : depth * indent, u' ');
4002
4003 QString qName(name);
4004 QString nsDecl(u""_s);
4005 if (!namespaceURI.isNull()) {
4016 if (prefix.isEmpty()) {
4017 nsDecl = u" xmlns"_s;
4018 } else {
4019 qName = prefix + u':' + name;
4020 nsDecl = u" xmlns:"_s + prefix;
4021 }
4022 nsDecl += u"=\""_s + encodeText(namespaceURI) + u'\"';
4023 }
4024 s << '<' << qName << nsDecl;
4025
4026
4027 /* Write out attributes. */
4028 if (!m_attr->map.isEmpty()) {
4029 /*
4030 * To ensure that we always output attributes in a consistent
4031 * order, sort the attributes before writing them into the
4032 * stream. (Note that the order may be different than the one
4033 * that e.g. we've read from a file, or the program order in
4034 * which these attributes have been populated. We just want to
4035 * guarantee reproducibile outputs.)
4036 */
4037 struct SavedAttribute {
4038 QString prefix;
4039 QString name;
4040 QString encodedValue;
4041 };
4042
4043 /* Gather all the attributes to save. */
4044 QVarLengthArray<SavedAttribute, 8> attributesToSave;
4045 attributesToSave.reserve(m_attr->map.size());
4046
4047 QDuplicateTracker<QString> outputtedPrefixes;
4048 for (const auto &[key, value] : std::as_const(m_attr->map).asKeyValueRange()) {
4049 Q_UNUSED(key); /* We extract the attribute name from the value. */
4050 bool mayNeedXmlNS = false;
4051
4052 SavedAttribute attr;
4053 attr.name = value->name;
4054 attr.encodedValue = encodeText(value->value, true, true);
4055 if (!value->namespaceURI.isNull()) {
4056 attr.prefix = value->prefix;
4057 mayNeedXmlNS = true;
4058 }
4059
4060 attributesToSave.push_back(std::move(attr));
4061
4062 /*
4063 * This is a fix for 138243, as good as it gets.
4064 *
4065 * QDomElementPrivate::save() output a namespace
4066 * declaration if the element is in a namespace, no matter
4067 * what. This function do as well, meaning that we get two
4068 * identical namespace declaration if we don't have the if-
4069 * statement below.
4070 *
4071 * This doesn't work when the parent element has the same
4072 * prefix as us but a different namespace. However, this
4073 * can only occur by the user modifying the element, and we
4074 * don't do fixups by that anyway, and hence it's the user
4075 * responsibility to avoid those situations.
4076 */
4077
4078 if (mayNeedXmlNS
4079 && ((!value->ownerNode || value->ownerNode->prefix != value->prefix)
4080 && !outputtedPrefixes.hasSeen(value->prefix)))
4081 {
4082 SavedAttribute nsAttr;
4083 nsAttr.prefix = QStringLiteral("xmlns");
4084 nsAttr.name = value->prefix;
4085 nsAttr.encodedValue = encodeText(value->namespaceURI, true, true);
4086 attributesToSave.push_back(std::move(nsAttr));
4087 }
4088 }
4089
4090 /* Sort the attributes by prefix and name. */
4091 const auto savedAttributeComparator = [](const SavedAttribute &lhs, const SavedAttribute &rhs)
4092 {
4093 const int cmp = QString::compare(lhs.prefix, rhs.prefix);
4094 return (cmp < 0) || ((cmp == 0) && (lhs.name < rhs.name));
4095 };
4096
4097 std::sort(attributesToSave.begin(), attributesToSave.end(), savedAttributeComparator);
4098
4099 /* Actually stream the sorted attributes. */
4100 for (const auto &attr : attributesToSave) {
4101 s << ' ';
4102 if (!attr.prefix.isEmpty())
4103 s << attr.prefix << ':';
4104 s << attr.name << "=\"" << attr.encodedValue << '\"';
4105 }
4106 }
4107
4108 if (last) {
4109 // has child nodes
4110 if (first->isText())
4111 s << '>';
4112 else {
4113 s << '>';
4114
4115 /* -1 disables new lines. */
4116 if (indent != -1)
4117 s << Qt::endl;
4118 }
4119 QDomNodePrivate::save(s, depth + 1, indent); if (!last->isText())
4120 s << QString(indent < 1 ? 0 : depth * indent, u' ');
4121
4122 s << "</" << qName << '>';
4123 } else {
4124 s << "/>";
4125 }
4126 if (!(next && next->isText())) {
4127 /* -1 disables new lines. */
4128 if (indent != -1)
4129 s << Qt::endl;
4130 }
4131}
4132
4133/**************************************************************
4134 *
4135 * QDomElement
4136 *
4137 **************************************************************/
4138
4139#define IMPL static_cast<QDomElementPrivate *>(impl)
4140
4198 : QDomNode()
4199{
4200}
4201
4210 : QDomNode(element)
4211{
4212}
4213
4215 : QDomNode(n)
4216{
4217}
4218
4227
4240{
4241 if (impl)
4242 impl->name = name;
4243}
4244
4255{
4256 if (!impl)
4257 return QString();
4258 return impl->nodeName();
4259}
4260
4261
4268{
4269 if (!impl)
4270 return QDomNamedNodeMap();
4271 return QDomNamedNodeMap(IMPL->attributes());
4272}
4273
4280QString QDomElement::attribute(const QString& name, const QString& defValue) const
4281{
4282 if (!impl)
4283 return defValue;
4284 return IMPL->attribute(name, defValue);
4285}
4286
4295{
4296 if (!impl)
4297 return;
4298 IMPL->setAttribute(name, value);
4299}
4300
4321{
4322 if (!impl)
4323 return;
4324 QString x;
4325 x.setNum(value);
4326 IMPL->setAttribute(name, x);
4327}
4328
4335{
4336 if (!impl)
4337 return;
4338 QString x;
4339 x.setNum(value);
4340 IMPL->setAttribute(name, x);
4341}
4342
4349{
4350 if (!impl)
4351 return;
4352 QString x;
4353 x.setNum(value, 'g', 8);
4354 IMPL->setAttribute(name, x);
4355}
4356
4363{
4364 if (!impl)
4365 return;
4366 QString x;
4367 x.setNum(value, 'g', 17);
4368 IMPL->setAttribute(name, x);
4369}
4370
4377{
4378 if (!impl)
4379 return;
4380 IMPL->removeAttribute(name);
4381}
4382
4391{
4392 if (!impl)
4393 return QDomAttr();
4394 return QDomAttr(IMPL->attributeNode(name));
4395}
4396
4408{
4409 if (!impl)
4410 return QDomAttr();
4411 return QDomAttr(IMPL->setAttributeNode(static_cast<QDomAttrPrivate *>(newAttr.impl)));
4412}
4413
4420{
4421 if (!impl)
4422 return QDomAttr(); // ### should this return oldAttr?
4423 return QDomAttr(IMPL->removeAttributeNode(static_cast<QDomAttrPrivate *>(oldAttr.impl)));
4424}
4425
4436{
4437 return QDomNodeList(new QDomNodeListPrivate(impl, tagname));
4438}
4439
4453{
4454 if (!impl)
4455 return false;
4456 return IMPL->hasAttribute(name);
4457}
4458
4466QString QDomElement::attributeNS(const QString& nsURI, const QString& localName, const QString& defValue) const
4467{
4468 if (!impl)
4469 return defValue;
4470 return IMPL->attributeNS(nsURI, localName, defValue);
4471}
4472
4485void QDomElement::setAttributeNS(const QString& nsURI, const QString& qName, const QString& value)
4486{
4487 if (!impl)
4488 return;
4489 IMPL->setAttributeNS(nsURI, qName, value);
4490}
4491
4508{
4509 if (!impl)
4510 return;
4511 QString x;
4512 x.setNum(value);
4513 IMPL->setAttributeNS(nsURI, qName, x);
4514}
4515
4520{
4521 if (!impl)
4522 return;
4523 QString x;
4524 x.setNum(value);
4525 IMPL->setAttributeNS(nsURI, qName, x);
4526}
4527
4531void QDomElement::setAttributeNS(const QString& nsURI, const QString& qName, double value)
4532{
4533 if (!impl)
4534 return;
4535 QString x;
4536 x.setNum(value, 'g', 17);
4537 IMPL->setAttributeNS(nsURI, qName, x);
4538}
4539
4546void QDomElement::removeAttributeNS(const QString& nsURI, const QString& localName)
4547{
4548 if (!impl)
4549 return;
4550 QDomNodePrivate *n = IMPL->attributeNodeNS(nsURI, localName);
4551 if (!n)
4552 return;
4553 IMPL->removeAttribute(n->nodeName());
4554}
4555
4565{
4566 if (!impl)
4567 return QDomAttr();
4568 return QDomAttr(IMPL->attributeNodeNS(nsURI, localName));
4569}
4570
4582{
4583 if (!impl)
4584 return QDomAttr();
4585 return QDomAttr(IMPL->setAttributeNodeNS(static_cast<QDomAttrPrivate *>(newAttr.impl)));
4586}
4587
4598{
4599 return QDomNodeList(new QDomNodeListPrivate(impl, nsURI, localName));
4600}
4601
4607bool QDomElement::hasAttributeNS(const QString& nsURI, const QString& localName) const
4608{
4609 if (!impl)
4610 return false;
4611 return IMPL->hasAttributeNS(nsURI, localName);
4612}
4613
4629{
4630 if (!impl)
4631 return QString();
4632 return IMPL->text();
4633}
4634
4635#undef IMPL
4636
4637/**************************************************************
4638 *
4639 * QDomTextPrivate
4640 *
4641 **************************************************************/
4642
4644 : QDomCharacterDataPrivate(d, parent, val)
4645{
4646 name = u"#text"_s;
4647}
4648
4653
4655{
4656 QDomNodePrivate* p = new QDomTextPrivate(this, deep);
4657 // We are not interested in this node
4658 p->ref.deref();
4659 return p;
4660}
4661
4663{
4664 if (!parent()) {
4665 qWarning("QDomText::splitText The node has no parent. So I cannot split");
4666 return nullptr;
4667 }
4668
4669 QDomTextPrivate* t = new QDomTextPrivate(ownerDocument(), nullptr, value.mid(offset));
4670 value.truncate(offset);
4671
4672 parent()->insertAfter(t, this);
4673 Q_ASSERT(t->ref.loadRelaxed() == 2);
4674
4675 // We are not interested in this node
4676 t->ref.deref();
4677
4678 return t;
4679}
4680
4682{
4683 QDomTextPrivate *that = const_cast<QDomTextPrivate*>(this);
4684 s << encodeText(value, !(that->parent() && that->parent()->isElement()), false, true);
4685}
4686
4687/**************************************************************
4688 *
4689 * QDomText
4690 *
4691 **************************************************************/
4692
4693#define IMPL static_cast<QDomTextPrivate *>(impl)
4694
4722
4734
4737{
4738}
4739
4747QDomText &QDomText::operator=(const QDomText &other) = default;
4748
4766{
4767 if (!impl)
4768 return QDomText();
4769 return QDomText(IMPL->splitText(offset));
4770}
4771
4772#undef IMPL
4773
4774/**************************************************************
4775 *
4776 * QDomCommentPrivate
4777 *
4778 **************************************************************/
4779
4781 : QDomCharacterDataPrivate(d, parent, val)
4782{
4783 name = u"#comment"_s;
4784}
4785
4790
4791
4793{
4794 QDomNodePrivate* p = new QDomCommentPrivate(this, deep);
4795 // We are not interested in this node
4796 p->ref.deref();
4797 return p;
4798}
4799
4800void QDomCommentPrivate::save(QTextStream& s, int depth, int indent) const
4801{
4802 /* We don't output whitespace if we would pollute a text node. */
4803 if (!(prev && prev->isText()))
4804 s << QString(indent < 1 ? 0 : depth * indent, u' ');
4805
4806 s << "<!--" << value;
4807 if (value.endsWith(u'-'))
4808 s << ' '; // Ensures that XML comment doesn't end with --->
4809 s << "-->";
4810
4811 if (!(next && next->isText()))
4812 s << Qt::endl;
4813}
4814
4815/**************************************************************
4816 *
4817 * QDomComment
4818 *
4819 **************************************************************/
4820
4850
4859 : QDomCharacterData(comment)
4860{
4861}
4862
4865{
4866}
4867
4876
4883/**************************************************************
4884 *
4885 * QDomCDATASectionPrivate
4886 *
4887 **************************************************************/
4888
4890 const QString& val)
4891 : QDomTextPrivate(d, parent, val)
4892{
4893 name = u"#cdata-section"_s;
4894}
4895
4900
4902{
4903 QDomNodePrivate* p = new QDomCDATASectionPrivate(this, deep);
4904 // We are not interested in this node
4905 p->ref.deref();
4906 return p;
4907}
4908
4910{
4911 // ### How do we escape "]]>" ?
4912 // "]]>" is not allowed; so there should be none in value anyway
4913 s << "<![CDATA[" << value << "]]>";
4914}
4915
4916/**************************************************************
4917 *
4918 * QDomCDATASection
4919 *
4920 **************************************************************/
4921
4955
4964 : QDomText(cdataSection)
4965{
4966}
4967
4969 : QDomText(n)
4970{
4971}
4972
4981
4988/**************************************************************
4989 *
4990 * QDomNotationPrivate
4991 *
4992 **************************************************************/
4993
4995 const QString& aname,
4996 const QString& pub, const QString& sys)
4997 : QDomNodePrivate(d, parent)
4998{
4999 name = aname;
5000 m_pub = pub;
5001 m_sys = sys;
5002}
5003
5005 : QDomNodePrivate(n, deep)
5006{
5007 m_sys = n->m_sys;
5008 m_pub = n->m_pub;
5009}
5010
5012{
5013 QDomNodePrivate* p = new QDomNotationPrivate(this, deep);
5014 // We are not interested in this node
5015 p->ref.deref();
5016 return p;
5017}
5018
5020{
5021 s << "<!NOTATION " << name << ' ';
5022 if (!m_pub.isNull()) {
5023 s << "PUBLIC " << quotedValue(m_pub);
5024 if (!m_sys.isNull())
5025 s << ' ' << quotedValue(m_sys);
5026 } else {
5027 s << "SYSTEM " << quotedValue(m_sys);
5028 }
5029 s << '>' << Qt::endl;
5030}
5031
5032/**************************************************************
5033 *
5034 * QDomNotation
5035 *
5036 **************************************************************/
5037
5038#define IMPL static_cast<QDomNotationPrivate *>(impl)
5039
5076
5085 : QDomNode(notation)
5086{
5087}
5088
5090 : QDomNode(n)
5091{
5092}
5093
5102
5113{
5114 if (!impl)
5115 return QString();
5116 return IMPL->m_pub;
5117}
5118
5123{
5124 if (!impl)
5125 return QString();
5126 return IMPL->m_sys;
5127}
5128
5129#undef IMPL
5130
5131/**************************************************************
5132 *
5133 * QDomEntityPrivate
5134 *
5135 **************************************************************/
5136
5138 const QString& aname,
5139 const QString& pub, const QString& sys, const QString& notation)
5140 : QDomNodePrivate(d, parent)
5141{
5142 name = aname;
5143 m_pub = pub;
5144 m_sys = sys;
5145 m_notationName = notation;
5146}
5147
5149 : QDomNodePrivate(n, deep)
5150{
5151 m_sys = n->m_sys;
5152 m_pub = n->m_pub;
5153 m_notationName = n->m_notationName;
5154}
5155
5157{
5158 QDomNodePrivate* p = new QDomEntityPrivate(this, deep);
5159 // We are not interested in this node
5160 p->ref.deref();
5161 return p;
5162}
5163
5164/*
5165 Encode an entity value upon saving.
5166*/
5168{
5169 QByteArray tmp(str);
5170 int len = tmp.size();
5171 int i = 0;
5172 const char* d = tmp.constData();
5173 while (i < len) {
5174 if (d[i] == '%'){
5175 tmp.replace(i, 1, "&#60;");
5176 d = tmp.constData();
5177 len += 4;
5178 i += 5;
5179 }
5180 else if (d[i] == '"') {
5181 tmp.replace(i, 1, "&#34;");
5182 d = tmp.constData();
5183 len += 4;
5184 i += 5;
5185 } else if (d[i] == '&' && i + 1 < len && d[i+1] == '#') {
5186 // Don't encode &lt; or &quot; or &custom;.
5187 // Only encode character references
5188 tmp.replace(i, 1, "&#38;");
5189 d = tmp.constData();
5190 len += 4;
5191 i += 5;
5192 } else {
5193 ++i;
5194 }
5195 }
5196
5197 return tmp;
5198}
5199
5201{
5202 QString _name = name;
5203 if (_name.startsWith(u'%'))
5204 _name = u"% "_s + _name.mid(1);
5205
5206 if (m_sys.isNull() && m_pub.isNull()) {
5207 s << "<!ENTITY " << _name << " \"" << encodeEntity(value.toUtf8()) << "\">" << Qt::endl;
5208 } else {
5209 s << "<!ENTITY " << _name << ' ';
5210 if (m_pub.isNull()) {
5211 s << "SYSTEM " << quotedValue(m_sys);
5212 } else {
5213 s << "PUBLIC " << quotedValue(m_pub) << ' ' << quotedValue(m_sys);
5214 }
5215 if (! m_notationName.isNull()) {
5216 s << " NDATA " << m_notationName;
5217 }
5218 s << '>' << Qt::endl;
5219 }
5220}
5221
5222/**************************************************************
5223 *
5224 * QDomEntity
5225 *
5226 **************************************************************/
5227
5228#define IMPL static_cast<QDomEntityPrivate *>(impl)
5229
5266 : QDomNode()
5267{
5268}
5269
5270
5279 : QDomNode(entity)
5280{
5281}
5282
5284 : QDomNode(n)
5285{
5286}
5287
5296
5308{
5309 if (!impl)
5310 return QString();
5311 return IMPL->m_pub;
5312}
5313
5319{
5320 if (!impl)
5321 return QString();
5322 return IMPL->m_sys;
5323}
5324
5331{
5332 if (!impl)
5333 return QString();
5334 return IMPL->m_notationName;
5335}
5336
5337#undef IMPL
5338
5339/**************************************************************
5340 *
5341 * QDomEntityReferencePrivate
5342 *
5343 **************************************************************/
5344
5350
5355
5357{
5358 QDomNodePrivate* p = new QDomEntityReferencePrivate(this, deep);
5359 // We are not interested in this node
5360 p->ref.deref();
5361 return p;
5362}
5363
5365{
5366 s << '&' << name << ';';
5367}
5368
5369/**************************************************************
5370 *
5371 * QDomEntityReference
5372 *
5373 **************************************************************/
5374
5419
5428 : QDomNode(entityReference)
5429{
5430}
5431
5433 : QDomNode(n)
5434{
5435}
5436
5445
5452/**************************************************************
5453 *
5454 * QDomProcessingInstructionPrivate
5455 *
5456 **************************************************************/
5457
5465
5470
5471
5473{
5475 // We are not interested in this node
5476 p->ref.deref();
5477 return p;
5478}
5479
5481{
5482 s << "<?" << name << ' ' << value << "?>" << Qt::endl;
5483}
5484
5485/**************************************************************
5486 *
5487 * QDomProcessingInstruction
5488 *
5489 **************************************************************/
5490
5533
5542 : QDomNode(processingInstruction)
5543{
5544}
5545
5547 : QDomNode(n)
5548{
5549}
5550
5560
5573{
5574 if (!impl)
5575 return QString();
5576 return impl->nodeName();
5577}
5578
5585{
5586 if (!impl)
5587 return QString();
5588 return impl->nodeValue();
5589}
5590
5597{
5598 if (impl)
5600}
5601
5602/**************************************************************
5603 *
5604 * QDomDocumentPrivate
5605 *
5606 **************************************************************/
5607
5610 impl(new QDomImplementationPrivate),
5611 nodeListTime(1)
5612{
5613 type = new QDomDocumentTypePrivate(this, this);
5614 type->ref.deref();
5615
5616 name = u"#document"_s;
5617}
5618
5621 impl(new QDomImplementationPrivate),
5622 nodeListTime(1)
5623{
5624 type = new QDomDocumentTypePrivate(this, this);
5625 type->ref.deref();
5626 type->name = aname;
5627
5628 name = u"#document"_s;
5629}
5630
5633 impl(new QDomImplementationPrivate),
5634 nodeListTime(1)
5635{
5636 if (dt != nullptr) {
5637 type = dt;
5638 } else {
5639 type = new QDomDocumentTypePrivate(this, this);
5640 type->ref.deref();
5641 }
5642
5643 name = u"#document"_s;
5644}
5645
5647 : QDomNodePrivate(n, deep),
5648 impl(n->impl->clone()),
5649 nodeListTime(1)
5650{
5651 type = static_cast<QDomDocumentTypePrivate*>(n->type->cloneNode());
5652 type->setParent(this);
5653}
5654
5658
5660{
5661 impl.reset();
5662 type.reset();
5664}
5665
5667 QDomDocument::ParseOptions options)
5668{
5669 clear();
5671 type = new QDomDocumentTypePrivate(this, this);
5672 type->ref.deref();
5673
5674 if (!reader) {
5675 const auto error = u"Failed to set content, XML reader is not initialized"_s;
5676 qWarning("%s", qPrintable(error));
5677 return { error };
5678 }
5679
5680 QDomParser domParser(this, reader, options);
5681
5682 if (!domParser.parse())
5683 return domParser.result();
5684 return {};
5685}
5686
5688{
5689 QDomNodePrivate *p = new QDomDocumentPrivate(this, deep);
5690 // We are not interested in this node
5691 p->ref.deref();
5692 return p;
5693}
5694
5696{
5698 while (p && !p->isElement())
5699 p = p->next;
5700
5701 return static_cast<QDomElementPrivate *>(p);
5702}
5703
5705{
5706 bool ok;
5707 QString fixedName = fixedXmlName(tagName, &ok);
5708 if (!ok)
5709 return nullptr;
5710
5711 QDomElementPrivate *e = new QDomElementPrivate(this, nullptr, fixedName);
5712 e->ref.deref();
5713 return e;
5714}
5715
5717{
5718 bool ok;
5719 QString fixedName = fixedXmlName(qName, &ok, true);
5720 if (!ok)
5721 return nullptr;
5722
5723 QDomElementPrivate *e = new QDomElementPrivate(this, nullptr, nsURI, fixedName);
5724 e->ref.deref();
5725 return e;
5726}
5727
5734
5736{
5737 bool ok;
5738 QString fixedData = fixedCharData(data, &ok);
5739 if (!ok)
5740 return nullptr;
5741
5742 QDomTextPrivate *t = new QDomTextPrivate(this, nullptr, fixedData);
5743 t->ref.deref();
5744 return t;
5745}
5746
5748{
5749 bool ok;
5750 QString fixedData = fixedComment(data, &ok);
5751 if (!ok)
5752 return nullptr;
5753
5754 QDomCommentPrivate *c = new QDomCommentPrivate(this, nullptr, fixedData);
5755 c->ref.deref();
5756 return c;
5757}
5758
5760{
5761 bool ok;
5762 QString fixedData = fixedCDataSection(data, &ok);
5763 if (!ok)
5764 return nullptr;
5765
5766 QDomCDATASectionPrivate *c = new QDomCDATASectionPrivate(this, nullptr, fixedData);
5767 c->ref.deref();
5768 return c;
5769}
5770
5772 const QString &data)
5773{
5774 bool ok;
5775 QString fixedData = fixedPIData(data, &ok);
5776 if (!ok)
5777 return nullptr;
5778 // [17] PITarget ::= Name - (('X' | 'x') ('M' | 'm') ('L' | 'l'))
5779 QString fixedTarget = fixedXmlName(target, &ok);
5780 if (!ok)
5781 return nullptr;
5782
5783 QDomProcessingInstructionPrivate *p = new QDomProcessingInstructionPrivate(this, nullptr, fixedTarget, fixedData);
5784 p->ref.deref();
5785 return p;
5786}
5788{
5789 bool ok;
5790 QString fixedName = fixedXmlName(aname, &ok);
5791 if (!ok)
5792 return nullptr;
5793
5794 QDomAttrPrivate *a = new QDomAttrPrivate(this, nullptr, fixedName);
5795 a->ref.deref();
5796 return a;
5797}
5798
5800{
5801 bool ok;
5802 QString fixedName = fixedXmlName(qName, &ok, true);
5803 if (!ok)
5804 return nullptr;
5805
5806 QDomAttrPrivate *a = new QDomAttrPrivate(this, nullptr, nsURI, fixedName);
5807 a->ref.deref();
5808 return a;
5809}
5810
5812{
5813 bool ok;
5814 QString fixedName = fixedXmlName(aname, &ok);
5815 if (!ok)
5816 return nullptr;
5817
5818 QDomEntityReferencePrivate *e = new QDomEntityReferencePrivate(this, nullptr, fixedName);
5819 e->ref.deref();
5820 return e;
5821}
5822
5824{
5825 QDomNodePrivate *node = nullptr;
5826 switch (importedNode->nodeType()) {
5828 node = new QDomAttrPrivate(static_cast<QDomAttrPrivate *>(importedNode), true);
5829 break;
5831 node = new QDomDocumentFragmentPrivate(
5832 static_cast<QDomDocumentFragmentPrivate *>(importedNode), deep);
5833 break;
5835 node = new QDomElementPrivate(static_cast<QDomElementPrivate *>(importedNode), deep);
5836 break;
5838 node = new QDomEntityPrivate(static_cast<QDomEntityPrivate *>(importedNode), deep);
5839 break;
5841 node = new QDomEntityReferencePrivate(
5842 static_cast<QDomEntityReferencePrivate *>(importedNode), false);
5843 break;
5845 node = new QDomNotationPrivate(static_cast<QDomNotationPrivate *>(importedNode), deep);
5846 break;
5849 static_cast<QDomProcessingInstructionPrivate *>(importedNode), deep);
5850 break;
5851 case QDomNode::TextNode:
5852 node = new QDomTextPrivate(static_cast<QDomTextPrivate *>(importedNode), deep);
5853 break;
5855 node = new QDomCDATASectionPrivate(static_cast<QDomCDATASectionPrivate *>(importedNode),
5856 deep);
5857 break;
5859 node = new QDomCommentPrivate(static_cast<QDomCommentPrivate *>(importedNode), deep);
5860 break;
5861 default:
5862 break;
5863 }
5864 if (node) {
5865 node->setOwnerDocument(this);
5866 // The QDomNode constructor increases the refcount, so deref first to
5867 // keep refcount balanced.
5868 node->ref.deref();
5869 }
5870 return node;
5871}
5872
5874{
5875 const QDomNodePrivate* n = first;
5876
5877 if (encUsed == QDomNode::EncodingFromDocument) {
5878#if QT_CONFIG(regularexpression)
5879 const QDomNodePrivate* n = first;
5880
5881 if (n && n->isProcessingInstruction() && n->nodeName() == "xml"_L1) {
5882 // we have an XML declaration
5883 QString data = n->nodeValue();
5884 QRegularExpression encoding(QString::fromLatin1("encoding\\s*=\\s*((\"([^\"]*)\")|('([^']*)'))"));
5885 auto match = encoding.match(data);
5886 QString enc = match.captured(3);
5887 if (enc.isEmpty())
5888 enc = match.captured(5);
5889 if (!enc.isEmpty()) {
5890 auto encoding = QStringConverter::encodingForName(enc.toUtf8().constData());
5891 if (!encoding)
5892 qWarning() << "QDomDocument::save(): Unsupported encoding" << enc << "specified.";
5893 else
5894 s.setEncoding(encoding.value());
5895 }
5896 }
5897#endif
5898 bool doc = false;
5899
5900 while (n) {
5901 if (!doc && !(n->isProcessingInstruction() && n->nodeName() == "xml"_L1)) {
5902 // save doctype after XML declaration
5903 type->save(s, 0, indent);
5904 doc = true;
5905 }
5906 n->save(s, 0, indent);
5907 n = n->next;
5908 }
5909 }
5910 else {
5911
5912 // Write out the XML declaration.
5913 const QByteArray codecName = QStringConverter::nameForEncoding(s.encoding());
5914
5915 s << "<?xml version=\"1.0\" encoding=\""
5916 << codecName
5917 << "\"?>\n";
5918
5919 // Skip the first processing instruction by name "xml", if any such exists.
5920 const QDomNodePrivate* startNode = n;
5921
5922 // First, we try to find the PI and sets the startNode to the one appearing after it.
5923 while (n) {
5924 if (n->isProcessingInstruction() && n->nodeName() == "xml"_L1) {
5925 startNode = n->next;
5926 break;
5927 }
5928 else
5929 n = n->next;
5930 }
5931
5932 // Now we serialize all the nodes after the faked XML declaration(the PI).
5933 while(startNode) {
5934 startNode->save(s, 0, indent);
5935 startNode = startNode->next;
5936 }
5937 }
5938}
5939
5940/**************************************************************
5941 *
5942 * QDomDocument
5943 *
5944 **************************************************************/
5945
5946#define IMPL static_cast<QDomDocumentPrivate *>(impl)
5947
6030{
6031 impl = nullptr;
6032}
6033
6039{
6040 // We take over ownership
6042}
6043
6053
6062 : QDomNode(document)
6063{
6064}
6065
6067 : QDomNode(pimpl)
6068{
6069}
6070
6079
6086
6087#if QT_DEPRECATED_SINCE(6, 8)
6099bool QDomDocument::setContent(const QString& text, bool namespaceProcessing,
6100 QString *errorMsg, int *errorLine, int *errorColumn)
6101{
6102 QXmlStreamReader reader(text);
6103 reader.setNamespaceProcessing(namespaceProcessing);
6104 return setContent(&reader, namespaceProcessing, errorMsg, errorLine, errorColumn);
6105}
6106
6140
6155
6159bool QDomDocument::setContent(const QByteArray &data, bool namespaceProcessing,
6160 QString *errorMsg, int *errorLine, int *errorColumn)
6161{
6162 QXmlStreamReader reader(data);
6163 reader.setNamespaceProcessing(namespaceProcessing);
6164 return setContent(&reader, namespaceProcessing, errorMsg, errorLine, errorColumn);
6165}
6166
6167static inline QDomDocument::ParseOptions toParseOptions(bool namespaceProcessing)
6168{
6169 return namespaceProcessing ? QDomDocument::ParseOption::UseNamespaceProcessing
6171}
6172
6173static inline void unpackParseResult(const QDomDocument::ParseResult &parseResult,
6174 QString *errorMsg, int *errorLine, int *errorColumn)
6175{
6176 if (!parseResult) {
6177 if (errorMsg)
6178 *errorMsg = parseResult.errorMessage;
6179 if (errorLine)
6180 *errorLine = static_cast<int>(parseResult.errorLine);
6181 if (errorColumn)
6182 *errorColumn = static_cast<int>(parseResult.errorColumn);
6183 }
6184}
6185
6198bool QDomDocument::setContent(QIODevice* dev, bool namespaceProcessing,
6199 QString *errorMsg, int *errorLine, int *errorColumn)
6200{
6201 ParseResult result = setContent(dev, toParseOptions(namespaceProcessing));
6202 unpackParseResult(result, errorMsg, errorLine, errorColumn);
6203 return bool(result);
6204}
6205
6217bool QDomDocument::setContent(const QString& text, QString *errorMsg, int *errorLine, int *errorColumn)
6218{
6219 return setContent(text, false, errorMsg, errorLine, errorColumn);
6220}
6221
6232bool QDomDocument::setContent(const QByteArray& buffer, QString *errorMsg, int *errorLine, int *errorColumn )
6233{
6234 return setContent(buffer, false, errorMsg, errorLine, errorColumn);
6235}
6236
6246bool QDomDocument::setContent(QIODevice* dev, QString *errorMsg, int *errorLine, int *errorColumn )
6247{
6248 return setContent(dev, false, errorMsg, errorLine, errorColumn);
6249}
6250
6271bool QDomDocument::setContent(QXmlStreamReader *reader, bool namespaceProcessing,
6272 QString *errorMsg, int *errorLine, int *errorColumn)
6273{
6274 ParseResult result = setContent(reader, toParseOptions(namespaceProcessing));
6275 unpackParseResult(result, errorMsg, errorLine, errorColumn);
6276 return bool(result);
6277}
6279#endif // QT_DEPRECATED_SINCE(6, 8)
6280
6392QDomDocument::ParseResult QDomDocument::setContentImpl(const QByteArray &data, ParseOptions options)
6393{
6394 QXmlStreamReader reader(data);
6395 reader.setNamespaceProcessing(options.testFlag(ParseOption::UseNamespaceProcessing));
6396 return setContent(&reader, options);
6397}
6398
6400{
6401 QXmlStreamReader reader(data);
6402 reader.setNamespaceProcessing(options.testFlag(ParseOption::UseNamespaceProcessing));
6403 return setContent(&reader, options);
6404}
6405
6407{
6408#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
6409 if (!device->isOpen()) {
6410 qWarning("QDomDocument called with unopened QIODevice. "
6411 "This will not be supported in future Qt versions.");
6412 if (!device->open(QIODevice::ReadOnly)) {
6413 const auto error = u"QDomDocument::setContent: Failed to open device."_s;
6414 qWarning("%s", qPrintable(error));
6415 return { error };
6416 }
6417 }
6418#endif
6419
6420 QXmlStreamReader reader(device);
6421 reader.setNamespaceProcessing(options.testFlag(ParseOption::UseNamespaceProcessing));
6422 return setContent(&reader, options);
6423}
6424
6425QDomDocument::ParseResult QDomDocument::setContent(QXmlStreamReader *reader, ParseOptions options)
6426{
6427 if (!impl)
6428 impl = new QDomDocumentPrivate();
6429 return IMPL->setContent(reader, options);
6430}
6431
6441{
6442 QString str;
6444 save(s, indent);
6445 return str;
6446}
6447
6458{
6459 // ### if there is an encoding specified in the xml declaration, this
6460 // encoding declaration should be changed to utf8
6461 return toString(indent).toUtf8();
6462}
6463
6464
6469{
6470 if (!impl)
6471 return QDomDocumentType();
6472 return QDomDocumentType(IMPL->doctype());
6473}
6474
6479{
6480 if (!impl)
6481 return QDomImplementation();
6482 return QDomImplementation(IMPL->implementation());
6483}
6484
6489{
6490 if (!impl)
6491 return QDomElement();
6492 return QDomElement(IMPL->documentElement());
6493}
6494
6506{
6507 if (!impl)
6508 impl = new QDomDocumentPrivate();
6509 return QDomElement(IMPL->createElement(tagName));
6510}
6511
6518{
6519 if (!impl)
6520 impl = new QDomDocumentPrivate();
6521 return QDomDocumentFragment(IMPL->createDocumentFragment());
6522}
6523
6535{
6536 if (!impl)
6537 impl = new QDomDocumentPrivate();
6538 return QDomText(IMPL->createTextNode(value));
6539}
6540
6551{
6552 if (!impl)
6553 impl = new QDomDocumentPrivate();
6554 return QDomComment(IMPL->createComment(value));
6555}
6556
6568{
6569 if (!impl)
6570 impl = new QDomDocumentPrivate();
6571 return QDomCDATASection(IMPL->createCDATASection(value));
6572}
6573
6587 const QString& data)
6588{
6589 if (!impl)
6590 impl = new QDomDocumentPrivate();
6591 return QDomProcessingInstruction(IMPL->createProcessingInstruction(target, data));
6592}
6593
6594
6605{
6606 if (!impl)
6607 impl = new QDomDocumentPrivate();
6608 return QDomAttr(IMPL->createAttribute(name));
6609}
6610
6621{
6622 if (!impl)
6623 impl = new QDomDocumentPrivate();
6624 return QDomEntityReference(IMPL->createEntityReference(name));
6625}
6626
6636{
6637 return QDomNodeList(new QDomNodeListPrivate(impl, tagname));
6638}
6639
6709QDomNode QDomDocument::importNode(const QDomNode& importedNode, bool deep)
6710{
6711 if (importedNode.isNull())
6712 return QDomNode();
6713 if (!impl)
6714 impl = new QDomDocumentPrivate();
6715 return QDomNode(IMPL->importNode(importedNode.impl, deep));
6716}
6717
6731{
6732 if (!impl)
6733 impl = new QDomDocumentPrivate();
6734 return QDomElement(IMPL->createElementNS(nsURI, qName));
6735}
6736
6750{
6751 if (!impl)
6752 impl = new QDomDocumentPrivate();
6753 return QDomAttr(IMPL->createAttributeNS(nsURI, qName));
6754}
6755
6765{
6766 return QDomNodeList(new QDomNodeListPrivate(impl, nsURI, localName));
6767}
6768
6780{
6781 qWarning("elementById() is not implemented and will always return a null node.");
6782 return QDomElement();
6783}
6784
6791#undef IMPL
6792
6793/**************************************************************
6794 *
6795 * Node casting functions
6796 *
6797 **************************************************************/
6798
6806{
6807 if (impl && impl->isAttr())
6808 return QDomAttr(static_cast<QDomAttrPrivate *>(impl));
6809 return QDomAttr();
6810}
6811
6819{
6820 if (impl && impl->isCDATASection())
6821 return QDomCDATASection(static_cast<QDomCDATASectionPrivate *>(impl));
6822 return QDomCDATASection();
6823}
6824
6837
6845{
6846 if (impl && impl->isDocument())
6847 return QDomDocument(static_cast<QDomDocumentPrivate *>(impl));
6848 return QDomDocument();
6849}
6850
6858{
6859 if (impl && impl->isDocumentType())
6860 return QDomDocumentType(static_cast<QDomDocumentTypePrivate *>(impl));
6861 return QDomDocumentType();
6862}
6863
6871{
6872 if (impl && impl->isElement())
6873 return QDomElement(static_cast<QDomElementPrivate *>(impl));
6874 return QDomElement();
6875}
6876
6889
6897{
6898 if (impl && impl->isText())
6899 return QDomText(static_cast<QDomTextPrivate *>(impl));
6900 return QDomText();
6901}
6902
6910{
6911 if (impl && impl->isEntity())
6912 return QDomEntity(static_cast<QDomEntityPrivate *>(impl));
6913 return QDomEntity();
6914}
6915
6923{
6924 if (impl && impl->isNotation())
6925 return QDomNotation(static_cast<QDomNotationPrivate *>(impl));
6926 return QDomNotation();
6927}
6928
6941
6949{
6950 if (impl && impl->isCharacterData())
6951 return QDomCharacterData(static_cast<QDomCharacterDataPrivate *>(impl));
6952 return QDomCharacterData();
6953}
6954
6962{
6963 if (impl && impl->isComment())
6964 return QDomComment(static_cast<QDomCommentPrivate *>(impl));
6965 return QDomComment();
6966}
6967
6975
6976#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:494
const char * constData() const noexcept
Returns a pointer to the const data stored in the byte array.
Definition qbytearray.h:124
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:339
\inmodule QtCore
QDomAttrPrivate(QDomDocumentPrivate *, QDomNodePrivate *, const QString &name)
Definition qdom.cpp:3550
QDomNodePrivate * cloneNode(bool deep=true) override
Definition qdom.cpp:3586
virtual void save(QTextStream &s, int, int) const override
Definition qdom.cpp:3657
bool m_specified
Definition qdom_p.h:297
bool specified() const
Definition qdom.cpp:3594
void setNodeValue(const QString &v) override
Definition qdom.cpp:3572
\reentrant
Definition qdom.h:444
friend class QDomElement
Definition qdom.h:466
QDomAttr()
Constructs an empty attribute.
Definition qdom.cpp:3727
QDomAttr & operator=(const QDomAttr &other)
Assigns other to this DOM attribute.
QString name() const
Returns the attribute's name.
Definition qdom.cpp:3760
QString value() const
Returns the value of the attribute or an empty string if the attribute has not been specified.
Definition qdom.cpp:3799
bool specified() const
Returns true if the attribute has been set by the user with setValue().
Definition qdom.cpp:3773
QDomElement ownerElement() const
Returns the element node this attribute is attached to or a \l{QDomNode::isNull()}{null node} if this...
Definition qdom.cpp:3785
void setValue(const QString &value)
Sets the attribute's value to value.
Definition qdom.cpp:3811
QDomCDATASectionPrivate(QDomDocumentPrivate *, QDomNodePrivate *parent, const QString &val)
Definition qdom.cpp:4889
virtual void save(QTextStream &s, int, int) const override
Definition qdom.cpp:4909
QDomNodePrivate * cloneNode(bool deep=true) override
Definition qdom.cpp:4901
\reentrant
Definition qdom.h:567
QDomCDATASection()
Constructs an empty CDATA section.
Definition qdom.cpp:4951
QDomCDATASection & operator=(const QDomCDATASection &other)
Assigns other to this CDATA section.
QDomNodePrivate * cloneNode(bool deep=true) override
Definition qdom.cpp:3347
QDomCharacterDataPrivate(QDomDocumentPrivate *, QDomNodePrivate *parent, const QString &data)
Definition qdom.cpp:3334
void appendData(const QString &arg)
Definition qdom.cpp:3380
void insertData(unsigned long offset, const QString &arg)
Definition qdom.cpp:3365
int dataLength() const
Definition qdom.cpp:3355
QString substringData(unsigned long offset, unsigned long count) const
Definition qdom.cpp:3360
void deleteData(unsigned long offset, unsigned long count)
Definition qdom.cpp:3370
void replaceData(unsigned long offset, unsigned long count, const QString &arg)
Definition qdom.cpp:3375
\reentrant
Definition qdom.h:411
int length() const
Returns the length of the stored string.
Definition qdom.cpp:3476
QString data() const
Returns the string stored in this object.
Definition qdom.cpp:3457
QDomCharacterData()
Constructs an empty character data object.
Definition qdom.cpp:3421
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:3524
void deleteData(unsigned long offset, unsigned long count)
Deletes a substring of length count from position offset.
Definition qdom.cpp:3514
QString substringData(unsigned long offset, unsigned long count)
Returns the substring of length count from position offset.
Definition qdom.cpp:3486
void setData(const QString &data)
Sets this object's string to data.
Definition qdom.cpp:3467
QDomCharacterData & operator=(const QDomCharacterData &other)
Assigns other to this character data.
void appendData(const QString &arg)
Appends the string arg to the stored string.
Definition qdom.cpp:3496
void insertData(unsigned long offset, const QString &arg)
Inserts the string arg into the stored string at position offset.
Definition qdom.cpp:3505
QDomNode::NodeType nodeType() const
Returns the type of node this object refers to (i.e.
Definition qdom.cpp:3535
QDomNodePrivate * cloneNode(bool deep=true) override
Definition qdom.cpp:4792
virtual void save(QTextStream &s, int, int) const override
Definition qdom.cpp:4800
QDomCommentPrivate(QDomDocumentPrivate *, QDomNodePrivate *parent, const QString &val)
Definition qdom.cpp:4780
\reentrant
Definition qdom.h:550
QDomComment & operator=(const QDomComment &other)
Assigns other to this DOM comment.
QDomComment()
Constructs an empty comment.
Definition qdom.cpp:4846
QDomDocumentFragmentPrivate(QDomDocumentPrivate *, QDomNodePrivate *parent=nullptr)
Definition qdom.cpp:3237
virtual QDomNodePrivate * cloneNode(bool deep=true) override
Definition qdom.cpp:3248
\reentrant
Definition qdom.h:394
QDomDocumentFragment & operator=(const QDomDocumentFragment &other)
Assigns other to this DOM document fragment.
QDomDocumentFragment()
Constructs an empty document fragment.
Definition qdom.cpp:3290
QDomDocument::ParseResult setContent(QXmlStreamReader *reader, QDomDocument::ParseOptions options)
Definition qdom.cpp:5666
QDomNodePrivate * cloneNode(bool deep=true) override
Definition qdom.cpp:5687
QDomElementPrivate * createElement(const QString &tagName)
Definition qdom.cpp:5704
QDomAttrPrivate * createAttribute(const QString &name)
Definition qdom.cpp:5787
QDomCDATASectionPrivate * createCDATASection(const QString &data)
Definition qdom.cpp:5759
QDomProcessingInstructionPrivate * createProcessingInstruction(const QString &target, const QString &data)
Definition qdom.cpp:5771
QDomTextPrivate * createTextNode(const QString &data)
Definition qdom.cpp:5735
QDomDocumentFragmentPrivate * createDocumentFragment()
Definition qdom.cpp:5728
void saveDocument(QTextStream &stream, const int indent, QDomNode::EncodingPolicy encUsed) const
Definition qdom.cpp:5873
void clear() override
Definition qdom.cpp:5659
QDomAttrPrivate * createAttributeNS(const QString &nsURI, const QString &qName)
Definition qdom.cpp:5799
QDomNodePrivate * importNode(QDomNodePrivate *importedNode, bool deep)
Definition qdom.cpp:5823
QDomElementPrivate * documentElement()
Definition qdom.cpp:5695
QExplicitlySharedDataPointer< QDomImplementationPrivate > impl
Definition qdom_p.h:458
QDomEntityReferencePrivate * createEntityReference(const QString &name)
Definition qdom.cpp:5811
QDomElementPrivate * createElementNS(const QString &nsURI, const QString &qName)
Definition qdom.cpp:5716
QDomCommentPrivate * createComment(const QString &data)
Definition qdom.cpp:5747
QDomNodePrivate * insertAfter(QDomNodePrivate *newChild, QDomNodePrivate *refChild) override
Definition qdom.cpp:2994
QDomDocumentTypePrivate(QDomDocumentPrivate *, QDomNodePrivate *parent=nullptr)
Definition qdom.cpp:2925
void save(QTextStream &s, int, int) const override
Definition qdom.cpp:3051
QDomNodePrivate * removeChild(QDomNodePrivate *oldChild) override
Definition qdom.cpp:3027
QDomNodePrivate * cloneNode(bool deep=true) override
Definition qdom.cpp:2973
QDomNodePrivate * appendChild(QDomNodePrivate *newChild) override
Definition qdom.cpp:3040
QDomNodePrivate * replaceChild(QDomNodePrivate *newChild, QDomNodePrivate *oldChild) override
Definition qdom.cpp:3007
QDomNodePrivate * insertBefore(QDomNodePrivate *newChild, QDomNodePrivate *refChild) override
Definition qdom.cpp:2981
QDomNamedNodeMapPrivate * entities
Definition qdom_p.h:230
QDomNamedNodeMapPrivate * notations
Definition qdom_p.h:231
\reentrant
Definition qdom.h:243
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:3182
QDomDocumentType & operator=(const QDomDocumentType &other)
Assigns other to this document type.
QDomDocumentType()
Creates an empty QDomDocumentType object.
Definition qdom.cpp:3114
QDomNamedNodeMap notations() const
Returns a map of all notations described in the DTD.
Definition qdom.cpp:3169
QString name() const
Returns the name of the document type as specified in the <!DOCTYPE name> tag.
Definition qdom.cpp:3149
QString internalSubset() const
Returns the internal subset of the document type or an empty string if there is no internal subset.
Definition qdom.cpp:3208
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:3195
QDomNamedNodeMap entities() const
Returns a map of all entities described in the DTD.
Definition qdom.cpp:3159
\reentrant
Definition qdom.h:269
QDomText createTextNode(const QString &data)
Creates a text node for the string value that can be inserted into the document tree,...
Definition qdom.cpp:6534
QDomDocument & operator=(const QDomDocument &other)
Assigns other to this DOM document.
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:6586
Q_WEAK_OVERLOAD ParseResult setContent(const QByteArray &data, ParseOptions options=ParseOption::Default)
Definition qdom.h:338
friend class QDomNode
Definition qdom.h:353
QDomAttr createAttribute(const QString &name)
Creates a new attribute called name that can be inserted into an element, e.g.
Definition qdom.cpp:6604
QDomNode importNode(const QDomNode &importedNode, bool deep)
Imports the node importedNode from another document to this document.
Definition qdom.cpp:6709
QDomElement documentElement() const
Returns the root element of the document.
Definition qdom.cpp:6488
QDomCDATASection createCDATASection(const QString &data)
Creates a new CDATA section for the string value that can be inserted into the document,...
Definition qdom.cpp:6567
QDomElement createElement(const QString &tagName)
Creates a new element called tagName that can be inserted into the DOM tree, e.g.
Definition qdom.cpp:6505
QDomDocument()
Constructs an empty document.
Definition qdom.cpp:6029
~QDomDocument()
Destroys the object and frees its resources.
Definition qdom.cpp:6083
QByteArray toByteArray(int indent=1) const
Converts the parsed document back to its textual representation and returns a QByteArray containing t...
Definition qdom.cpp:6457
QString toString(int indent=1) const
Converts the parsed document back to its textual representation.
Definition qdom.cpp:6440
QDomImplementation implementation() const
Returns a QDomImplementation object.
Definition qdom.cpp:6478
QDomNodeList elementsByTagName(const QString &tagname) const
Returns a QDomNodeList, that contains all the elements in the document with the name tagname.
Definition qdom.cpp:6635
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:6764
QDomDocumentFragment createDocumentFragment()
Creates a new document fragment, that can be used to hold parts of the document, e....
Definition qdom.cpp:6517
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:6749
QDomEntityReference createEntityReference(const QString &name)
Creates a new entity reference called name that can be inserted into the document,...
Definition qdom.cpp:6620
QDomElement elementById(const QString &elementId)
Returns the element whose ID is equal to elementId.
Definition qdom.cpp:6779
QDomComment createComment(const QString &data)
Creates a new comment for the string value that can be inserted into the document,...
Definition qdom.cpp:6550
QDomDocumentType doctype() const
Returns the document type of this document.
Definition qdom.cpp:6468
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:6730
bool hasAttribute(const QString &name)
Definition qdom.cpp:3972
QDomElementPrivate(QDomDocumentPrivate *, QDomNodePrivate *parent, const QString &name)
Definition qdom.cpp:3833
QString attributeNS(const QString &nsURI, const QString &localName, const QString &defValue) const
Definition qdom.cpp:3882
QDomNamedNodeMapPrivate * m_attr
Definition qdom_p.h:333
QString attribute(const QString &name, const QString &defValue) const
Definition qdom.cpp:3873
virtual void save(QTextStream &s, int, int) const override
Definition qdom.cpp:3998
void setAttribute(const QString &name, const QString &value)
Definition qdom.cpp:3891
void removeAttribute(const QString &name)
Definition qdom.cpp:3926
QDomAttrPrivate * removeAttributeNode(QDomAttrPrivate *oldAttr)
Definition qdom.cpp:3967
QDomNodePrivate * cloneNode(bool deep=true) override
Definition qdom.cpp:3865
bool hasAttributeNS(const QString &nsURI, const QString &localName)
Definition qdom.cpp:3977
QDomAttrPrivate * attributeNode(const QString &name)
Definition qdom.cpp:3933
QString text()
Definition qdom.cpp:3982
QDomAttrPrivate * setAttributeNodeNS(QDomAttrPrivate *newAttr)
Definition qdom.cpp:3955
QDomAttrPrivate * setAttributeNode(QDomAttrPrivate *newAttr)
Definition qdom.cpp:3943
void setAttributeNS(const QString &nsURI, const QString &qName, const QString &newValue)
Definition qdom.cpp:3907
QDomAttrPrivate * attributeNodeNS(const QString &nsURI, const QString &localName)
Definition qdom.cpp:3938
\reentrant
Definition qdom.h:471
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:4546
QDomAttr setAttributeNodeNS(const QDomAttr &newAttr)
Adds the attribute newAttr to this element.
Definition qdom.cpp:4581
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:4607
void removeAttribute(const QString &name)
Removes the attribute called name name from this element.
Definition qdom.cpp:4376
bool hasAttribute(const QString &name) const
Returns true if this element has an attribute called name; otherwise returns false.
Definition qdom.cpp:4452
QDomAttr attributeNode(const QString &name)
Returns the QDomAttr object that corresponds to the attribute called name.
Definition qdom.cpp:4390
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:4564
void setAttribute(const QString &name, const QString &value)
Adds an attribute called name with value value.
Definition qdom.cpp:4294
QString tagName() const
Returns the tag name of this element.
Definition qdom.cpp:4254
QDomAttr setAttributeNode(const QDomAttr &newAttr)
Adds the attribute newAttr to this element.
Definition qdom.cpp:4407
QDomElement & operator=(const QDomElement &other)
Assigns other to this DOM element.
friend class QDomAttr
Definition qdom.h:525
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:4485
QDomNamedNodeMap attributes() const
Returns a QDomNamedNodeMap containing all this element's attributes.
Definition qdom.cpp:4267
QString text() const
Returns the element's text or an empty string.
Definition qdom.cpp:4628
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:4597
QDomAttr removeAttributeNode(const QDomAttr &oldAttr)
Removes the attribute oldAttr from the element and returns it.
Definition qdom.cpp:4419
void setTagName(const QString &name)
Sets this element's tag name to name.
Definition qdom.cpp:4239
QDomElement()
Constructs an empty element.
Definition qdom.cpp:4197
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:4466
QDomNodeList elementsByTagName(const QString &tagname) const
Returns a QDomNodeList containing all descendants of this element named tagname encountered during a ...
Definition qdom.cpp:4435
QString attribute(const QString &name, const QString &defValue=QString()) const
Returns the attribute called name.
Definition qdom.cpp:4280
QString m_sys
Definition qdom_p.h:390
QString m_notationName
Definition qdom_p.h:392
virtual void save(QTextStream &s, int, int) const override
Definition qdom.cpp:5200
QDomEntityPrivate(QDomDocumentPrivate *, QDomNodePrivate *parent, const QString &name, const QString &pub, const QString &sys, const QString &notation)
Definition qdom.cpp:5137
QString m_pub
Definition qdom_p.h:391
QDomNodePrivate * cloneNode(bool deep=true) override
Definition qdom.cpp:5156
QDomNodePrivate * cloneNode(bool deep=true) override
Definition qdom.cpp:5356
QDomEntityReferencePrivate(QDomDocumentPrivate *, QDomNodePrivate *parent, const QString &name)
Definition qdom.cpp:5345
virtual void save(QTextStream &s, int, int) const override
Definition qdom.cpp:5364
\reentrant
Definition qdom.h:626
QDomEntityReference()
Constructs an empty entity reference.
Definition qdom.cpp:5415
QDomEntityReference & operator=(const QDomEntityReference &other)
Assigns other to this entity reference.
\reentrant
Definition qdom.h:605
QString publicId() const
Returns the public identifier associated with this entity.
Definition qdom.cpp:5307
QDomEntity & operator=(const QDomEntity &other)
Assigns other to this DOM entity.
QString systemId() const
Returns the system identifier associated with this entity.
Definition qdom.cpp:5318
QString notationName() const
For unparsed entities this function returns the name of the notation for the entity.
Definition qdom.cpp:5330
QDomEntity()
Constructs an empty entity.
Definition qdom.cpp:5265
static QDomImplementation::InvalidDataPolicy invalidDataPolicy
Definition qdom_p.h:40
QDomImplementationPrivate * clone()
Definition qdom.cpp:324
\reentrant
Definition qdom.h:60
bool operator!=(const QDomImplementation &other) const
Returns true if other and this DOM implementation object were created from different QDomDocuments; o...
Definition qdom.cpp:420
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:85
QDomImplementation & operator=(const QDomImplementation &other)
Assigns other to this DOM implementation.
Definition qdom.cpp:397
InvalidDataPolicy
This enum specifies what should be done when a factory function in QDomDocument is called with invali...
Definition qdom.h:74
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
bool operator==(const QDomImplementation &other) const
Returns true if other and this DOM implementation object were created from the same QDomDocument; oth...
Definition qdom.cpp:411
static InvalidDataPolicy invalidDataPolicy()
Definition qdom.cpp:576
~QDomImplementation()
Destroys the object and frees its resources.
Definition qdom.cpp:428
bool contains(const QString &name) const
Definition qdom.cpp:2634
void setAppendToParent(bool b)
Definition qdom_p.h:193
QDomNamedNodeMapPrivate * clone(QDomNodePrivate *parent)
Definition qdom.cpp:2518
QDomNodePrivate * namedItemNS(const QString &nsURI, const QString &localName) const
Definition qdom.cpp:2554
QDomNodePrivate * item(int index) const
Definition qdom.cpp:2622
QDomNamedNodeMapPrivate(QDomNodePrivate *)
Definition qdom.cpp:2505
QDomNodePrivate * setNamedItem(QDomNodePrivate *arg)
Definition qdom.cpp:2569
QMultiHash< QString, QDomNodePrivate * > map
Definition qdom_p.h:203
bool containsNS(const QString &nsURI, const QString &localName) const
Definition qdom.cpp:2639
QDomNodePrivate * namedItem(const QString &name) const
Definition qdom.cpp:2548
QDomNodePrivate * removeNamedItem(const QString &name)
Definition qdom.cpp:2605
QDomNodePrivate * parent
Definition qdom_p.h:204
QDomNodePrivate * setNamedItemNS(QDomNodePrivate *arg)
Definition qdom.cpp:2584
\reentrant
Definition qdom.h:357
QDomNamedNodeMap & operator=(const QDomNamedNodeMap &other)
Assigns other to this named node map.
Definition qdom.cpp:2718
~QDomNamedNodeMap()
Destroys the object and frees its resources.
Definition qdom.cpp:2749
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:2828
QDomNode removeNamedItem(const QString &name)
Removes the node called name from the map.
Definition qdom.cpp:2797
friend class QDomNode
Definition qdom.h:388
QDomNamedNodeMap()
Constructs an empty named node map.
Definition qdom.cpp:2693
bool operator==(const QDomNamedNodeMap &other) const
Returns true if other and this named node map are equal; otherwise returns false.
Definition qdom.cpp:2732
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:2861
QDomNode namedItem(const QString &name) const
Returns the node called name.
Definition qdom.cpp:2764
QDomNode setNamedItem(const QDomNode &newNode)
Inserts the node newNode into the named node map.
Definition qdom.cpp:2781
int length() const
Returns the number of nodes in the map.
Definition qdom.cpp:2876
bool contains(const QString &name) const
Returns true if the map contains a node called name; otherwise returns false.
Definition qdom.cpp:2910
QDomNode setNamedItemNS(const QDomNode &newNode)
Inserts the node newNode in the map.
Definition qdom.cpp:2843
QDomNode item(int index) const
Retrieves the node at position index.
Definition qdom.cpp:2812
bool operator!=(const QDomNamedNodeMap &other) const
Returns true if other and this named node map are not equal; otherwise returns false.
Definition qdom.cpp:2741
QAtomicInt ref
Definition qdom_p.h:150
void createList() const
Definition qdom.cpp:652
QList< QDomNodePrivate * > list
Definition qdom_p.h:157
int length() const
Definition qdom.cpp:726
bool operator==(const QDomNodeListPrivate &) const
Definition qdom.cpp:642
QDomNodePrivate * node_impl
Definition qdom_p.h:154
QDomNodePrivate * item(int index)
Definition qdom.cpp:718
QDomNodeListPrivate(QDomNodePrivate *)
Definition qdom.cpp:607
bool maybeCreateList() const
Definition qdom.cpp:706
bool operator!=(const QDomNodeListPrivate &) const
Definition qdom.cpp:647
\reentrant
Definition qdom.h:214
bool operator!=(const QDomNodeList &other) const
Returns true the node list other and this node list are not equal; otherwise returns false.
Definition qdom.cpp:818
friend class QDomNode
Definition qdom.h:237
QDomNode item(int index) const
Returns the node at position index.
Definition qdom.cpp:841
QDomNodeList & operator=(const QDomNodeList &other)
Assigns other to this node list.
Definition qdom.cpp:791
int length() const
Returns the number of nodes in the list.
Definition qdom.cpp:852
~QDomNodeList()
Destroys the object and frees its resources.
Definition qdom.cpp:826
QDomNodeList()
Creates an empty node list.
Definition qdom.cpp:768
bool operator==(const QDomNodeList &other) const
Returns true if the node list other and this node list are equal; otherwise returns false.
Definition qdom.cpp:805
QDomDocumentPrivate * ownerDocument()
Definition qdom.cpp:1308
bool isComment() const
Definition qdom_p.h:107
QDomNodePrivate * next
Definition qdom_p.h:118
void setOwnerDocument(QDomDocumentPrivate *doc)
Definition qdom.cpp:895
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:956
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:1078
QAtomicInt ref
Definition qdom_p.h:116
bool isNotation() const
Definition qdom_p.h:96
virtual ~QDomNodePrivate()
Definition qdom.cpp:939
QDomNodePrivate * first
Definition qdom_p.h:120
QDomNodePrivate(QDomDocumentPrivate *, QDomNodePrivate *parent=nullptr)
Definition qdom.cpp:901
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:1302
virtual void normalize()
Definition qdom.cpp:1350
virtual void save(QTextStream &, int, int) const
Definition qdom.cpp:1360
QString name
Definition qdom_p.h:123
QDomNodePrivate * namedItem(const QString &name)
Definition qdom.cpp:971
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:1266
bool isEntity() const
Definition qdom_p.h:95
void setLocation(int lineNumber, int columnNumber)
Definition qdom.cpp:1369
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:1174
virtual QDomNodePrivate * cloneNode(bool deep=true)
Definition qdom.cpp:1320
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:983
\reentrant
Definition qdom.h:89
QString nodeName() const
Returns the name of the node.
Definition qdom.cpp:1588
EncodingPolicy
Definition qdom.h:109
@ EncodingFromDocument
Definition qdom.h:110
void setNodeValue(const QString &value)
Sets the node's value to value.
Definition qdom.cpp:1628
bool isCharacterData() const
Returns true if the node is a character data node; otherwise returns false.
Definition qdom.cpp:2356
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:2146
int columnNumber() const
Definition qdom.cpp:2493
QDomDocument toDocument() const
Converts a QDomNode into a QDomDocument.
Definition qdom.cpp:6844
QDomEntityReference toEntityReference() const
Converts a QDomNode into a QDomEntityReference.
Definition qdom.cpp:6883
QDomNode()
Constructs a \l{isNull()}{null} node.
Definition qdom.cpp:1470
friend class QDomDocumentType
Definition qdom.h:208
QDomNode replaceChild(const QDomNode &newChild, const QDomNode &oldChild)
Replaces oldChild with newChild.
Definition qdom.cpp:2013
QDomNode parentNode() const
Returns the parent node.
Definition qdom.cpp:1673
QDomNodeList childNodes() const
Returns a list of all direct child nodes.
Definition qdom.cpp:1698
QDomDocumentType toDocumentType() const
Converts a QDomNode into a QDomDocumentType.
Definition qdom.cpp:6857
QDomNodePrivate * impl
Definition qdom.h:202
bool operator==(const QDomNode &other) const
Returns true if other and this DOM node are equal; otherwise returns false.
Definition qdom.cpp:1536
friend class QDomNodeList
Definition qdom.h:209
friend class QDomDocument
Definition qdom.h:207
bool operator!=(const QDomNode &other) const
Returns true if other and this DOM node are not equal; otherwise returns false.
Definition qdom.cpp:1545
QString prefix() const
Returns the namespace prefix of the node or an empty string if the node has no namespace prefix.
Definition qdom.cpp:1882
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:2412
bool hasChildNodes() const
Returns true if the node has one or more children; otherwise returns false.
Definition qdom.cpp:2076
QDomEntity toEntity() const
Converts a QDomNode into a QDomEntity.
Definition qdom.cpp:6909
QDomNode insertAfter(const QDomNode &newChild, const QDomNode &refChild)
Inserts the node newChild after the child node refChild.
Definition qdom.cpp:1991
int lineNumber() const
Definition qdom.cpp:2479
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:2435
QDomDocumentFragment toDocumentFragment() const
Converts a QDomNode into a QDomDocumentFragment.
Definition qdom.cpp:6831
QDomAttr toAttr() const
Converts a QDomNode into a QDomAttr.
Definition qdom.cpp:6805
friend class QDomNamedNodeMap
Definition qdom.h:210
QDomNode lastChild() const
Returns the last child of the node.
Definition qdom.cpp:1726
bool isAttr() const
Returns true if the node is an attribute; otherwise returns false.
Definition qdom.cpp:2179
bool isProcessingInstruction() const
Returns true if the node is a processing instruction; otherwise returns false.
Definition qdom.cpp:2339
QDomCDATASection toCDATASection() const
Converts a QDomNode into a QDomCDATASection.
Definition qdom.cpp:6818
QDomCharacterData toCharacterData() const
Converts a QDomNode into a QDomCharacterData.
Definition qdom.cpp:6948
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:2098
QDomNode firstChild() const
Returns the first child of the node.
Definition qdom.cpp:1712
QDomNotation toNotation() const
Converts a QDomNode into a QDomNotation.
Definition qdom.cpp:6922
QDomElement toElement() const
Converts a QDomNode into a QDomElement.
Definition qdom.cpp:6870
bool isEntity() const
Returns true if the node is an entity; otherwise returns false.
Definition qdom.cpp:2307
QDomNode & operator=(const QDomNode &other)
Assigns a copy of other to this DOM node.
Definition qdom.cpp:1506
QDomNode nextSibling() const
Returns the next sibling in the document tree.
Definition qdom.cpp:1766
QString namespaceURI() const
Returns the namespace URI of this node or an empty string if the node has no namespace URI.
Definition qdom.cpp:1853
QDomDocument ownerDocument() const
Returns the document to which this node belongs.
Definition qdom.cpp:1793
bool isEntityReference() const
Returns true if the node is an entity reference; otherwise returns false.
Definition qdom.cpp:2277
QDomNode namedItem(const QString &name) const
Returns the first direct child node for which nodeName() equals name.
Definition qdom.cpp:2114
QDomNode cloneNode(bool deep=true) const
Creates a deep (not shallow) copy of the QDomNode.
Definition qdom.cpp:1808
bool isText() const
Returns true if the node is a text node; otherwise returns false.
Definition qdom.cpp:2292
bool isNotation() const
Returns true if the node is a notation; otherwise returns false.
Definition qdom.cpp:2322
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:1903
bool isNull() const
Returns true if this node is null (i.e.
Definition qdom.cpp:2087
QDomProcessingInstruction toProcessingInstruction() const
Converts a QDomNode into a QDomProcessingInstruction.
Definition qdom.cpp:6935
void normalize()
Calling normalize() on an element converts all its children into a standard form.
Definition qdom.cpp:1821
QString localName() const
If the node uses namespaces, this function returns the local name of the node; otherwise it returns a...
Definition qdom.cpp:1923
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:2163
QDomText toText() const
Converts a QDomNode into a QDomText.
Definition qdom.cpp:6896
bool isComment() const
Returns true if the node is a comment; otherwise returns false.
Definition qdom.cpp:2371
bool isDocumentFragment() const
Returns true if the node is a document fragment; otherwise returns false.
Definition qdom.cpp:2213
QDomNamedNodeMap attributes() const
Returns a named node map of all attributes.
Definition qdom.cpp:1782
bool hasAttributes() const
Returns true if the node has attributes; otherwise returns false.
Definition qdom.cpp:1935
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:2458
bool isElement() const
Returns true if the node is an element; otherwise returns false.
Definition qdom.cpp:2260
bool isCDATASection() const
Returns true if the node is a CDATA section; otherwise returns false.
Definition qdom.cpp:2196
NodeType
This enum defines the type of the node: \value ElementNode \value AttributeNode \value TextNode \valu...
Definition qdom.h:91
@ EntityReferenceNode
Definition qdom.h:96
@ CommentNode
Definition qdom.h:99
@ DocumentFragmentNode
Definition qdom.h:102
@ CDATASectionNode
Definition qdom.h:95
@ EntityNode
Definition qdom.h:97
@ TextNode
Definition qdom.h:94
@ ElementNode
Definition qdom.h:92
@ CharacterDataNode
Definition qdom.h:105
@ BaseNode
Definition qdom.h:104
@ NotationNode
Definition qdom.h:103
@ ProcessingInstructionNode
Definition qdom.h:98
@ AttributeNode
Definition qdom.h:93
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:1835
QDomNode insertBefore(const QDomNode &newChild, const QDomNode &refChild)
Inserts the node newChild before the child node refChild.
Definition qdom.cpp:1963
QString nodeValue() const
Returns the value of the node.
Definition qdom.cpp:1616
QDomNode removeChild(const QDomNode &oldChild)
Removes oldChild from the list of children.
Definition qdom.cpp:2028
bool isDocument() const
Returns true if the node is a document; otherwise returns false.
Definition qdom.cpp:2228
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:2390
QDomComment toComment() const
Converts a QDomNode into a QDomComment.
Definition qdom.cpp:6961
QDomNode previousSibling() const
Returns the previous sibling in the document tree.
Definition qdom.cpp:1746
QDomNode appendChild(const QDomNode &newChild)
Appends newChild as the node's last child.
Definition qdom.cpp:2063
bool isDocumentType() const
Returns true if the node is a document type; otherwise returns false.
Definition qdom.cpp:2245
NodeType nodeType() const
Returns the type of the node.
Definition qdom.cpp:1662
~QDomNode()
Destroys the object and frees its resources.
Definition qdom.cpp:1553
virtual void save(QTextStream &s, int, int) const override
Definition qdom.cpp:5019
QDomNotationPrivate(QDomDocumentPrivate *, QDomNodePrivate *parent, const QString &name, const QString &pub, const QString &sys)
Definition qdom.cpp:4994
QDomNodePrivate * cloneNode(bool deep=true) override
Definition qdom.cpp:5011
\reentrant
Definition qdom.h:584
QDomNotation()
Constructor.
Definition qdom.cpp:5072
QDomNotation & operator=(const QDomNotation &other)
Assigns other to this DOM notation.
QString publicId() const
Returns the public identifier of this notation.
Definition qdom.cpp:5112
QString systemId() const
Returns the system identifier of this notation.
Definition qdom.cpp:5122
QDomNodePrivate * cloneNode(bool deep=true) override
Definition qdom.cpp:5472
virtual void save(QTextStream &s, int, int) const override
Definition qdom.cpp:5480
QDomProcessingInstructionPrivate(QDomDocumentPrivate *, QDomNodePrivate *parent, const QString &target, const QString &data)
Definition qdom.cpp:5458
void setData(const QString &data)
Sets the data contained in the processing instruction to data.
Definition qdom.cpp:5596
QDomProcessingInstruction()
Constructs an empty processing instruction.
Definition qdom.cpp:5529
QString target() const
Returns the target of this processing instruction.
Definition qdom.cpp:5572
QString data() const
Returns the content of this processing instruction.
Definition qdom.cpp:5584
QDomProcessingInstruction & operator=(const QDomProcessingInstruction &other)
Assigns other to this processing instruction.
QDomNodePrivate * cloneNode(bool deep=true) override
Definition qdom.cpp:4654
QDomTextPrivate(QDomDocumentPrivate *, QDomNodePrivate *parent, const QString &val)
Definition qdom.cpp:4643
QDomTextPrivate * splitText(int offset)
Definition qdom.cpp:4662
virtual void save(QTextStream &s, int, int) const override
Definition qdom.cpp:4681
\reentrant
Definition qdom.h:529
QDomText()
Constructs an empty QDomText object.
Definition qdom.cpp:4718
QDomText splitText(int offset)
Splits this DOM text object into two QDomText objects.
Definition qdom.cpp:4765
QDomText & operator=(const QDomText &other)
Assigns other to this DOM text.
void reset(T *ptr=nullptr) noexcept
\inmodule QtCore \reentrant
Definition qiodevice.h:34
qsizetype size() const noexcept
Definition qlist.h:397
const_reference at(qsizetype i) const noexcept
Definition qlist.h:446
void append(parameter_type t)
Definition qlist.h:458
void clear()
Definition qlist.h:434
iterator find(const Key &key)
Definition qhash.h:2021
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:1921
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:1925
T value(const Key &key) const noexcept
Definition qhash.h:1703
bool contains(const Key &key) const noexcept
Definition qhash.h:1658
qsizetype remove(const Key &key)
Definition qhash.h:1596
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition qhash.h:2034
bool isEmpty() const noexcept
Definition qhash.h:1569
iterator begin()
Returns an \l{STL-style iterators}{STL-style iterator} pointing to the first item in the hash.
Definition qhash.h:1918
qsizetype size() const noexcept
Definition qhash.h:1567
void clear() noexcept(std::is_nothrow_destructible< Node >::value)
Definition qhash.h:1588
iterator end() noexcept
Returns an \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item after the last ...
Definition qhash.h:1922
\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:129
QString left(qsizetype n) const &
Definition qstring.h:363
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:5455
QString & replace(qsizetype i, qsizetype len, QChar after)
Definition qstring.cpp:3824
void reserve(qsizetype size)
Ensures the string has space for at least size characters.
Definition qstring.h:1325
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:5871
QString mid(qsizetype position, qsizetype n=-1) const &
Definition qstring.cpp:5300
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
Definition qstring.h:192
void clear()
Clears the contents of the string and makes it null.
Definition qstring.h:1252
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition qstring.h:994
qsizetype size() const noexcept
Returns the number of characters in this string.
Definition qstring.h:186
int compare(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
Definition qstring.cpp:6664
QString & insert(qsizetype i, QChar c)
Definition qstring.cpp:3132
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:8084
QString & setNum(short, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.h:1257
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:3466
QByteArray toUtf8() const &
Definition qstring.h:634
\inmodule QtCore
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
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:1381
static QString quotedValue(const QString &data)
Definition qdom.cpp:3045
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:3609
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:5167
static void qNormalizeNode(QDomNodePrivate *n)
Definition qdom.cpp:1328
EGLStreamKHR stream
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
#define QT_RETHROW
#define QT_CATCH(A)
#define QT_TRY
#define qWarning
Definition qlogging.h:166
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
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLfloat GLfloat f
GLenum GLuint buffer
GLenum type
GLenum target
GLenum GLuint GLintptr offset
GLint ref
GLuint name
GLint first
GLfloat n
GLdouble s
[6]
Definition qopenglext.h:235
const GLubyte * c
GLdouble GLdouble t
Definition qopenglext.h:243
GLuint64EXT * result
[6]
GLfloat GLfloat p
[1]
GLenum GLsizei len
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
SSL_CTX int void * arg
#define qPrintable(string)
Definition qstring.h:1531
#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:64
ptrdiff_t qsizetype
Definition qtypes.h:165
qint64 qlonglong
Definition qtypes.h:63
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:279
qsizetype errorColumn
Definition qdom.h:282