5#include <qplatformdefs.h>
7#include "private/qxmlutils_p.h"
12#include "qdomhelpers_p.h"
17#if QT_CONFIG(regularexpression)
18#include <qregularexpression.h>
20#include <qtextstream.h>
22#include <qshareddata.h>
24#include <qxmlstream.h>
25#include <private/qduplicatetracker_p.h>
26#include <private/qstringiterator_p.h>
27#include <qvarlengtharray.h>
35using namespace Qt::StringLiterals;
38
39
40
41
42
43
44
45
46
47
50
51
52
53
54
55
58
59
60
61
62
63
64
65
66
67
68
72
73
74static void qt_split_namespace(QString& prefix, QString& name,
const QString& qName,
bool hasURI)
76 qsizetype i = qName.indexOf(u':');
84 prefix = qName.left(i);
85 name = qName.mid(i + 1);
90
91
92
93
94QDomImplementation::InvalidDataPolicy QDomImplementationPrivate::invalidDataPolicy
95 = QDomImplementation::ReturnNullNode;
99static QString fixedXmlName(
const QString &_name,
bool *ok,
bool namespaces =
false)
101 QString name, prefix;
103 qt_split_namespace(prefix, name, _name,
true);
107 if (name.isEmpty()) {
112 if (QDomImplementationPrivate::invalidDataPolicy == QDomImplementation::AcceptInvalidChars) {
118 bool firstChar =
true;
119 for (
int i = 0; i < name.size(); ++i) {
120 QChar c = name.at(i);
122 if (QXmlUtils::isLetter(c) || c.unicode() ==
'_' || c.unicode() ==
':') {
125 }
else if (QDomImplementationPrivate::invalidDataPolicy == QDomImplementation::ReturnNullNode) {
130 if (QXmlUtils::isNameChar(c))
132 else if (QDomImplementationPrivate::invalidDataPolicy == QDomImplementation::ReturnNullNode) {
139 if (result.isEmpty()) {
145 if (namespaces && !prefix.isEmpty())
146 return prefix + u':' + result;
153static QString fixedCharData(
const QString &data,
bool *ok)
155 if (QDomImplementationPrivate::invalidDataPolicy == QDomImplementation::AcceptInvalidChars) {
161 QStringIterator it(data);
162 while (it.hasNext()) {
163 const char32_t c = it.next(QChar::Null);
164 if (QXmlUtils::isChar(c)) {
165 result.append(QChar::fromUcs4(c));
166 }
else if (QDomImplementationPrivate::invalidDataPolicy == QDomImplementation::ReturnNullNode) {
179static QString fixedComment(
const QString &data,
bool *ok)
181 if (QDomImplementationPrivate::invalidDataPolicy == QDomImplementation::AcceptInvalidChars) {
186 QString fixedData = fixedCharData(data, ok);
191 qsizetype idx = fixedData.indexOf(
"--"_L1);
194 if (QDomImplementationPrivate::invalidDataPolicy == QDomImplementation::ReturnNullNode) {
198 fixedData.remove(idx, 2);
208static QString fixedCDataSection(
const QString &data,
bool *ok)
210 if (QDomImplementationPrivate::invalidDataPolicy == QDomImplementation::AcceptInvalidChars) {
215 QString fixedData = fixedCharData(data, ok);
220 qsizetype idx = fixedData.indexOf(
"]]>"_L1);
223 if (QDomImplementationPrivate::invalidDataPolicy == QDomImplementation::ReturnNullNode) {
227 fixedData.remove(idx, 3);
236static QString fixedPIData(
const QString &data,
bool *ok)
238 if (QDomImplementationPrivate::invalidDataPolicy == QDomImplementation::AcceptInvalidChars) {
243 QString fixedData = fixedCharData(data, ok);
248 qsizetype idx = fixedData.indexOf(
"?>"_L1);
251 if (QDomImplementationPrivate::invalidDataPolicy == QDomImplementation::ReturnNullNode) {
255 fixedData.remove(idx, 2);
265static QString fixedPubidLiteral(
const QString &data,
bool *ok)
267 if (QDomImplementationPrivate::invalidDataPolicy == QDomImplementation::AcceptInvalidChars) {
274 if (QXmlUtils::isPublicID(data))
276 else if (QDomImplementationPrivate::invalidDataPolicy == QDomImplementation::ReturnNullNode) {
281 if (result.indexOf(u'\'') != -1 && result.indexOf(u'"') != -1) {
282 if (QDomImplementationPrivate::invalidDataPolicy == QDomImplementation::ReturnNullNode) {
286 result.remove(u'\'');
297static QString fixedSystemLiteral(
const QString &data,
bool *ok)
299 if (QDomImplementationPrivate::invalidDataPolicy == QDomImplementation::AcceptInvalidChars) {
304 QString result = data;
306 if (result.indexOf(u'\'') != -1 && result.indexOf(u'"') != -1) {
307 if (QDomImplementationPrivate::invalidDataPolicy == QDomImplementation::ReturnNullNode) {
311 result.remove(u'\'');
320
321
322
323
325QDomImplementationPrivate* QDomImplementationPrivate::clone()
327 return new QDomImplementationPrivate;
331
332
333
334
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
370
371
372QDomImplementation::QDomImplementation()
378
379
380QDomImplementation::QDomImplementation(
const QDomImplementation &implementation)
381 : impl(implementation.impl)
387QDomImplementation::QDomImplementation(QDomImplementationPrivate *pimpl)
396
397
398QDomImplementation& QDomImplementation::operator=(
const QDomImplementation &other)
401 other.impl->ref.ref();
402 if (impl && !impl->ref.deref())
409
410
411
412bool QDomImplementation::operator==(
const QDomImplementation &other)
const
414 return impl == other.impl;
418
419
420
421bool QDomImplementation::operator!=(
const QDomImplementation &other)
const
423 return !operator==(other);
427
428
429QDomImplementation::~QDomImplementation()
431 if (impl && !impl->ref.deref())
436
437
438
439
440
441
442
443
444
445bool QDomImplementation::hasFeature(
const QString& feature,
const QString& version)
const
447 if (feature ==
"XML"_L1) {
448 if (version.isEmpty() || version ==
"1.0"_L1)
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487QDomDocumentType QDomImplementation::createDocumentType(
const QString& qName,
const QString& publicId,
const QString& systemId)
490 QString fixedName = fixedXmlName(qName, &ok,
true);
492 return QDomDocumentType();
494 QString fixedPublicId = fixedPubidLiteral(publicId, &ok);
496 return QDomDocumentType();
498 QString fixedSystemId = fixedSystemLiteral(systemId, &ok);
500 return QDomDocumentType();
502 QDomDocumentTypePrivate *dt =
new QDomDocumentTypePrivate(
nullptr);
503 dt->name = fixedName;
504 if (systemId.isNull()) {
505 dt->publicId.clear();
506 dt->systemId.clear();
508 dt->publicId = std::move(fixedPublicId);
509 dt->systemId = std::move(fixedSystemId);
512 return QDomDocumentType(dt);
516
517
518
519
520QDomDocument QDomImplementation::createDocument(
const QString& nsURI,
const QString& qName,
const QDomDocumentType& doctype)
522 QDomDocument doc(doctype);
523 QDomElement root = doc.createElementNS(nsURI, qName);
525 return QDomDocument();
526 doc.appendChild(root);
531
532
533
534bool QDomImplementation::isNull()
536 return (impl ==
nullptr);
540
541
542
543
544
545
546
547
548
549
550
551
552
553
556
557
558
559
560
561
562
563
564
565
566
569
570
571
572
573
574
575
576
578QDomImplementation::InvalidDataPolicy QDomImplementation::invalidDataPolicy()
580 return QDomImplementationPrivate::invalidDataPolicy;
584
585
586
587
588
589
590
591
592
593
594
595
596
598void QDomImplementation::setInvalidDataPolicy(InvalidDataPolicy policy)
600 QDomImplementationPrivate::invalidDataPolicy = policy;
604
605
606
607
609QDomNodeListPrivate::QDomNodeListPrivate(QDomNodePrivate *n_impl) : ref(1)
613 node_impl->ref.ref();
617QDomNodeListPrivate::QDomNodeListPrivate(QDomNodePrivate *n_impl,
const QString &name) :
622 node_impl->ref.ref();
627QDomNodeListPrivate::QDomNodeListPrivate(QDomNodePrivate *n_impl,
const QString &_nsURI,
const QString &localName) :
632 node_impl->ref.ref();
638QDomNodeListPrivate::~QDomNodeListPrivate()
640 if (node_impl && !node_impl->ref.deref())
644bool QDomNodeListPrivate::operator==(
const QDomNodeListPrivate &other)
const noexcept
646 return (node_impl == other.node_impl) && (tagname == other.tagname);
649void QDomNodeListPrivate::createList()
const
655 const QDomDocumentPrivate *
const doc = node_impl->ownerDocument();
656 if (doc && timestamp != doc->nodeListTime)
657 timestamp = doc->nodeListTime;
658 forEachNode([&](QDomNodePrivate *p){ list.append(p); });
662
663
664
665
666bool QDomNodeListPrivate::checkNode(QDomNodePrivate *p)
const
668 return p && p->isElement() && (nsURI.isNull()
669 ? p->nodeName() == tagname
670 : p->name == tagname && p->namespaceURI == nsURI);
674
675
676
677
678
679
680
681
682QDomNodePrivate *QDomNodeListPrivate::findNextInOrder(QDomNodePrivate *p)
const
687 if (tagname.isNull()) {
690 else if (p && p->next)
694 if (p == node_impl) {
699 while (p && p != node_impl) {
702 }
else if (p->next) {
706 while (p && p != node_impl && !p->next)
708 if (p && p != node_impl)
718
719
720
721
722
723QDomNodePrivate *QDomNodeListPrivate::findPrevInOrder(QDomNodePrivate *p)
const
728 if (tagname.isNull() && p == node_impl)
730 if (tagname.isNull())
735 if (p == node_impl) {
757void QDomNodeListPrivate::forEachNode(qxp::function_ref<
void(QDomNodePrivate*)> yield)
const
762 QDomNodePrivate *current = findNextInOrder(node_impl);
763 while (current && current != node_impl) {
765 current = findNextInOrder(current);
769bool QDomNodeListPrivate::maybeCreateList()
const
774 const QDomDocumentPrivate *
const doc = node_impl->ownerDocument();
775 if (!doc || timestamp != doc->nodeListTime)
781QDomNodePrivate *QDomNodeListPrivate::item(
int index)
783 if (!maybeCreateList() || index >= list.size() || index < 0)
786 return list.at(index);
789int QDomNodeListPrivate::length()
const
791 if (!maybeCreateList())
797int QDomNodeListPrivate::noexceptLength()
const noexcept
800 forEachNode([&](QDomNodePrivate*){ ++count; });
805
806
807
808
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
836
837
838QDomNodeList::QDomNodeList()
843QDomNodeList::QDomNodeList(QDomNodeListPrivate *pimpl)
849
850
851QDomNodeList::QDomNodeList(
const QDomNodeList &nodeList)
852 : impl(nodeList.impl)
859
860
861QDomNodeList& QDomNodeList::operator=(
const QDomNodeList &other)
864 other.impl->ref.ref();
865 if (impl && !impl->ref.deref())
872
873
874
875
876
877bool comparesEqual(
const QDomNodeList &lhs,
const QDomNodeList &rhs)
noexcept
879 if (lhs.impl == rhs.impl)
881 if (!lhs.impl || !rhs.impl)
883 return *lhs.impl == *rhs.impl;
887
888
889
890
891
894
895
896QDomNodeList::~QDomNodeList()
898 if (impl && !impl->ref.deref())
903
904
905
906
907
908
909
910
911QDomNode QDomNodeList::item(
int index)
const
916 return QDomNode(impl->item(index));
920
921
922int QDomNodeList::length()
const
926 return impl->length();
930
931
932int QDomNodeList::noexceptLength()
const noexcept
936 return impl->noexceptLength();
940
941
942
943
944
947
948
949
950
953
954
955
956
959
960
961
962
963
964
965
966
967
970
971
972
973
974
975
976
977
978
979
982
983
984
985
986
987
988
989
990
991
992
993
994
995
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1017QDomNodeList::It::It(
const QDomNodeListPrivate *lp,
bool start)
noexcept
1020 if (!lp || !lp->node_impl)
1023 current = lp->findNextInOrder(lp->node_impl);
1025 current = lp->node_impl;
1028QDomNodePrivate *QDomNodeList::It::findNextInOrder(
const QDomNodeListPrivate *parent, QDomNodePrivate *current)
1030 return parent->findNextInOrder(current);
1033QDomNodePrivate *QDomNodeList::It::findPrevInOrder(
const QDomNodeListPrivate *parent, QDomNodePrivate *current)
1035 return parent->findPrevInOrder(current);
1039
1040
1041
1042
1044inline void QDomNodePrivate::setOwnerDocument(QDomDocumentPrivate *doc)
1050QDomNodePrivate::QDomNodePrivate(QDomDocumentPrivate *doc, QDomNodePrivate *par) : ref(1)
1055 setOwnerDocument(doc);
1060 createdWithDom1Interface =
true;
1065QDomNodePrivate::QDomNodePrivate(QDomNodePrivate *n,
bool deep) : ref(1)
1067 setOwnerDocument(n->ownerDocument());
1076 namespaceURI = n->namespaceURI;
1077 createdWithDom1Interface = n->createdWithDom1Interface;
1084 for (QDomNodePrivate* x = n->first; x; x = x->next)
1085 appendChild(x->cloneNode(
true));
1088QDomNodePrivate::~QDomNodePrivate()
1090 QDomNodePrivate *p =
this;
1094 if (QDomNodePrivate *c = p->first) {
1103 delete std::exchange(p, p->parent());
1108void QDomNodePrivate::clear()
1110 QDomNodePrivate* p = first;
1115 if (!p->ref.deref())
1123QDomNodePrivate* QDomNodePrivate::namedItem(
const QString &n)
1125 QDomNodePrivate* p = first;
1127 if (p->nodeName() == n)
1135QDomNodePrivate* QDomNodePrivate::insertBefore(QDomNodePrivate* newChild, QDomNodePrivate* refChild)
1142 if (newChild == refChild)
1146 if (refChild && refChild->parent() !=
this)
1150 QDomDocumentPrivate *
const doc = ownerDocument();
1152 doc->nodeListTime++;
1156 if (newChild->isDocumentFragment()) {
1158 if (newChild->first ==
nullptr)
1162 QDomNodePrivate* n = newChild->first;
1169 if (!refChild || refChild->prev ==
nullptr) {
1171 first->prev = newChild->last;
1172 newChild->last->next = first;
1174 last = newChild->last;
1175 first = newChild->first;
1178 newChild->last->next = refChild;
1179 newChild->first->prev = refChild->prev;
1180 refChild->prev->next = newChild->first;
1181 refChild->prev = newChild->last;
1188 newChild->first =
nullptr;
1189 newChild->last =
nullptr;
1195 newChild->ref.ref();
1197 if (newChild->parent())
1198 newChild->parent()->removeChild(newChild);
1200 newChild->setParent(
this);
1204 first->prev = newChild;
1205 newChild->next = first;
1212 if (refChild->prev ==
nullptr) {
1214 first->prev = newChild;
1215 newChild->next = first;
1222 newChild->next = refChild;
1223 newChild->prev = refChild->prev;
1224 refChild->prev->next = newChild;
1225 refChild->prev = newChild;
1230QDomNodePrivate* QDomNodePrivate::insertAfter(QDomNodePrivate* newChild, QDomNodePrivate* refChild)
1237 if (newChild == refChild)
1241 if (refChild && refChild->parent() !=
this)
1245 QDomDocumentPrivate *
const doc = ownerDocument();
1247 doc->nodeListTime++;
1251 if (newChild->isDocumentFragment()) {
1253 if (newChild->first ==
nullptr)
1257 QDomNodePrivate* n = newChild->first;
1264 if (!refChild || refChild->next ==
nullptr) {
1266 last->next = newChild->first;
1267 newChild->first->prev = last;
1269 first = newChild->first;
1270 last = newChild->last;
1272 newChild->first->prev = refChild;
1273 newChild->last->next = refChild->next;
1274 refChild->next->prev = newChild->last;
1275 refChild->next = newChild->first;
1282 newChild->first =
nullptr;
1283 newChild->last =
nullptr;
1288 if (newChild->parent())
1289 newChild->parent()->removeChild(newChild);
1293 newChild->ref.ref();
1295 newChild->setParent(
this);
1300 last->next = newChild;
1301 newChild->prev = last;
1308 if (refChild->next ==
nullptr) {
1310 last->next = newChild;
1311 newChild->prev = last;
1318 newChild->prev = refChild;
1319 newChild->next = refChild->next;
1320 refChild->next->prev = newChild;
1321 refChild->next = newChild;
1326QDomNodePrivate* QDomNodePrivate::replaceChild(QDomNodePrivate* newChild, QDomNodePrivate* oldChild)
1328 if (!newChild || !oldChild)
1330 if (oldChild->parent() !=
this)
1332 if (newChild == oldChild)
1336 QDomDocumentPrivate *
const doc = ownerDocument();
1338 doc->nodeListTime++;
1342 if (newChild->isDocumentFragment()) {
1344 if (newChild->first ==
nullptr)
1348 QDomNodePrivate* n = newChild->first;
1356 oldChild->next->prev = newChild->last;
1358 oldChild->prev->next = newChild->first;
1360 newChild->last->next = oldChild->next;
1361 newChild->first->prev = oldChild->prev;
1363 if (first == oldChild)
1364 first = newChild->first;
1365 if (last == oldChild)
1366 last = newChild->last;
1368 oldChild->setNoParent();
1369 oldChild->next =
nullptr;
1370 oldChild->prev =
nullptr;
1376 newChild->first =
nullptr;
1377 newChild->last =
nullptr;
1380 oldChild->ref.deref();
1387 newChild->ref.ref();
1390 if (newChild->parent())
1391 newChild->parent()->removeChild(newChild);
1393 newChild->setParent(
this);
1396 oldChild->next->prev = newChild;
1398 oldChild->prev->next = newChild;
1400 newChild->next = oldChild->next;
1401 newChild->prev = oldChild->prev;
1403 if (first == oldChild)
1405 if (last == oldChild)
1408 oldChild->setNoParent();
1409 oldChild->next =
nullptr;
1410 oldChild->prev =
nullptr;
1413 oldChild->ref.deref();
1418QDomNodePrivate* QDomNodePrivate::removeChild(QDomNodePrivate* oldChild)
1421 if (oldChild->parent() !=
this)
1425 QDomDocumentPrivate *
const doc = ownerDocument();
1427 doc->nodeListTime++;
1431 if (oldChild->next ==
nullptr && oldChild->prev ==
nullptr && first != oldChild)
1435 oldChild->next->prev = oldChild->prev;
1437 oldChild->prev->next = oldChild->next;
1439 if (last == oldChild)
1440 last = oldChild->prev;
1441 if (first == oldChild)
1442 first = oldChild->next;
1444 oldChild->setNoParent();
1445 oldChild->next =
nullptr;
1446 oldChild->prev =
nullptr;
1449 oldChild->ref.deref();
1454QDomNodePrivate* QDomNodePrivate::appendChild(QDomNodePrivate* newChild)
1457 return insertAfter(newChild,
nullptr);
1460QDomDocumentPrivate* QDomNodePrivate::ownerDocument()
1462 QDomNodePrivate* p =
this;
1463 while (p && !p->isDocument()) {
1465 return static_cast<QDomDocumentPrivate *>(p->ownerNode);
1469 return static_cast<QDomDocumentPrivate *>(p);
1472QDomNodePrivate* QDomNodePrivate::cloneNode(
bool deep)
1474 QDomNodePrivate* p =
new QDomNodePrivate(
this, deep);
1480static void qNormalizeNode(QDomNodePrivate* n)
1482 QDomNodePrivate* p = n->first;
1483 QDomTextPrivate* t =
nullptr;
1488 QDomNodePrivate* tmp = p->next;
1489 t->appendData(p->nodeValue());
1493 t =
static_cast<QDomTextPrivate *>(p);
1502void QDomNodePrivate::normalize()
1506 qNormalizeNode(
this);
1509void QDomNodePrivate::saveSubTree(
const QDomNodePrivate *n, QTextStream &s,
1510 int depth,
int indent)
const
1515 const QDomNodePrivate *root = n->first;
1516 n->save(s, depth, indent);
1518 const int branchDepth = depth + 1;
1521 root->save(s, layerDepth + branchDepth, indent);
1528 root->afterSave(s, layerDepth + branchDepth, indent);
1529 const QDomNodePrivate *prev = root;
1532 while (!root && (layerDepth > 0)) {
1533 root = prev->parent();
1535 root->afterSave(s, layerDepth + branchDepth, indent);
1540 Q_ASSERT(layerDepth == 0);
1542 n->afterSave(s, depth, indent);
1545void QDomNodePrivate::setLocation(
int lineNumber,
int columnNumber)
1547 this->lineNumber = lineNumber;
1548 this->columnNumber = columnNumber;
1552
1553
1554
1555
1557#define IMPL static_cast<QDomNodePrivate *>(impl)
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1644
1645
1652
1653
1654
1655
1656
1657
1658QDomNode::QDomNode(
const QDomNode &node)
1666
1667
1668QDomNode::QDomNode(QDomNodePrivate *pimpl)
1676
1677
1678
1679
1680
1681
1682QDomNode& QDomNode::operator=(
const QDomNode &other)
1685 other.impl->ref.ref();
1686 if (impl && !impl->ref.deref())
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712bool QDomNode::operator==(
const QDomNode &other)
const
1714 return impl == other.impl;
1718
1719
1720
1721bool QDomNode::operator!=(
const QDomNode &other)
const
1723 return !operator==(other);
1727
1728
1729QDomNode::~QDomNode()
1731 if (impl && !impl->ref.deref())
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764QString QDomNode::nodeName()
const
1769 if (!IMPL->prefix.isEmpty())
1770 return IMPL->prefix + u':' + IMPL->name;
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792QString QDomNode::nodeValue()
const
1800
1801
1802
1803
1804void QDomNode::setNodeValue(
const QString& value)
1807 IMPL->setNodeValue(value);
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1831
1832
1833
1834
1835
1836
1837
1838QDomNode::NodeType QDomNode::nodeType()
const
1841 return QDomNode::BaseNode;
1842 return IMPL->nodeType();
1846
1847
1848
1849QDomNode QDomNode::parentNode()
const
1853 return QDomNode(IMPL->parent());
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874QDomNodeList QDomNode::childNodes()
const
1877 return QDomNodeList();
1878 return QDomNodeList(
new QDomNodeListPrivate(impl));
1882
1883
1884
1885
1886
1887
1888QDomNode QDomNode::firstChild()
const
1892 return QDomNode(IMPL->first);
1896
1897
1898
1899
1900
1901
1902QDomNode QDomNode::lastChild()
const
1906 return QDomNode(IMPL->last);
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922QDomNode QDomNode::previousSibling()
const
1926 return QDomNode(IMPL->prev);
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942QDomNode QDomNode::nextSibling()
const
1946 return QDomNode(IMPL->next);
1952
1953
1954
1955
1956
1957
1958QDomNamedNodeMap QDomNode::attributes()
const
1960 if (!impl || !impl->isElement())
1961 return QDomNamedNodeMap();
1963 return QDomNamedNodeMap(
static_cast<QDomElementPrivate *>(impl)->attributes());
1967
1968
1969QDomDocument QDomNode::ownerDocument()
const
1972 return QDomDocument();
1973 return QDomDocument(IMPL->ownerDocument());
1977
1978
1979
1980
1981
1982
1983
1984QDomNode QDomNode::cloneNode(
bool deep)
const
1988 return QDomNode(IMPL->cloneNode(deep));
1992
1993
1994
1995
1996
1997void QDomNode::normalize()
2005
2006
2007
2008
2009
2010
2011bool QDomNode::isSupported(
const QString& feature,
const QString& version)
const
2013 QDomImplementation i;
2014 return i.hasFeature(feature, version);
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029QString QDomNode::namespaceURI()
const
2033 return IMPL->namespaceURI;
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058QString QDomNode::prefix()
const
2062 return IMPL->prefix;
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079void QDomNode::setPrefix(
const QString& pre)
2081 if (!impl || IMPL->prefix.isNull())
2083 if (isAttr() || isElement())
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099QString QDomNode::localName()
const
2101 if (!impl || IMPL->createdWithDom1Interface)
2107
2108
2109
2110
2111bool QDomNode::hasAttributes()
const
2113 if (!impl || !impl->isElement())
2115 return static_cast<QDomElementPrivate *>(impl)->hasAttributes();
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139QDomNode QDomNode::insertBefore(
const QDomNode& newChild,
const QDomNode& refChild)
2143 return QDomNode(IMPL->insertBefore(newChild.impl, refChild.impl));
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167QDomNode QDomNode::insertAfter(
const QDomNode& newChild,
const QDomNode& refChild)
2171 return QDomNode(IMPL->insertAfter(newChild.impl, refChild.impl));
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189QDomNode QDomNode::replaceChild(
const QDomNode& newChild,
const QDomNode& oldChild)
2191 if (!impl || !newChild.impl || !oldChild.impl)
2193 return QDomNode(IMPL->replaceChild(newChild.impl, oldChild.impl));
2197
2198
2199
2200
2201
2202
2203
2204QDomNode QDomNode::removeChild(
const QDomNode& oldChild)
2209 if (oldChild.isNull())
2212 return QDomNode(IMPL->removeChild(oldChild.impl));
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239QDomNode QDomNode::appendChild(
const QDomNode& newChild)
2242 qWarning(
"Calling appendChild() on a null node does nothing.");
2245 return QDomNode(IMPL->appendChild(newChild.impl));
2249
2250
2251
2252bool QDomNode::hasChildNodes()
const
2256 return IMPL->first !=
nullptr;
2260
2261
2262
2263bool QDomNode::isNull()
const
2265 return (impl ==
nullptr);
2269
2270
2271
2272
2273
2274void QDomNode::clear()
2276 if (impl && !impl->ref.deref())
2282
2283
2284
2285
2286
2287
2288
2289
2290QDomNode QDomNode::namedItem(
const QString& name)
const
2294 return QDomNode(impl->namedItem(name));
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322void QDomNode::save(QTextStream& stream,
int indent, EncodingPolicy encodingPolicy)
const
2328 static_cast<
const QDomDocumentPrivate *>(impl)->saveDocument(stream, indent, encodingPolicy);
2330 IMPL->saveSubTree(IMPL, stream, 1, indent);
2334
2335
2336
2337
2338
2339QTextStream& operator<<(QTextStream& str,
const QDomNode& node)
2347
2348
2349
2350
2351
2352
2353
2354
2355bool QDomNode::isAttr()
const
2358 return impl->isAttr();
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372bool QDomNode::isCDATASection()
const
2375 return impl->isCDATASection();
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389bool QDomNode::isDocumentFragment()
const
2392 return impl->isDocumentFragment();
2397
2398
2399
2400
2401
2402
2403
2404bool QDomNode::isDocument()
const
2407 return impl->isDocument();
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421bool QDomNode::isDocumentType()
const
2424 return impl->isDocumentType();
2429
2430
2431
2432
2433
2434
2435
2436bool QDomNode::isElement()
const
2439 return impl->isElement();
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453bool QDomNode::isEntityReference()
const
2456 return impl->isEntityReference();
2461
2462
2463
2464
2465
2466
2467
2468bool QDomNode::isText()
const
2471 return impl->isText();
2476
2477
2478
2479
2480
2481
2482
2483bool QDomNode::isEntity()
const
2486 return impl->isEntity();
2491
2492
2493
2494
2495
2496
2497
2498bool QDomNode::isNotation()
const
2501 return impl->isNotation();
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515bool QDomNode::isProcessingInstruction()
const
2518 return impl->isProcessingInstruction();
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532bool QDomNode::isCharacterData()
const
2535 return impl->isCharacterData();
2540
2541
2542
2543
2544
2545
2546
2547bool QDomNode::isComment()
const
2550 return impl->isComment();
2557
2558
2559
2560
2561
2562
2563
2564
2566QDomElement QDomNode::firstChildElement(
const QString &tagName,
const QString &namespaceURI)
const
2568 for (QDomNode child = firstChild(); !child.isNull(); child = child.nextSibling()) {
2569 if (child.isElement() && (namespaceURI.isEmpty() || child.namespaceURI() == namespaceURI)) {
2570 QDomElement elt = child.toElement();
2571 if (tagName.isEmpty() || elt.tagName() == tagName)
2575 return QDomElement();
2579
2580
2581
2582
2583
2584
2585
2586
2588QDomElement QDomNode::lastChildElement(
const QString &tagName,
const QString &namespaceURI)
const
2590 for (QDomNode child = lastChild(); !child.isNull(); child = child.previousSibling()) {
2591 if (child.isElement() && (namespaceURI.isEmpty() || child.namespaceURI() == namespaceURI)) {
2592 QDomElement elt = child.toElement();
2593 if (tagName.isEmpty() || elt.tagName() == tagName)
2597 return QDomElement();
2601
2602
2603
2604
2605
2606
2607
2608
2609
2611QDomElement QDomNode::nextSiblingElement(
const QString &tagName,
const QString &namespaceURI)
const
2613 for (QDomNode sib = nextSibling(); !sib.isNull(); sib = sib.nextSibling()) {
2614 if (sib.isElement() && (namespaceURI.isEmpty() || sib.namespaceURI() == namespaceURI)) {
2615 QDomElement elt = sib.toElement();
2616 if (tagName.isEmpty() || elt.tagName() == tagName)
2620 return QDomElement();
2624
2625
2626
2627
2628
2629
2630
2631
2632
2634QDomElement QDomNode::previousSiblingElement(
const QString &tagName,
const QString &namespaceURI)
const
2636 for (QDomNode sib = previousSibling(); !sib.isNull(); sib = sib.previousSibling()) {
2637 if (sib.isElement() && (namespaceURI.isEmpty() || sib.namespaceURI() == namespaceURI)) {
2638 QDomElement elt = sib.toElement();
2639 if (tagName.isEmpty() || elt.tagName() == tagName)
2643 return QDomElement();
2647
2648
2649
2650
2651
2652
2653
2654
2655int QDomNode::lineNumber()
const
2657 return impl ? impl->lineNumber : -1;
2661
2662
2663
2664
2665
2666
2667
2668
2669int QDomNode::columnNumber()
const
2671 return impl ? impl->columnNumber : -1;
2676
2677
2678
2679
2681QDomNamedNodeMapPrivate::QDomNamedNodeMapPrivate(QDomNodePrivate *pimpl)
2685 , appendToParent(
false)
2689QDomNamedNodeMapPrivate::~QDomNamedNodeMapPrivate()
2694QDomNamedNodeMapPrivate* QDomNamedNodeMapPrivate::clone(QDomNodePrivate *pimpl)
2696 std::unique_ptr<QDomNamedNodeMapPrivate> m(
new QDomNamedNodeMapPrivate(pimpl));
2697 m->readonly = readonly;
2698 m->appendToParent = appendToParent;
2700 auto it = map.constBegin();
2701 for (; it != map.constEnd(); ++it) {
2702 QDomNodePrivate *new_node = it.value()->cloneNode();
2703 new_node->setParent(pimpl);
2704 m->setNamedItem(new_node);
2712void QDomNamedNodeMapPrivate::clearMap()
2715 if (!appendToParent) {
2716 auto it = map.constBegin();
2717 for (; it != map.constEnd(); ++it)
2718 if (!it.value()->ref.deref())
2724QDomNodePrivate* QDomNamedNodeMapPrivate::namedItem(
const QString& name)
const
2726 auto it = map.find(name);
2727 return it == map.end() ?
nullptr : it.value();
2730QDomNodePrivate* QDomNamedNodeMapPrivate::namedItemNS(
const QString& nsURI,
const QString& localName)
const
2732 auto it = map.constBegin();
2734 for (; it != map.constEnd(); ++it) {
2736 if (!n->prefix.isNull()) {
2738 if (n->namespaceURI == nsURI && n->name == localName)
2745QDomNodePrivate* QDomNamedNodeMapPrivate::setNamedItem(QDomNodePrivate* arg)
2747 if (readonly || !arg)
2751 return parent->appendChild(arg);
2753 QDomNodePrivate *n = map.value(arg->nodeName());
2756 map.insert(arg->nodeName(), arg);
2760QDomNodePrivate* QDomNamedNodeMapPrivate::setNamedItemNS(QDomNodePrivate* arg)
2762 if (readonly || !arg)
2766 return parent->appendChild(arg);
2768 if (!arg->prefix.isNull()) {
2770 QDomNodePrivate *n = namedItemNS(arg->namespaceURI, arg->name);
2773 map.insert(arg->nodeName(), arg);
2777 return setNamedItem(arg);
2781QDomNodePrivate* QDomNamedNodeMapPrivate::removeNamedItem(
const QString& name)
2786 QDomNodePrivate* p = namedItem(name);
2790 return parent->removeChild(p);
2792 map.remove(p->nodeName());
2798QDomNodePrivate* QDomNamedNodeMapPrivate::item(
int index)
const
2800 if (index >= length() || index < 0)
2802 return std::next(map.begin(), index).value();
2805int QDomNamedNodeMapPrivate::length()
const
2810bool QDomNamedNodeMapPrivate::contains(
const QString& name)
const
2812 return map.contains(name);
2815bool QDomNamedNodeMapPrivate::containsNS(
const QString& nsURI,
const QString & localName)
const
2817 return namedItemNS(nsURI, localName) !=
nullptr;
2821
2822
2823
2824
2826#define IMPL static_cast<QDomNamedNodeMapPrivate *>(impl)
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2867
2868
2869QDomNamedNodeMap::QDomNamedNodeMap()
2875
2876
2877QDomNamedNodeMap::QDomNamedNodeMap(
const QDomNamedNodeMap &namedNodeMap)
2878 : impl(namedNodeMap.impl)
2884QDomNamedNodeMap::QDomNamedNodeMap(QDomNamedNodeMapPrivate *pimpl)
2892
2893
2894QDomNamedNodeMap& QDomNamedNodeMap::operator=(
const QDomNamedNodeMap &other)
2897 other.impl->ref.ref();
2898 if (impl && !impl->ref.deref())
2905
2906
2907
2908bool QDomNamedNodeMap::operator==(
const QDomNamedNodeMap &other)
const
2910 return impl == other.impl;
2914
2915
2916
2917bool QDomNamedNodeMap::operator!=(
const QDomNamedNodeMap &other)
const
2919 return !operator==(other);
2923
2924
2925QDomNamedNodeMap::~QDomNamedNodeMap()
2927 if (impl && !impl->ref.deref())
2932
2933
2934
2935
2936
2937
2938
2939
2940QDomNode QDomNamedNodeMap::namedItem(
const QString& name)
const
2944 return QDomNode(IMPL->namedItem(name));
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957QDomNode QDomNamedNodeMap::setNamedItem(
const QDomNode& newNode)
2961 return QDomNode(IMPL->setNamedItem(
static_cast<QDomNodePrivate *>(newNode.impl)));
2965
2966
2967
2968
2969
2970
2971
2972
2973QDomNode QDomNamedNodeMap::removeNamedItem(
const QString& name)
2977 return QDomNode(IMPL->removeNamedItem(name));
2981
2982
2983
2984
2985
2986
2987
2988QDomNode QDomNamedNodeMap::item(
int index)
const
2992 return QDomNode(IMPL->item(index));
2996
2997
2998
2999
3000
3001
3002
3003
3004QDomNode QDomNamedNodeMap::namedItemNS(
const QString& nsURI,
const QString& localName)
const
3008 return QDomNode(IMPL->namedItemNS(nsURI, localName));
3012
3013
3014
3015
3016
3017
3018
3019QDomNode QDomNamedNodeMap::setNamedItemNS(
const QDomNode& newNode)
3023 return QDomNode(IMPL->setNamedItemNS(
static_cast<QDomNodePrivate *>(newNode.impl)));
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037QDomNode QDomNamedNodeMap::removeNamedItemNS(
const QString& nsURI,
const QString& localName)
3041 QDomNodePrivate *n = IMPL->namedItemNS(nsURI, localName);
3044 return QDomNode(IMPL->removeNamedItem(n->name));
3048
3049
3050
3051
3052int QDomNamedNodeMap::length()
const
3056 return IMPL->length();
3060
3061
3062
3063
3064
3067
3068
3069
3070
3073
3074
3075
3076
3079
3080
3081
3082
3083
3084
3085
3086bool QDomNamedNodeMap::contains(
const QString& name)
const
3090 return IMPL->contains(name);
3096
3097
3098
3099
3101QDomDocumentTypePrivate::QDomDocumentTypePrivate(QDomDocumentPrivate* doc, QDomNodePrivate* parent)
3102 : QDomNodePrivate(doc, parent)
3107QDomDocumentTypePrivate::QDomDocumentTypePrivate(QDomDocumentTypePrivate* n,
bool deep)
3108 : QDomNodePrivate(n, deep)
3112 QDomNodePrivate* p = first;
3116 entities->map.insert(p->nodeName(), p);
3117 if (p->isNotation())
3119 notations->map.insert(p->nodeName(), p);
3124QDomDocumentTypePrivate::~QDomDocumentTypePrivate()
3126 if (!entities->ref.deref())
3128 if (!notations->ref.deref())
3132void QDomDocumentTypePrivate::init()
3134 entities =
new QDomNamedNodeMapPrivate(
this);
3136 notations =
new QDomNamedNodeMapPrivate(
this);
3139 internalSubset.clear();
3141 entities->setAppendToParent(
true);
3142 notations->setAppendToParent(
true);
3149QDomNodePrivate* QDomDocumentTypePrivate::cloneNode(
bool deep)
3151 QDomNodePrivate* p =
new QDomDocumentTypePrivate(
this, deep);
3157QDomNodePrivate* QDomDocumentTypePrivate::insertBefore(QDomNodePrivate* newChild, QDomNodePrivate* refChild)
3160 QDomNodePrivate* p = QDomNodePrivate::insertBefore(newChild, refChild);
3162 if (p && p->isEntity())
3163 entities->map.insert(p->nodeName(), p);
3164 else if (p && p->isNotation())
3165 notations->map.insert(p->nodeName(), p);
3170QDomNodePrivate* QDomDocumentTypePrivate::insertAfter(QDomNodePrivate* newChild, QDomNodePrivate* refChild)
3173 QDomNodePrivate* p = QDomNodePrivate::insertAfter(newChild, refChild);
3175 if (p && p->isEntity())
3176 entities->map.insert(p->nodeName(), p);
3177 else if (p && p->isNotation())
3178 notations->map.insert(p->nodeName(), p);
3183QDomNodePrivate* QDomDocumentTypePrivate::replaceChild(QDomNodePrivate* newChild, QDomNodePrivate* oldChild)
3186 QDomNodePrivate* p = QDomNodePrivate::replaceChild(newChild, oldChild);
3189 if (oldChild && oldChild->isEntity())
3190 entities->map.remove(oldChild->nodeName());
3191 else if (oldChild && oldChild->isNotation())
3192 notations->map.remove(oldChild->nodeName());
3195 entities->map.insert(p->nodeName(), p);
3196 else if (p->isNotation())
3197 notations->map.insert(p->nodeName(), p);
3203QDomNodePrivate* QDomDocumentTypePrivate::removeChild(QDomNodePrivate* oldChild)
3206 QDomNodePrivate* p = QDomNodePrivate::removeChild( oldChild);
3208 if (p && p->isEntity())
3209 entities->map.remove(p->nodeName());
3210 else if (p && p->isNotation())
3211 notations->map.remove(p ->nodeName());
3216QDomNodePrivate* QDomDocumentTypePrivate::appendChild(QDomNodePrivate* newChild)
3218 return insertAfter(newChild,
nullptr);
3221static QString quotedValue(
const QString &data)
3223 QChar quote = data.indexOf(u'\'') == -1 ? u'\'' : u'"';
3224 return quote + data + quote;
3227void QDomDocumentTypePrivate::save(QTextStream& s,
int,
int indent)
const
3232 s <<
"<!DOCTYPE " << name;
3234 if (!publicId.isNull()) {
3235 s <<
" PUBLIC " << quotedValue(publicId);
3236 if (!systemId.isNull()) {
3237 s <<
' ' << quotedValue(systemId);
3239 }
else if (!systemId.isNull()) {
3240 s <<
" SYSTEM " << quotedValue(systemId);
3243 if (entities->length()>0 || notations->length()>0) {
3244 s <<
" [" << Qt::endl;
3246 auto it2 = notations->map.constBegin();
3247 for (; it2 != notations->map.constEnd(); ++it2)
3248 it2.value()->saveSubTree(it2.value(), s, 0, indent);
3250 auto it = entities->map.constBegin();
3251 for (; it != entities->map.constEnd(); ++it)
3252 it.value()->saveSubTree(it.value(), s, 0, indent);
3257 s <<
'>' << Qt::endl;
3261
3262
3263
3264
3266#define IMPL static_cast<QDomDocumentTypePrivate *>(impl)
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3288
3289
3290QDomDocumentType::QDomDocumentType() : QDomNode()
3295
3296
3297
3298
3299
3300
3301QDomDocumentType::QDomDocumentType(
const QDomDocumentType &documentType)
3302 : QDomNode(documentType)
3306QDomDocumentType::QDomDocumentType(QDomDocumentTypePrivate *pimpl)
3312
3313
3314
3315
3316
3317
3318QDomDocumentType &QDomDocumentType::operator=(
const QDomDocumentType &other) =
default;
3320
3321
3322
3323
3324
3325QString QDomDocumentType::name()
const
3329 return IMPL->nodeName();
3333
3334
3335QDomNamedNodeMap QDomDocumentType::entities()
const
3338 return QDomNamedNodeMap();
3339 return QDomNamedNodeMap(IMPL->entities);
3343
3344
3345QDomNamedNodeMap QDomDocumentType::notations()
const
3348 return QDomNamedNodeMap();
3349 return QDomNamedNodeMap(IMPL->notations);
3353
3354
3355
3356
3357
3358QString QDomDocumentType::publicId()
const
3362 return IMPL->publicId;
3366
3367
3368
3369
3370
3371QString QDomDocumentType::systemId()
const
3375 return IMPL->systemId;
3379
3380
3381
3382
3383
3384QString QDomDocumentType::internalSubset()
const
3388 return IMPL->internalSubset;
3392
3393
3394
3395
3398
3399
3400
3401
3402
3403
3408
3409
3410
3411
3413QDomDocumentFragmentPrivate::QDomDocumentFragmentPrivate(QDomDocumentPrivate* doc, QDomNodePrivate* parent)
3414 : QDomNodePrivate(doc, parent)
3416 name = u"#document-fragment"_s;
3419QDomDocumentFragmentPrivate::QDomDocumentFragmentPrivate(QDomNodePrivate* n,
bool deep)
3420 : QDomNodePrivate(n, deep)
3424QDomNodePrivate* QDomDocumentFragmentPrivate::cloneNode(
bool deep)
3426 QDomNodePrivate* p =
new QDomDocumentFragmentPrivate(
this, deep);
3433
3434
3435
3436
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3464
3465
3466QDomDocumentFragment::QDomDocumentFragment()
3470QDomDocumentFragment::QDomDocumentFragment(QDomDocumentFragmentPrivate* n)
3476
3477
3478
3479
3480
3481
3482QDomDocumentFragment::QDomDocumentFragment(
const QDomDocumentFragment &documentFragment)
3483 : QDomNode(documentFragment)
3488
3489
3490
3491
3492
3493
3494QDomDocumentFragment &QDomDocumentFragment::operator=(
const QDomDocumentFragment &other) =
default;
3497
3498
3499
3500
3501
3502
3505
3506
3507
3508
3510QDomCharacterDataPrivate::QDomCharacterDataPrivate(QDomDocumentPrivate* d, QDomNodePrivate* p,
3511 const QString& data)
3512 : QDomNodePrivate(d, p)
3515 name = u"#character-data"_s;
3518QDomCharacterDataPrivate::QDomCharacterDataPrivate(QDomCharacterDataPrivate* n,
bool deep)
3519 : QDomNodePrivate(n, deep)
3523QDomNodePrivate* QDomCharacterDataPrivate::cloneNode(
bool deep)
3525 QDomNodePrivate* p =
new QDomCharacterDataPrivate(
this, deep);
3531int QDomCharacterDataPrivate::dataLength()
const
3533 return value.size();
3536QString QDomCharacterDataPrivate::substringData(
unsigned long offset,
unsigned long n)
const
3538 return value.mid(offset, n);
3541void QDomCharacterDataPrivate::insertData(
unsigned long offset,
const QString& arg)
3543 value.insert(offset, arg);
3546void QDomCharacterDataPrivate::deleteData(
unsigned long offset,
unsigned long n)
3548 value.remove(offset, n);
3551void QDomCharacterDataPrivate::replaceData(
unsigned long offset,
unsigned long n,
const QString& arg)
3553 value.replace(offset, n, arg);
3556void QDomCharacterDataPrivate::appendData(
const QString& arg)
3562
3563
3564
3565
3567#define IMPL static_cast<QDomCharacterDataPrivate *>(impl)
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3595
3596
3597QDomCharacterData::QDomCharacterData()
3602
3603
3604
3605
3606
3607
3608QDomCharacterData::QDomCharacterData(
const QDomCharacterData &characterData)
3609 : QDomNode(characterData)
3613QDomCharacterData::QDomCharacterData(QDomCharacterDataPrivate* n)
3619
3620
3621
3622
3623
3624
3625QDomCharacterData &QDomCharacterData::operator=(
const QDomCharacterData &other) =
default;
3628
3629
3630
3631
3632
3633QString QDomCharacterData::data()
const
3637 return impl->nodeValue();
3641
3642
3643void QDomCharacterData::setData(
const QString &data)
3646 impl->setNodeValue(data);
3650
3651
3652int QDomCharacterData::length()
const
3655 return IMPL->dataLength();
3660
3661
3662QString QDomCharacterData::substringData(
unsigned long offset,
unsigned long count)
3666 return IMPL->substringData(offset, count);
3670
3671
3672void QDomCharacterData::appendData(
const QString& arg)
3675 IMPL->appendData(arg);
3679
3680
3681void QDomCharacterData::insertData(
unsigned long offset,
const QString& arg)
3684 IMPL->insertData(offset, arg);
3688
3689
3690void QDomCharacterData::deleteData(
unsigned long offset,
unsigned long count)
3693 IMPL->deleteData(offset, count);
3697
3698
3699
3700void QDomCharacterData::replaceData(
unsigned long offset,
unsigned long count,
const QString& arg)
3703 IMPL->replaceData(offset, count, arg);
3707
3708
3709
3710
3711QDomNode::NodeType QDomCharacterData::nodeType()
const
3714 return CharacterDataNode;
3715 return QDomNode::nodeType();
3721
3722
3723
3724
3726QDomAttrPrivate::QDomAttrPrivate(QDomDocumentPrivate* d, QDomNodePrivate* parent,
const QString& name_)
3727 : QDomNodePrivate(d, parent)
3730 m_specified =
false;
3733QDomAttrPrivate::QDomAttrPrivate(QDomDocumentPrivate* d, QDomNodePrivate* p,
const QString& nsURI,
const QString& qName)
3734 : QDomNodePrivate(d, p)
3736 qt_split_namespace(prefix, name, qName, !nsURI.isNull());
3737 namespaceURI = nsURI;
3738 createdWithDom1Interface =
false;
3739 m_specified =
false;
3742QDomAttrPrivate::QDomAttrPrivate(QDomAttrPrivate* n,
bool deep)
3743 : QDomNodePrivate(n, deep)
3745 m_specified = n->specified();
3748void QDomAttrPrivate::setNodeValue(
const QString& v)
3751 QDomTextPrivate *t =
new QDomTextPrivate(
nullptr,
this, v);
3755 auto removed = removeChild(first);
3756 if (removed && !removed->ref.loadRelaxed())
3762QDomNodePrivate* QDomAttrPrivate::cloneNode(
bool deep)
3764 QDomNodePrivate* p =
new QDomAttrPrivate(
this, deep);
3770bool QDomAttrPrivate::specified()
const
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785static QString encodeText(
const QString &str,
3786 const bool encodeQuotes =
true,
3787 const bool performAVN =
false,
3788 const bool encodeEOLs =
false)
3791 qsizetype start = 0;
3792 auto appendToOutput = [&](qsizetype cur,
const auto &replacement)
3795 retval.reserve(str.size() + replacement.size());
3796 retval.append(QStringView(str).first(cur).sliced(start));
3800 retval.append(replacement);
3803 const qsizetype len = str.size();
3804 for (qsizetype cur = 0; cur < len; ++cur) {
3805 switch (str[cur].unicode()) {
3807 appendToOutput(cur,
"<"_L1);
3811 appendToOutput(cur,
"""_L1);
3814 appendToOutput(cur,
"&"_L1);
3817 if (cur >= 2 && str[cur - 1] == u']' && str[cur - 2] == u']')
3818 appendToOutput(cur,
">"_L1);
3821 if (performAVN || encodeEOLs)
3822 appendToOutput(cur,
"
"_L1);
3826 appendToOutput(cur,
"
"_L1);
3830 appendToOutput(cur,
"	"_L1);
3837 retval.append(QStringView(str).first(len).sliced(start));
3843void QDomAttrPrivate::save(QTextStream& s,
int,
int)
const
3845 if (namespaceURI.isNull()) {
3846 s << name <<
"=\"" << encodeText(value,
true,
true) <<
'\"';
3848 s << prefix <<
':' << name <<
"=\"" << encodeText(value,
true,
true) <<
'\"';
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3861 ownerNode->prefix != prefix) {
3862 s <<
" xmlns:" << prefix <<
"=\"" << encodeText(namespaceURI,
true,
true) <<
'\"';
3868
3869
3870
3871
3873#define IMPL static_cast<QDomAttrPrivate *>(impl)
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3911
3912
3918
3919
3920
3921
3922
3923
3924QDomAttr::QDomAttr(
const QDomAttr &attr)
3929QDomAttr::QDomAttr(QDomAttrPrivate* n)
3935
3936
3937
3938
3939
3940
3941QDomAttr &QDomAttr::operator=(
const QDomAttr &other) =
default;
3944
3945
3946QString QDomAttr::name()
const
3950 return impl->nodeName();
3954
3955
3956
3957
3958
3959bool QDomAttr::specified()
const
3963 return IMPL->specified();
3967
3968
3969
3970
3971QDomElement QDomAttr::ownerElement()
const
3973 Q_ASSERT(impl->parent());
3974 if (!impl->parent()->isElement())
3975 return QDomElement();
3976 return QDomElement(
static_cast<QDomElementPrivate *>(impl->parent()));
3980
3981
3982
3983
3984
3985QString QDomAttr::value()
const
3989 return impl->nodeValue();
3993
3994
3995
3996
3997void QDomAttr::setValue(
const QString &value)
4001 impl->setNodeValue(value);
4002 IMPL->m_specified =
true;
4006
4007
4008
4009
4014
4015
4016
4017
4019QDomElementPrivate::QDomElementPrivate(QDomDocumentPrivate* d, QDomNodePrivate* p,
4020 const QString& tagname)
4021 : QDomNodePrivate(d, p)
4024 m_attr =
new QDomNamedNodeMapPrivate(
this);
4027QDomElementPrivate::QDomElementPrivate(QDomDocumentPrivate* d, QDomNodePrivate* p,
4028 const QString& nsURI,
const QString& qName)
4029 : QDomNodePrivate(d, p)
4031 qt_split_namespace(prefix, name, qName, !nsURI.isNull());
4032 namespaceURI = nsURI;
4033 createdWithDom1Interface =
false;
4034 m_attr =
new QDomNamedNodeMapPrivate(
this);
4037QDomElementPrivate::QDomElementPrivate(QDomElementPrivate* n,
bool deep) :
4038 QDomNodePrivate(n, deep)
4040 m_attr = n->m_attr->clone(
this);
4045QDomElementPrivate::~QDomElementPrivate()
4047 if (!m_attr->ref.deref())
4051QDomNodePrivate* QDomElementPrivate::cloneNode(
bool deep)
4053 QDomNodePrivate* p =
new QDomElementPrivate(
this, deep);
4059QString QDomElementPrivate::attribute(
const QString& name_,
const QString& defValue)
const
4061 QDomNodePrivate* n = m_attr->namedItem(name_);
4065 return n->nodeValue();
4068QString QDomElementPrivate::attributeNS(
const QString& nsURI,
const QString& localName,
const QString& defValue)
const
4070 QDomNodePrivate* n = m_attr->namedItemNS(nsURI, localName);
4074 return n->nodeValue();
4077void QDomElementPrivate::setAttribute(
const QString& aname,
const QString& newValue)
4079 QDomNodePrivate* n = m_attr->namedItem(aname);
4081 n =
new QDomAttrPrivate(ownerDocument(),
this, aname);
4082 n->setNodeValue(newValue);
4087 m_attr->setNamedItem(n);
4089 n->setNodeValue(newValue);
4093void QDomElementPrivate::setAttributeNS(
const QString& nsURI,
const QString& qName,
const QString& newValue)
4095 QString prefix, localName;
4096 qt_split_namespace(prefix, localName, qName,
true);
4097 QDomNodePrivate* n = m_attr->namedItemNS(nsURI, localName);
4099 n =
new QDomAttrPrivate(ownerDocument(),
this, nsURI, qName);
4100 n->setNodeValue(newValue);
4105 m_attr->setNamedItem(n);
4107 n->setNodeValue(newValue);
4108 n->prefix = std::move(prefix);
4112void QDomElementPrivate::removeAttribute(
const QString& aname)
4114 QDomNodePrivate* p = m_attr->removeNamedItem(aname);
4115 if (p && p->ref.loadRelaxed() == 0)
4119QDomAttrPrivate* QDomElementPrivate::attributeNode(
const QString& aname)
4121 return static_cast<QDomAttrPrivate *>(m_attr->namedItem(aname));
4124QDomAttrPrivate* QDomElementPrivate::attributeNodeNS(
const QString& nsURI,
const QString& localName)
4126 return static_cast<QDomAttrPrivate *>(m_attr->namedItemNS(nsURI, localName));
4129QDomAttrPrivate* QDomElementPrivate::setAttributeNode(QDomAttrPrivate* newAttr)
4134 QDomNodePrivate* foundAttr = m_attr->namedItem(newAttr->nodeName());
4136 m_attr->removeNamedItem(newAttr->nodeName());
4139 m_attr->setNamedItem(newAttr);
4140 newAttr->setParent(
this);
4142 return static_cast<QDomAttrPrivate *>(foundAttr);
4145QDomAttrPrivate* QDomElementPrivate::setAttributeNodeNS(QDomAttrPrivate* newAttr)
4147 QDomNodePrivate* n =
nullptr;
4148 if (!newAttr->prefix.isNull())
4149 n = m_attr->namedItemNS(newAttr->namespaceURI, newAttr->name);
4152 m_attr->setNamedItem(newAttr);
4154 return static_cast<QDomAttrPrivate *>(n);
4157QDomAttrPrivate* QDomElementPrivate::removeAttributeNode(QDomAttrPrivate* oldAttr)
4159 return static_cast<QDomAttrPrivate *>(m_attr->removeNamedItem(oldAttr->nodeName()));
4162bool QDomElementPrivate::hasAttribute(
const QString& aname)
4164 return m_attr->contains(aname);
4167bool QDomElementPrivate::hasAttributeNS(
const QString& nsURI,
const QString& localName)
4169 return m_attr->containsNS(nsURI, localName);
4172QString QDomElementPrivate::text()
4176 QDomNodePrivate* p = first;
4178 if (p->isText() || p->isCDATASection())
4179 t += p->nodeValue();
4180 else if (p->isElement())
4181 t +=
static_cast<QDomElementPrivate *>(p)->text();
4188void QDomElementPrivate::save(QTextStream& s,
int depth,
int indent)
const
4190 if (!(prev && prev->isText()))
4191 s << QString(indent < 1 ? 0 : depth * indent, u' ');
4193 QString qName(name);
4194 QString nsDecl(u""_s);
4195 if (!namespaceURI.isNull()) {
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206 if (prefix.isEmpty()) {
4207 nsDecl = u" xmlns"_s;
4209 qName = prefix + u':' + name;
4210 nsDecl = u" xmlns:"_s + prefix;
4212 nsDecl += u"=\""_s + encodeText(namespaceURI) + u'\"';
4214 s <<
'<' << qName << nsDecl;
4218 if (!m_attr->map.isEmpty()) {
4220
4221
4222
4223
4224
4225
4226
4227 struct SavedAttribute {
4230 QString encodedValue;
4234 QVarLengthArray<SavedAttribute, 8> attributesToSave;
4235 attributesToSave.reserve(m_attr->map.size());
4237 QDuplicateTracker<QString> outputtedPrefixes;
4238 for (
const auto &[key, value] : std::as_const(m_attr->map).asKeyValueRange()) {
4240 bool mayNeedXmlNS =
false;
4242 SavedAttribute attr;
4243 attr.name = value->name;
4244 attr.encodedValue = encodeText(value->value,
true,
true);
4245 if (!value->namespaceURI.isNull()) {
4246 attr.prefix = value->prefix;
4247 mayNeedXmlNS =
true;
4250 attributesToSave.push_back(std::move(attr));
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4269 && ((!value->ownerNode || value->ownerNode->prefix != value->prefix)
4270 && !outputtedPrefixes.hasSeen(value->prefix)))
4272 SavedAttribute nsAttr;
4273 nsAttr.prefix = QStringLiteral(
"xmlns");
4274 nsAttr.name = value->prefix;
4275 nsAttr.encodedValue = encodeText(value->namespaceURI,
true,
true);
4276 attributesToSave.push_back(std::move(nsAttr));
4281 const auto savedAttributeComparator = [](
const SavedAttribute &lhs,
const SavedAttribute &rhs)
4283 const int cmp = QString::compare(lhs.prefix, rhs.prefix);
4284 return (cmp < 0) || ((cmp == 0) && (lhs.name < rhs.name));
4287 std::sort(attributesToSave.begin(), attributesToSave.end(), savedAttributeComparator);
4290 for (
const auto &attr : attributesToSave) {
4292 if (!attr.prefix.isEmpty())
4293 s << attr.prefix <<
':';
4294 s << attr.name <<
"=\"" << attr.encodedValue <<
'\"';
4300 if (first->isText())
4314void QDomElementPrivate::afterSave(QTextStream &s,
int depth,
int indent)
const
4317 QString qName(name);
4319 if (!prefix.isEmpty())
4320 qName = prefix + u':' + name;
4322 if (!last->isText())
4323 s << QString(indent < 1 ? 0 : depth * indent, u' ');
4325 s <<
"</" << qName <<
'>';
4328 if (!(next && next->isText())) {
4336
4337
4338
4339
4341#define IMPL static_cast<QDomElementPrivate *>(impl)
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4396
4397
4398
4399QDomElement::QDomElement()
4405
4406
4407
4408
4409
4410
4411QDomElement::QDomElement(
const QDomElement &element)
4416QDomElement::QDomElement(QDomElementPrivate* n)
4422
4423
4424
4425
4426
4427
4428QDomElement &QDomElement::operator=(
const QDomElement &other) =
default;
4431
4432
4433
4434
4437
4438
4439
4440
4441void QDomElement::setTagName(
const QString& name)
4448
4449
4450
4451
4452
4453
4454
4455
4456QString QDomElement::tagName()
const
4460 return impl->nodeName();
4465
4466
4467
4468
4469QDomNamedNodeMap QDomElement::attributes()
const
4472 return QDomNamedNodeMap();
4473 return QDomNamedNodeMap(IMPL->attributes());
4477
4478
4479
4480
4481
4482QString QDomElement::attribute(
const QString& name,
const QString& defValue)
const
4486 return IMPL->attribute(name, defValue);
4490
4491
4492
4493
4494
4495
4496void QDomElement::setAttribute(
const QString& name,
const QString& value)
4500 IMPL->setAttribute(name, value);
4504
4505
4506
4507
4508
4511
4512
4513
4514
4515
4518
4519
4520
4521
4522void QDomElement::setAttribute(
const QString& name, qlonglong value)
4528 IMPL->setAttribute(name, x);
4532
4533
4534
4535
4536void QDomElement::setAttribute(
const QString& name, qulonglong value)
4542 IMPL->setAttribute(name, x);
4546
4547
4548
4549
4550void QDomElement::setAttribute(
const QString& name,
float value)
4555 x.setNum(value,
'g', 8);
4556 IMPL->setAttribute(name, x);
4560
4561
4562
4563
4564void QDomElement::setAttribute(
const QString& name,
double value)
4569 x.setNum(value,
'g', 17);
4570 IMPL->setAttribute(name, x);
4574
4575
4576
4577
4578void QDomElement::removeAttribute(
const QString& name)
4582 IMPL->removeAttribute(name);
4586
4587
4588
4589
4590
4591
4592QDomAttr QDomElement::attributeNode(
const QString& name)
4596 return QDomAttr(IMPL->attributeNode(name));
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609QDomAttr QDomElement::setAttributeNode(
const QDomAttr& newAttr)
4613 return QDomAttr(IMPL->setAttributeNode(
static_cast<QDomAttrPrivate *>(newAttr.impl)));
4617
4618
4619
4620
4621QDomAttr QDomElement::removeAttributeNode(
const QDomAttr& oldAttr)
4625 return QDomAttr(IMPL->removeAttributeNode(
static_cast<QDomAttrPrivate *>(oldAttr.impl)));
4629
4630
4631
4632
4633
4634
4635
4636
4637QDomNodeList QDomElement::elementsByTagName(
const QString& tagname)
const
4639 return QDomNodeList(
new QDomNodeListPrivate(impl, tagname));
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654bool QDomElement::hasAttribute(
const QString& name)
const
4658 return IMPL->hasAttribute(name);
4662
4663
4664
4665
4666
4667
4668QString QDomElement::attributeNS(
const QString& nsURI,
const QString& localName,
const QString& defValue)
const
4672 return IMPL->attributeNS(nsURI, localName, defValue);
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687void QDomElement::setAttributeNS(
const QString& nsURI,
const QString& qName,
const QString& value)
4691 IMPL->setAttributeNS(nsURI, qName, value);
4695
4696
4697
4698
4701
4702
4703
4704
4707
4708
4709void QDomElement::setAttributeNS(
const QString& nsURI,
const QString& qName, qlonglong value)
4715 IMPL->setAttributeNS(nsURI, qName, x);
4719
4720
4721void QDomElement::setAttributeNS(
const QString& nsURI,
const QString& qName, qulonglong value)
4727 IMPL->setAttributeNS(nsURI, qName, x);
4731
4732
4733void QDomElement::setAttributeNS(
const QString& nsURI,
const QString& qName,
double value)
4738 x.setNum(value,
'g', 17);
4739 IMPL->setAttributeNS(nsURI, qName, x);
4743
4744
4745
4746
4747
4748void QDomElement::removeAttributeNS(
const QString& nsURI,
const QString& localName)
4752 QDomNodePrivate *n = IMPL->attributeNodeNS(nsURI, localName);
4755 IMPL->removeAttribute(n->nodeName());
4759
4760
4761
4762
4763
4764
4765
4766QDomAttr QDomElement::attributeNodeNS(
const QString& nsURI,
const QString& localName)
4770 return QDomAttr(IMPL->attributeNodeNS(nsURI, localName));
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783QDomAttr QDomElement::setAttributeNodeNS(
const QDomAttr& newAttr)
4787 return QDomAttr(IMPL->setAttributeNodeNS(
static_cast<QDomAttrPrivate *>(newAttr.impl)));
4791
4792
4793
4794
4795
4796
4797
4798
4799QDomNodeList QDomElement::elementsByTagNameNS(
const QString& nsURI,
const QString& localName)
const
4801 return QDomNodeList(
new QDomNodeListPrivate(impl, nsURI, localName));
4805
4806
4807
4808
4809bool QDomElement::hasAttributeNS(
const QString& nsURI,
const QString& localName)
const
4813 return IMPL->hasAttributeNS(nsURI, localName);
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830QString QDomElement::text()
const
4834 return IMPL->text();
4840
4841
4842
4843
4845QDomTextPrivate::QDomTextPrivate(QDomDocumentPrivate* d, QDomNodePrivate* parent,
const QString& val)
4846 : QDomCharacterDataPrivate(d, parent, val)
4851QDomTextPrivate::QDomTextPrivate(QDomTextPrivate* n,
bool deep)
4852 : QDomCharacterDataPrivate(n, deep)
4856QDomNodePrivate* QDomTextPrivate::cloneNode(
bool deep)
4858 QDomNodePrivate* p =
new QDomTextPrivate(
this, deep);
4864QDomTextPrivate* QDomTextPrivate::splitText(
int offset)
4867 qWarning(
"QDomText::splitText The node has no parent. So I cannot split");
4871 QDomTextPrivate* t =
new QDomTextPrivate(ownerDocument(),
nullptr, value.mid(offset));
4872 value.truncate(offset);
4874 parent()->insertAfter(t,
this);
4875 Q_ASSERT(t->ref.loadRelaxed() == 2);
4883void QDomTextPrivate::save(QTextStream& s,
int,
int)
const
4885 QDomTextPrivate *that =
const_cast<QDomTextPrivate*>(
this);
4886 s << encodeText(value, !(that->parent() && that->parent()->isElement()),
false,
true);
4890
4891
4892
4893
4895#define IMPL static_cast<QDomTextPrivate *>(impl)
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4916
4917
4918
4919
4921 : QDomCharacterData()
4926
4927
4928
4929
4930
4931
4932QDomText::QDomText(
const QDomText &text)
4933 : QDomCharacterData(text)
4937QDomText::QDomText(QDomTextPrivate* n)
4938 : QDomCharacterData(n)
4943
4944
4945
4946
4947
4948
4949QDomText &QDomText::operator=(
const QDomText &other) =
default;
4952
4953
4954
4955
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967QDomText QDomText::splitText(
int offset)
4971 return QDomText(IMPL->splitText(offset));
4977
4978
4979
4980
4982QDomCommentPrivate::QDomCommentPrivate(QDomDocumentPrivate* d, QDomNodePrivate* parent,
const QString& val)
4983 : QDomCharacterDataPrivate(d, parent, val)
4985 name = u"#comment"_s;
4988QDomCommentPrivate::QDomCommentPrivate(QDomCommentPrivate* n,
bool deep)
4989 : QDomCharacterDataPrivate(n, deep)
4994QDomNodePrivate* QDomCommentPrivate::cloneNode(
bool deep)
4996 QDomNodePrivate* p =
new QDomCommentPrivate(
this, deep);
5002void QDomCommentPrivate::save(QTextStream& s,
int depth,
int indent)
const
5005 if (!(prev && prev->isText()))
5006 s << QString(indent < 1 ? 0 : depth * indent, u' ');
5008 s <<
"<!--" << value;
5009 if (value.endsWith(u'-'))
5013 if (!(next && next->isText()))
5018
5019
5020
5021
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5045
5046
5047
5048QDomComment::QDomComment()
5049 : QDomCharacterData()
5054
5055
5056
5057
5058
5059
5060QDomComment::QDomComment(
const QDomComment &comment)
5061 : QDomCharacterData(comment)
5065QDomComment::QDomComment(QDomCommentPrivate* n)
5066 : QDomCharacterData(n)
5071
5072
5073
5074
5075
5076
5077QDomComment &QDomComment::operator=(
const QDomComment &other) =
default;
5080
5081
5082
5083
5086
5087
5088
5089
5091QDomCDATASectionPrivate::QDomCDATASectionPrivate(QDomDocumentPrivate* d, QDomNodePrivate* parent,
5093 : QDomTextPrivate(d, parent, val)
5095 name = u"#cdata-section"_s;
5098QDomCDATASectionPrivate::QDomCDATASectionPrivate(QDomCDATASectionPrivate* n,
bool deep)
5099 : QDomTextPrivate(n, deep)
5103QDomNodePrivate* QDomCDATASectionPrivate::cloneNode(
bool deep)
5105 QDomNodePrivate* p =
new QDomCDATASectionPrivate(
this, deep);
5111void QDomCDATASectionPrivate::save(QTextStream& s,
int,
int)
const
5115 s <<
"<![CDATA[" << value <<
"]]>";
5119
5120
5121
5122
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5150
5151
5152
5153QDomCDATASection::QDomCDATASection()
5159
5160
5161
5162
5163
5164
5165QDomCDATASection::QDomCDATASection(
const QDomCDATASection &cdataSection)
5166 : QDomText(cdataSection)
5170QDomCDATASection::QDomCDATASection(QDomCDATASectionPrivate* n)
5176
5177
5178
5179
5180
5181
5182QDomCDATASection &QDomCDATASection::operator=(
const QDomCDATASection &other) =
default;
5185
5186
5187
5188
5191
5192
5193
5194
5196QDomNotationPrivate::QDomNotationPrivate(QDomDocumentPrivate* d, QDomNodePrivate* parent,
5197 const QString& aname,
5198 const QString& pub,
const QString& sys)
5199 : QDomNodePrivate(d, parent)
5206QDomNotationPrivate::QDomNotationPrivate(QDomNotationPrivate* n,
bool deep)
5207 : QDomNodePrivate(n, deep)
5213QDomNodePrivate* QDomNotationPrivate::cloneNode(
bool deep)
5215 QDomNodePrivate* p =
new QDomNotationPrivate(
this, deep);
5221void QDomNotationPrivate::save(QTextStream& s,
int,
int)
const
5223 s <<
"<!NOTATION " << name <<
' ';
5224 if (!m_pub.isNull()) {
5225 s <<
"PUBLIC " << quotedValue(m_pub);
5226 if (!m_sys.isNull())
5227 s <<
' ' << quotedValue(m_sys);
5229 s <<
"SYSTEM " << quotedValue(m_sys);
5231 s <<
'>' << Qt::endl;
5235
5236
5237
5238
5240#define IMPL static_cast<QDomNotationPrivate *>(impl)
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5272
5273
5274QDomNotation::QDomNotation()
5280
5281
5282
5283
5284
5285
5286QDomNotation::QDomNotation(
const QDomNotation ¬ation)
5287 : QDomNode(notation)
5291QDomNotation::QDomNotation(QDomNotationPrivate* n)
5297
5298
5299
5300
5301
5302
5303QDomNotation &QDomNotation::operator=(
const QDomNotation &other) =
default;
5306
5307
5308
5309
5312
5313
5314QString QDomNotation::publicId()
const
5322
5323
5324QString QDomNotation::systemId()
const
5334
5335
5336
5337
5339QDomEntityPrivate::QDomEntityPrivate(QDomDocumentPrivate* d, QDomNodePrivate* parent,
5340 const QString& aname,
5341 const QString& pub,
const QString& sys,
const QString& notation)
5342 : QDomNodePrivate(d, parent)
5347 m_notationName = notation;
5350QDomEntityPrivate::QDomEntityPrivate(QDomEntityPrivate* n,
bool deep)
5351 : QDomNodePrivate(n, deep)
5355 m_notationName = n->m_notationName;
5358QDomNodePrivate* QDomEntityPrivate::cloneNode(
bool deep)
5360 QDomNodePrivate* p =
new QDomEntityPrivate(
this, deep);
5367
5368
5369static QByteArray encodeEntity(
const QByteArray& str)
5371 QByteArray tmp(str);
5372 int len = tmp.size();
5374 const char* d = tmp.constData();
5377 tmp.replace(i, 1,
"<");
5378 d = tmp.constData();
5382 else if (d[i] ==
'"') {
5383 tmp.replace(i, 1,
""");
5384 d = tmp.constData();
5387 }
else if (d[i] ==
'&' && i + 1 < len && d[i+1] ==
'#') {
5390 tmp.replace(i, 1,
"&");
5391 d = tmp.constData();
5402void QDomEntityPrivate::save(QTextStream& s,
int,
int)
const
5404 QString _name = name;
5405 if (_name.startsWith(u'%'))
5406 _name = u"% "_s + _name.mid(1);
5408 if (m_sys.isNull() && m_pub.isNull()) {
5409 s <<
"<!ENTITY " << _name <<
" \"" << encodeEntity(value.toUtf8()) <<
"\">" << Qt::endl;
5411 s <<
"<!ENTITY " << _name <<
' ';
5412 if (m_pub.isNull()) {
5413 s <<
"SYSTEM " << quotedValue(m_sys);
5415 s <<
"PUBLIC " << quotedValue(m_pub) <<
' ' << quotedValue(m_sys);
5417 if (! m_notationName.isNull()) {
5418 s <<
" NDATA " << m_notationName;
5420 s <<
'>' << Qt::endl;
5425
5426
5427
5428
5430#define IMPL static_cast<QDomEntityPrivate *>(impl)
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5465
5466
5467QDomEntity::QDomEntity()
5474
5475
5476
5477
5478
5479
5480QDomEntity::QDomEntity(
const QDomEntity &entity)
5485QDomEntity::QDomEntity(QDomEntityPrivate* n)
5491
5492
5493
5494
5495
5496
5497QDomEntity &QDomEntity::operator=(
const QDomEntity &other) =
default;
5500
5501
5502
5503
5506
5507
5508
5509QString QDomEntity::publicId()
const
5517
5518
5519
5520QString QDomEntity::systemId()
const
5528
5529
5530
5531
5532QString QDomEntity::notationName()
const
5536 return IMPL->m_notationName;
5542
5543
5544
5545
5547QDomEntityReferencePrivate::QDomEntityReferencePrivate(QDomDocumentPrivate* d, QDomNodePrivate* parent,
const QString& aname)
5548 : QDomNodePrivate(d, parent)
5553QDomEntityReferencePrivate::QDomEntityReferencePrivate(QDomNodePrivate* n,
bool deep)
5554 : QDomNodePrivate(n, deep)
5558QDomNodePrivate* QDomEntityReferencePrivate::cloneNode(
bool deep)
5560 QDomNodePrivate* p =
new QDomEntityReferencePrivate(
this, deep);
5566void QDomEntityReferencePrivate::save(QTextStream& s,
int,
int)
const
5568 s <<
'&' << name <<
';';
5572
5573
5574
5575
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5613
5614
5615
5616
5617QDomEntityReference::QDomEntityReference()
5623
5624
5625
5626
5627
5628
5629QDomEntityReference::QDomEntityReference(
const QDomEntityReference &entityReference)
5630 : QDomNode(entityReference)
5634QDomEntityReference::QDomEntityReference(QDomEntityReferencePrivate* n)
5640
5641
5642
5643
5644
5645
5646QDomEntityReference &QDomEntityReference::operator=(
const QDomEntityReference &other) =
default;
5649
5650
5651
5652
5655
5656
5657
5658
5660QDomProcessingInstructionPrivate::QDomProcessingInstructionPrivate(QDomDocumentPrivate* d,
5661 QDomNodePrivate* parent,
const QString& target,
const QString& data)
5662 : QDomNodePrivate(d, parent)
5668QDomProcessingInstructionPrivate::QDomProcessingInstructionPrivate(QDomProcessingInstructionPrivate* n,
bool deep)
5669 : QDomNodePrivate(n, deep)
5674QDomNodePrivate* QDomProcessingInstructionPrivate::cloneNode(
bool deep)
5676 QDomNodePrivate* p =
new QDomProcessingInstructionPrivate(
this, deep);
5682void QDomProcessingInstructionPrivate::save(QTextStream& s,
int,
int)
const
5684 s <<
"<?" << name <<
' ' << value <<
"?>" << Qt::endl;
5688
5689
5690
5691
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5735
5736
5737
5738
5739QDomProcessingInstruction::QDomProcessingInstruction()
5745
5746
5747
5748
5749
5750
5751QDomProcessingInstruction::QDomProcessingInstruction(
const QDomProcessingInstruction &processingInstruction)
5752 : QDomNode(processingInstruction)
5756QDomProcessingInstruction::QDomProcessingInstruction(QDomProcessingInstructionPrivate* n)
5762
5763
5764
5765
5766
5767
5768QDomProcessingInstruction &
5769QDomProcessingInstruction::operator=(
const QDomProcessingInstruction &other) =
default;
5772
5773
5774
5775
5778
5779
5780
5781
5782QString QDomProcessingInstruction::target()
const
5786 return impl->nodeName();
5790
5791
5792
5793
5794QString QDomProcessingInstruction::data()
const
5798 return impl->nodeValue();
5802
5803
5804
5805
5806void QDomProcessingInstruction::setData(
const QString &data)
5809 impl->setNodeValue(data);
5813
5814
5815
5816
5818QDomDocumentPrivate::QDomDocumentPrivate()
5819 : QDomNodePrivate(
nullptr),
5820 impl(
new QDomImplementationPrivate),
5823 type =
new QDomDocumentTypePrivate(
this,
this);
5826 name = u"#document"_s;
5829QDomDocumentPrivate::QDomDocumentPrivate(
const QString& aname)
5830 : QDomNodePrivate(
nullptr),
5831 impl(
new QDomImplementationPrivate),
5834 type =
new QDomDocumentTypePrivate(
this,
this);
5838 name = u"#document"_s;
5841QDomDocumentPrivate::QDomDocumentPrivate(QDomDocumentTypePrivate* dt)
5842 : QDomNodePrivate(
nullptr),
5843 impl(
new QDomImplementationPrivate),
5846 if (dt !=
nullptr) {
5849 type =
new QDomDocumentTypePrivate(
this,
this);
5853 name = u"#document"_s;
5856QDomDocumentPrivate::QDomDocumentPrivate(QDomDocumentPrivate* n,
bool deep)
5857 : QDomNodePrivate(n, deep),
5858 impl(n->impl->clone()),
5861 type =
static_cast<QDomDocumentTypePrivate*>(n->type->cloneNode());
5862 type->setParent(
this);
5865QDomDocumentPrivate::~QDomDocumentPrivate()
5869void QDomDocumentPrivate::clear()
5873 QDomNodePrivate::clear();
5876QDomDocument::ParseResult QDomDocumentPrivate::setContent(QXmlStreamReader *reader,
5877 QDomDocument::ParseOptions options)
5880 impl =
new QDomImplementationPrivate;
5881 type =
new QDomDocumentTypePrivate(
this,
this);
5885 const auto error = u"Failed to set content, XML reader is not initialized"_s;
5886 qWarning(
"%s", qPrintable(error));
5890 QDomParser domParser(
this, reader, options);
5892 if (!domParser.parse())
5893 return domParser.result();
5897QDomNodePrivate* QDomDocumentPrivate::cloneNode(
bool deep)
5899 QDomNodePrivate *p =
new QDomDocumentPrivate(
this, deep);
5905QDomElementPrivate* QDomDocumentPrivate::documentElement()
5907 QDomNodePrivate *p = first;
5908 while (p && !p->isElement())
5911 return static_cast<QDomElementPrivate *>(p);
5914QDomElementPrivate* QDomDocumentPrivate::createElement(
const QString &tagName)
5917 QString fixedName = fixedXmlName(tagName, &ok);
5921 QDomElementPrivate *e =
new QDomElementPrivate(
this,
nullptr, fixedName);
5926QDomElementPrivate* QDomDocumentPrivate::createElementNS(
const QString &nsURI,
const QString &qName)
5929 QString fixedName = fixedXmlName(qName, &ok,
true);
5933 QDomElementPrivate *e =
new QDomElementPrivate(
this,
nullptr, nsURI, fixedName);
5938QDomDocumentFragmentPrivate* QDomDocumentPrivate::createDocumentFragment()
5940 QDomDocumentFragmentPrivate *f =
new QDomDocumentFragmentPrivate(
this,
nullptr);
5945QDomTextPrivate* QDomDocumentPrivate::createTextNode(
const QString &data)
5948 QString fixedData = fixedCharData(data, &ok);
5952 QDomTextPrivate *t =
new QDomTextPrivate(
this,
nullptr, fixedData);
5957QDomCommentPrivate* QDomDocumentPrivate::createComment(
const QString &data)
5960 QString fixedData = fixedComment(data, &ok);
5964 QDomCommentPrivate *c =
new QDomCommentPrivate(
this,
nullptr, fixedData);
5969QDomCDATASectionPrivate* QDomDocumentPrivate::createCDATASection(
const QString &data)
5972 QString fixedData = fixedCDataSection(data, &ok);
5976 QDomCDATASectionPrivate *c =
new QDomCDATASectionPrivate(
this,
nullptr, fixedData);
5981QDomProcessingInstructionPrivate* QDomDocumentPrivate::createProcessingInstruction(
const QString &target,
5982 const QString &data)
5985 QString fixedData = fixedPIData(data, &ok);
5989 QString fixedTarget = fixedXmlName(target, &ok);
5993 QDomProcessingInstructionPrivate *p =
new QDomProcessingInstructionPrivate(
this,
nullptr, fixedTarget, fixedData);
5997QDomAttrPrivate* QDomDocumentPrivate::createAttribute(
const QString &aname)
6000 QString fixedName = fixedXmlName(aname, &ok);
6004 QDomAttrPrivate *a =
new QDomAttrPrivate(
this,
nullptr, fixedName);
6009QDomAttrPrivate* QDomDocumentPrivate::createAttributeNS(
const QString &nsURI,
const QString &qName)
6012 QString fixedName = fixedXmlName(qName, &ok,
true);
6016 QDomAttrPrivate *a =
new QDomAttrPrivate(
this,
nullptr, nsURI, fixedName);
6021QDomEntityReferencePrivate* QDomDocumentPrivate::createEntityReference(
const QString &aname)
6024 QString fixedName = fixedXmlName(aname, &ok);
6028 QDomEntityReferencePrivate *e =
new QDomEntityReferencePrivate(
this,
nullptr, fixedName);
6033QDomNodePrivate* QDomDocumentPrivate::importNode(QDomNodePrivate *importedNode,
bool deep)
6035 QDomNodePrivate *node =
nullptr;
6036 switch (importedNode->nodeType()) {
6037 case QDomNode::AttributeNode:
6038 node =
new QDomAttrPrivate(
static_cast<QDomAttrPrivate *>(importedNode),
true);
6040 case QDomNode::DocumentFragmentNode:
6041 node =
new QDomDocumentFragmentPrivate(
6042 static_cast<QDomDocumentFragmentPrivate *>(importedNode), deep);
6044 case QDomNode::ElementNode:
6045 node =
new QDomElementPrivate(
static_cast<QDomElementPrivate *>(importedNode), deep);
6047 case QDomNode::EntityNode:
6048 node =
new QDomEntityPrivate(
static_cast<QDomEntityPrivate *>(importedNode), deep);
6050 case QDomNode::EntityReferenceNode:
6051 node =
new QDomEntityReferencePrivate(
6052 static_cast<QDomEntityReferencePrivate *>(importedNode),
false);
6054 case QDomNode::NotationNode:
6055 node =
new QDomNotationPrivate(
static_cast<QDomNotationPrivate *>(importedNode), deep);
6057 case QDomNode::ProcessingInstructionNode:
6058 node =
new QDomProcessingInstructionPrivate(
6059 static_cast<QDomProcessingInstructionPrivate *>(importedNode), deep);
6061 case QDomNode::TextNode:
6062 node =
new QDomTextPrivate(
static_cast<QDomTextPrivate *>(importedNode), deep);
6064 case QDomNode::CDATASectionNode:
6065 node =
new QDomCDATASectionPrivate(
static_cast<QDomCDATASectionPrivate *>(importedNode),
6068 case QDomNode::CommentNode:
6069 node =
new QDomCommentPrivate(
static_cast<QDomCommentPrivate *>(importedNode), deep);
6075 node->setOwnerDocument(
this);
6083void QDomDocumentPrivate::saveDocument(QTextStream& s,
const int indent, QDomNode::EncodingPolicy encUsed)
const
6085 const QDomNodePrivate* n = first;
6087 if (encUsed == QDomNode::EncodingFromDocument) {
6088#if QT_CONFIG(regularexpression)
6089 const QDomNodePrivate* n = first;
6091 if (n && n->isProcessingInstruction() && n->nodeName() ==
"xml"_L1) {
6093 QString data = n->nodeValue();
6094 QRegularExpression encoding(QString::fromLatin1(
"encoding\\s*=\\s*((\"([^\"]*)\")|('([^']*)'))"));
6095 auto match = encoding.match(data);
6096 QString enc = match.captured(3);
6098 enc = match.captured(5);
6099 if (!enc.isEmpty()) {
6100 auto encoding = QStringConverter::encodingForName(enc.toUtf8().constData());
6102 qWarning() <<
"QDomDocument::save(): Unsupported encoding" << enc <<
"specified.";
6104 s.setEncoding(encoding.value());
6111 if (!doc && !(n->isProcessingInstruction() && n->nodeName() ==
"xml"_L1)) {
6113 type->save(s, 0, indent);
6116 n->saveSubTree(n, s, 0, indent);
6123 const QByteArray codecName = QStringConverter::nameForEncoding(s.encoding());
6125 s <<
"<?xml version=\"1.0\" encoding=\""
6130 const QDomNodePrivate* startNode = n;
6134 if (n->isProcessingInstruction() && n->nodeName() ==
"xml"_L1) {
6135 startNode = n->next;
6144 startNode->saveSubTree(startNode, s, 0, indent);
6145 startNode = startNode->next;
6151
6152
6153
6154
6156#define IMPL static_cast<QDomDocumentPrivate *>(impl)
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6237
6238
6239QDomDocument::QDomDocument()
6245
6246
6247
6248QDomDocument::QDomDocument(
const QString& name)
6251 impl =
new QDomDocumentPrivate(name);
6255
6256
6257
6258
6259QDomDocument::QDomDocument(
const QDomDocumentType& doctype)
6261 impl =
new QDomDocumentPrivate(
static_cast<QDomDocumentTypePrivate *>(doctype.impl));
6265
6266
6267
6268
6269
6270
6271QDomDocument::QDomDocument(
const QDomDocument &document)
6272 : QDomNode(document)
6276QDomDocument::QDomDocument(QDomDocumentPrivate *pimpl)
6282
6283
6284
6285
6286
6287
6288QDomDocument &QDomDocument::operator=(
const QDomDocument &other) =
default;
6291
6292
6293QDomDocument::~QDomDocument()
6297#if QT_DEPRECATED_SINCE(6
, 8
)
6299QT_WARNING_DISABLE_DEPRECATED
6301
6302
6303
6304
6305
6306
6307
6308
6309bool QDomDocument::setContent(
const QString& text,
bool namespaceProcessing,
6310 QString *errorMsg,
int *errorLine,
int *errorColumn)
6312 QXmlStreamReader reader(text);
6313 reader.setNamespaceProcessing(namespaceProcessing);
6314 return setContent(&reader, namespaceProcessing, errorMsg, errorLine, errorColumn);
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369bool QDomDocument::setContent(
const QByteArray &data,
bool namespaceProcessing,
6370 QString *errorMsg,
int *errorLine,
int *errorColumn)
6372 QXmlStreamReader reader(data);
6373 reader.setNamespaceProcessing(namespaceProcessing);
6374 return setContent(&reader, namespaceProcessing, errorMsg, errorLine, errorColumn);
6377static inline QDomDocument::ParseOptions toParseOptions(
bool namespaceProcessing)
6379 return namespaceProcessing ? QDomDocument::ParseOption::UseNamespaceProcessing
6380 : QDomDocument::ParseOption::Default;
6383static inline void unpackParseResult(
const QDomDocument::ParseResult &parseResult,
6384 QString *errorMsg,
int *errorLine,
int *errorColumn)
6388 *errorMsg = parseResult.errorMessage;
6390 *errorLine =
static_cast<
int>(parseResult.errorLine);
6392 *errorColumn =
static_cast<
int>(parseResult.errorColumn);
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408bool QDomDocument::setContent(QIODevice* dev,
bool namespaceProcessing,
6409 QString *errorMsg,
int *errorLine,
int *errorColumn)
6411 ParseResult result = setContent(dev, toParseOptions(namespaceProcessing));
6412 unpackParseResult(result, errorMsg, errorLine, errorColumn);
6413 return bool(result);
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427bool QDomDocument::setContent(
const QString& text, QString *errorMsg,
int *errorLine,
int *errorColumn)
6429 return setContent(text,
false, errorMsg, errorLine, errorColumn);
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442bool QDomDocument::setContent(
const QByteArray& buffer, QString *errorMsg,
int *errorLine,
int *errorColumn )
6444 return setContent(buffer,
false, errorMsg, errorLine, errorColumn);
6448
6449
6450
6451
6452
6453
6454
6455
6456bool QDomDocument::setContent(QIODevice* dev, QString *errorMsg,
int *errorLine,
int *errorColumn )
6458 return setContent(dev,
false, errorMsg, errorLine, errorColumn);
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481bool QDomDocument::setContent(QXmlStreamReader *reader,
bool namespaceProcessing,
6482 QString *errorMsg,
int *errorLine,
int *errorColumn)
6484 ParseResult result = setContent(reader, toParseOptions(namespaceProcessing));
6485 unpackParseResult(result, errorMsg, errorLine, errorColumn);
6486 return bool(result);
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6522
6523
6524
6525
6526
6527
6528
6531
6532
6533
6534
6535
6536
6537
6540
6541
6542
6543
6544
6545
6546
6549
6550
6551
6552
6553
6554
6555
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602QDomDocument::ParseResult QDomDocument::setContentImpl(
const QByteArray &data, ParseOptions options)
6604 QXmlStreamReader reader(data);
6605 reader.setNamespaceProcessing(options.testFlag(ParseOption::UseNamespaceProcessing));
6606 return setContent(&reader, options);
6609QDomDocument::ParseResult QDomDocument::setContent(QAnyStringView data, ParseOptions options)
6611 QXmlStreamReader reader(data);
6612 reader.setNamespaceProcessing(options.testFlag(ParseOption::UseNamespaceProcessing));
6613 return setContent(&reader, options);
6616QDomDocument::ParseResult QDomDocument::setContent(QIODevice *device, ParseOptions options)
6618#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
6619 if (!device->isOpen()) {
6620 qWarning(
"QDomDocument called with unopened QIODevice. "
6621 "This will not be supported in future Qt versions.");
6622 if (!device->open(QIODevice::ReadOnly)) {
6623 const auto error = u"QDomDocument::setContent: Failed to open device."_s;
6624 qWarning(
"%s", qPrintable(error));
6630 QXmlStreamReader reader(device);
6631 reader.setNamespaceProcessing(options.testFlag(ParseOption::UseNamespaceProcessing));
6632 return setContent(&reader, options);
6635QDomDocument::ParseResult QDomDocument::setContent(QXmlStreamReader *reader, ParseOptions options)
6638 impl =
new QDomDocumentPrivate();
6639 return IMPL->setContent(reader, options);
6643
6644
6645
6646
6647
6648
6649
6650QString QDomDocument::toString(
int indent)
const
6653 QTextStream s(&str, QIODevice::WriteOnly);
6659
6660
6661
6662
6663
6664
6665
6666
6667QByteArray QDomDocument::toByteArray(
int indent)
const
6671 return toString(indent).toUtf8();
6676
6677
6678QDomDocumentType QDomDocument::doctype()
const
6681 return QDomDocumentType();
6682 return QDomDocumentType(IMPL->doctype());
6686
6687
6688QDomImplementation QDomDocument::implementation()
const
6691 return QDomImplementation();
6692 return QDomImplementation(IMPL->implementation());
6696
6697
6698QDomElement QDomDocument::documentElement()
const
6701 return QDomElement();
6702 return QDomElement(IMPL->documentElement());
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715QDomElement QDomDocument::createElement(
const QString& tagName)
6718 impl =
new QDomDocumentPrivate();
6719 return QDomElement(IMPL->createElement(tagName));
6723
6724
6725
6726
6727QDomDocumentFragment QDomDocument::createDocumentFragment()
6730 impl =
new QDomDocumentPrivate();
6731 return QDomDocumentFragment(IMPL->createDocumentFragment());
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744QDomText QDomDocument::createTextNode(
const QString& value)
6747 impl =
new QDomDocumentPrivate();
6748 return QDomText(IMPL->createTextNode(value));
6752
6753
6754
6755
6756
6757
6758
6759
6760QDomComment QDomDocument::createComment(
const QString& value)
6763 impl =
new QDomDocumentPrivate();
6764 return QDomComment(IMPL->createComment(value));
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777QDomCDATASection QDomDocument::createCDATASection(
const QString& value)
6780 impl =
new QDomDocumentPrivate();
6781 return QDomCDATASection(IMPL->createCDATASection(value));
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796QDomProcessingInstruction QDomDocument::createProcessingInstruction(
const QString& target,
6797 const QString& data)
6800 impl =
new QDomDocumentPrivate();
6801 return QDomProcessingInstruction(IMPL->createProcessingInstruction(target, data));
6806
6807
6808
6809
6810
6811
6812
6813
6814QDomAttr QDomDocument::createAttribute(
const QString& name)
6817 impl =
new QDomDocumentPrivate();
6818 return QDomAttr(IMPL->createAttribute(name));
6822
6823
6824
6825
6826
6827
6828
6829
6830QDomEntityReference QDomDocument::createEntityReference(
const QString& name)
6833 impl =
new QDomDocumentPrivate();
6834 return QDomEntityReference(IMPL->createEntityReference(name));
6838
6839
6840
6841
6842
6843
6844
6845QDomNodeList QDomDocument::elementsByTagName(
const QString& tagname)
const
6847 return QDomNodeList(
new QDomNodeListPrivate(impl, tagname));
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919QDomNode QDomDocument::importNode(
const QDomNode& importedNode,
bool deep)
6921 if (importedNode.isNull())
6924 impl =
new QDomDocumentPrivate();
6925 return QDomNode(IMPL->importNode(importedNode.impl, deep));
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940QDomElement QDomDocument::createElementNS(
const QString& nsURI,
const QString& qName)
6943 impl =
new QDomDocumentPrivate();
6944 return QDomElement(IMPL->createElementNS(nsURI, qName));
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959QDomAttr QDomDocument::createAttributeNS(
const QString& nsURI,
const QString& qName)
6962 impl =
new QDomDocumentPrivate();
6963 return QDomAttr(IMPL->createAttributeNS(nsURI, qName));
6967
6968
6969
6970
6971
6972
6973
6974QDomNodeList QDomDocument::elementsByTagNameNS(
const QString& nsURI,
const QString& localName)
6976 return QDomNodeList(
new QDomNodeListPrivate(impl, nsURI, localName));
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989QDomElement QDomDocument::elementById(
const QString& )
6991 qWarning(
"elementById() is not implemented and will always return a null node.");
6992 return QDomElement();
6996
6997
6998
6999
7004
7005
7006
7007
7010
7011
7012
7013
7014
7015QDomAttr QDomNode::toAttr()
const
7017 if (impl && impl->isAttr())
7018 return QDomAttr(
static_cast<QDomAttrPrivate *>(impl));
7023
7024
7025
7026
7027
7028QDomCDATASection QDomNode::toCDATASection()
const
7030 if (impl && impl->isCDATASection())
7031 return QDomCDATASection(
static_cast<QDomCDATASectionPrivate *>(impl));
7032 return QDomCDATASection();
7036
7037
7038
7039
7040
7041QDomDocumentFragment QDomNode::toDocumentFragment()
const
7043 if (impl && impl->isDocumentFragment())
7044 return QDomDocumentFragment(
static_cast<QDomDocumentFragmentPrivate *>(impl));
7045 return QDomDocumentFragment();
7049
7050
7051
7052
7053
7054QDomDocument QDomNode::toDocument()
const
7056 if (impl && impl->isDocument())
7057 return QDomDocument(
static_cast<QDomDocumentPrivate *>(impl));
7058 return QDomDocument();
7062
7063
7064
7065
7066
7067QDomDocumentType QDomNode::toDocumentType()
const
7069 if (impl && impl->isDocumentType())
7070 return QDomDocumentType(
static_cast<QDomDocumentTypePrivate *>(impl));
7071 return QDomDocumentType();
7075
7076
7077
7078
7079
7080QDomElement QDomNode::toElement()
const
7082 if (impl && impl->isElement())
7083 return QDomElement(
static_cast<QDomElementPrivate *>(impl));
7084 return QDomElement();
7088
7089
7090
7091
7092
7093QDomEntityReference QDomNode::toEntityReference()
const
7095 if (impl && impl->isEntityReference())
7096 return QDomEntityReference(
static_cast<QDomEntityReferencePrivate *>(impl));
7097 return QDomEntityReference();
7101
7102
7103
7104
7105
7106QDomText QDomNode::toText()
const
7108 if (impl && impl->isText())
7109 return QDomText(
static_cast<QDomTextPrivate *>(impl));
7114
7115
7116
7117
7118
7119QDomEntity QDomNode::toEntity()
const
7121 if (impl && impl->isEntity())
7122 return QDomEntity(
static_cast<QDomEntityPrivate *>(impl));
7123 return QDomEntity();
7127
7128
7129
7130
7131
7132QDomNotation QDomNode::toNotation()
const
7134 if (impl && impl->isNotation())
7135 return QDomNotation(
static_cast<QDomNotationPrivate *>(impl));
7136 return QDomNotation();
7140
7141
7142
7143
7144
7145QDomProcessingInstruction QDomNode::toProcessingInstruction()
const
7147 if (impl && impl->isProcessingInstruction())
7148 return QDomProcessingInstruction(
static_cast<QDomProcessingInstructionPrivate *>(impl));
7149 return QDomProcessingInstruction();
7153
7154
7155
7156
7157
7158QDomCharacterData QDomNode::toCharacterData()
const
7160 if (impl && impl->isCharacterData())
7161 return QDomCharacterData(
static_cast<QDomCharacterDataPrivate *>(impl));
7162 return QDomCharacterData();
7166
7167
7168
7169
7170
7171QDomComment QDomNode::toComment()
const
7173 if (impl && impl->isComment())
7174 return QDomComment(
static_cast<QDomCommentPrivate *>(impl));
7175 return QDomComment();
7179
7180
7181
7182