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)
const
4164 return m_attr->contains(aname);
4167bool QDomElementPrivate::hasAttributeNS(
const QString& nsURI,
const QString& localName)
const
4169 return m_attr->containsNS(nsURI, localName);
4172QString QDomElementPrivate::text()
const
4177 if (QDomNodePrivate* p = first) {
4179 if (p->isText() || p->isCDATASection()) {
4180 t += p->nodeValue();
4181 }
else if (p->isElement() && p->first) {
4198void QDomElementPrivate::save(QTextStream& s,
int depth,
int indent)
const
4200 if (!(prev && prev->isText()))
4201 s << QString(indent < 1 ? 0 : depth * indent, u' ');
4203 QString qName(name);
4204 QString nsDecl(u""_s);
4205 if (!namespaceURI.isNull()) {
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216 if (prefix.isEmpty()) {
4217 nsDecl = u" xmlns"_s;
4219 qName = prefix + u':' + name;
4220 nsDecl = u" xmlns:"_s + prefix;
4222 nsDecl += u"=\""_s + encodeText(namespaceURI) + u'\"';
4224 s <<
'<' << qName << nsDecl;
4228 if (!m_attr->map.isEmpty()) {
4230
4231
4232
4233
4234
4235
4236
4237 struct SavedAttribute {
4240 QString encodedValue;
4244 QVarLengthArray<SavedAttribute, 8> attributesToSave;
4245 attributesToSave.reserve(m_attr->map.size());
4247 QDuplicateTracker<QString> outputtedPrefixes;
4248 for (
const auto &[key, value] : std::as_const(m_attr->map).asKeyValueRange()) {
4250 bool mayNeedXmlNS =
false;
4252 SavedAttribute attr;
4253 attr.name = value->name;
4254 attr.encodedValue = encodeText(value->value,
true,
true);
4255 if (!value->namespaceURI.isNull()) {
4256 attr.prefix = value->prefix;
4257 mayNeedXmlNS =
true;
4260 attributesToSave.push_back(std::move(attr));
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4279 && ((!value->ownerNode || value->ownerNode->prefix != value->prefix)
4280 && !outputtedPrefixes.hasSeen(value->prefix)))
4282 SavedAttribute nsAttr;
4283 nsAttr.prefix = QStringLiteral(
"xmlns");
4284 nsAttr.name = value->prefix;
4285 nsAttr.encodedValue = encodeText(value->namespaceURI,
true,
true);
4286 attributesToSave.push_back(std::move(nsAttr));
4291 const auto savedAttributeComparator = [](
const SavedAttribute &lhs,
const SavedAttribute &rhs)
4293 const int cmp = QString::compare(lhs.prefix, rhs.prefix);
4294 return (cmp < 0) || ((cmp == 0) && (lhs.name < rhs.name));
4297 std::sort(attributesToSave.begin(), attributesToSave.end(), savedAttributeComparator);
4300 for (
const auto &attr : attributesToSave) {
4302 if (!attr.prefix.isEmpty())
4303 s << attr.prefix <<
':';
4304 s << attr.name <<
"=\"" << attr.encodedValue <<
'\"';
4310 if (first->isText())
4324void QDomElementPrivate::afterSave(QTextStream &s,
int depth,
int indent)
const
4327 QString qName(name);
4329 if (!prefix.isEmpty())
4330 qName = prefix + u':' + name;
4332 if (!last->isText())
4333 s << QString(indent < 1 ? 0 : depth * indent, u' ');
4335 s <<
"</" << qName <<
'>';
4338 if (!(next && next->isText())) {
4346
4347
4348
4349
4351#define IMPL static_cast<QDomElementPrivate *>(impl)
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
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4406
4407
4408
4409QDomElement::QDomElement()
4415
4416
4417
4418
4419
4420
4421QDomElement::QDomElement(
const QDomElement &element)
4426QDomElement::QDomElement(QDomElementPrivate* n)
4432
4433
4434
4435
4436
4437
4438QDomElement &QDomElement::operator=(
const QDomElement &other) =
default;
4441
4442
4443
4444
4447
4448
4449
4450
4451void QDomElement::setTagName(
const QString& name)
4458
4459
4460
4461
4462
4463
4464
4465
4466QString QDomElement::tagName()
const
4470 return impl->nodeName();
4475
4476
4477
4478
4479QDomNamedNodeMap QDomElement::attributes()
const
4482 return QDomNamedNodeMap();
4483 return QDomNamedNodeMap(IMPL->attributes());
4487
4488
4489
4490
4491
4492QString QDomElement::attribute(
const QString& name,
const QString& defValue)
const
4496 return IMPL->attribute(name, defValue);
4500
4501
4502
4503
4504
4505
4506void QDomElement::setAttribute(
const QString& name,
const QString& value)
4510 IMPL->setAttribute(name, value);
4514
4515
4516
4517
4518
4521
4522
4523
4524
4525
4528
4529
4530
4531
4532void QDomElement::setAttribute(
const QString& name, qlonglong value)
4538 IMPL->setAttribute(name, x);
4542
4543
4544
4545
4546void QDomElement::setAttribute(
const QString& name, qulonglong value)
4552 IMPL->setAttribute(name, x);
4556
4557
4558
4559
4560void QDomElement::setAttribute(
const QString& name,
float value)
4565 x.setNum(value,
'g', 8);
4566 IMPL->setAttribute(name, x);
4570
4571
4572
4573
4574void QDomElement::setAttribute(
const QString& name,
double value)
4579 x.setNum(value,
'g', 17);
4580 IMPL->setAttribute(name, x);
4584
4585
4586
4587
4588void QDomElement::removeAttribute(
const QString& name)
4592 IMPL->removeAttribute(name);
4596
4597
4598
4599
4600
4601
4602QDomAttr QDomElement::attributeNode(
const QString& name)
4606 return QDomAttr(IMPL->attributeNode(name));
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619QDomAttr QDomElement::setAttributeNode(
const QDomAttr& newAttr)
4623 return QDomAttr(IMPL->setAttributeNode(
static_cast<QDomAttrPrivate *>(newAttr.impl)));
4627
4628
4629
4630
4631QDomAttr QDomElement::removeAttributeNode(
const QDomAttr& oldAttr)
4635 return QDomAttr(IMPL->removeAttributeNode(
static_cast<QDomAttrPrivate *>(oldAttr.impl)));
4639
4640
4641
4642
4643
4644
4645
4646
4647QDomNodeList QDomElement::elementsByTagName(
const QString& tagname)
const
4649 return QDomNodeList(
new QDomNodeListPrivate(impl, tagname));
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664bool QDomElement::hasAttribute(
const QString& name)
const
4668 return IMPL->hasAttribute(name);
4672
4673
4674
4675
4676
4677
4678QString QDomElement::attributeNS(
const QString& nsURI,
const QString& localName,
const QString& defValue)
const
4682 return IMPL->attributeNS(nsURI, localName, defValue);
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697void QDomElement::setAttributeNS(
const QString& nsURI,
const QString& qName,
const QString& value)
4701 IMPL->setAttributeNS(nsURI, qName, value);
4705
4706
4707
4708
4711
4712
4713
4714
4717
4718
4719void QDomElement::setAttributeNS(
const QString& nsURI,
const QString& qName, qlonglong value)
4725 IMPL->setAttributeNS(nsURI, qName, x);
4729
4730
4731void QDomElement::setAttributeNS(
const QString& nsURI,
const QString& qName, qulonglong value)
4737 IMPL->setAttributeNS(nsURI, qName, x);
4741
4742
4743void QDomElement::setAttributeNS(
const QString& nsURI,
const QString& qName,
double value)
4748 x.setNum(value,
'g', 17);
4749 IMPL->setAttributeNS(nsURI, qName, x);
4753
4754
4755
4756
4757
4758void QDomElement::removeAttributeNS(
const QString& nsURI,
const QString& localName)
4762 QDomNodePrivate *n = IMPL->attributeNodeNS(nsURI, localName);
4765 IMPL->removeAttribute(n->nodeName());
4769
4770
4771
4772
4773
4774
4775
4776QDomAttr QDomElement::attributeNodeNS(
const QString& nsURI,
const QString& localName)
4780 return QDomAttr(IMPL->attributeNodeNS(nsURI, localName));
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793QDomAttr QDomElement::setAttributeNodeNS(
const QDomAttr& newAttr)
4797 return QDomAttr(IMPL->setAttributeNodeNS(
static_cast<QDomAttrPrivate *>(newAttr.impl)));
4801
4802
4803
4804
4805
4806
4807
4808
4809QDomNodeList QDomElement::elementsByTagNameNS(
const QString& nsURI,
const QString& localName)
const
4811 return QDomNodeList(
new QDomNodeListPrivate(impl, nsURI, localName));
4815
4816
4817
4818
4819bool QDomElement::hasAttributeNS(
const QString& nsURI,
const QString& localName)
const
4823 return IMPL->hasAttributeNS(nsURI, localName);
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840QString QDomElement::text()
const
4844 return IMPL->text();
4850
4851
4852
4853
4855QDomTextPrivate::QDomTextPrivate(QDomDocumentPrivate* d, QDomNodePrivate* parent,
const QString& val)
4856 : QDomCharacterDataPrivate(d, parent, val)
4861QDomTextPrivate::QDomTextPrivate(QDomTextPrivate* n,
bool deep)
4862 : QDomCharacterDataPrivate(n, deep)
4866QDomNodePrivate* QDomTextPrivate::cloneNode(
bool deep)
4868 QDomNodePrivate* p =
new QDomTextPrivate(
this, deep);
4874QDomTextPrivate* QDomTextPrivate::splitText(
int offset)
4877 qWarning(
"QDomText::splitText The node has no parent. So I cannot split");
4881 QDomTextPrivate* t =
new QDomTextPrivate(ownerDocument(),
nullptr, value.mid(offset));
4882 value.truncate(offset);
4884 parent()->insertAfter(t,
this);
4885 Q_ASSERT(t->ref.loadRelaxed() == 2);
4893void QDomTextPrivate::save(QTextStream& s,
int,
int)
const
4895 QDomTextPrivate *that =
const_cast<QDomTextPrivate*>(
this);
4896 s << encodeText(value, !(that->parent() && that->parent()->isElement()),
false,
true);
4900
4901
4902
4903
4905#define IMPL static_cast<QDomTextPrivate *>(impl)
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4926
4927
4928
4929
4931 : QDomCharacterData()
4936
4937
4938
4939
4940
4941
4942QDomText::QDomText(
const QDomText &text)
4943 : QDomCharacterData(text)
4947QDomText::QDomText(QDomTextPrivate* n)
4948 : QDomCharacterData(n)
4953
4954
4955
4956
4957
4958
4959QDomText &QDomText::operator=(
const QDomText &other) =
default;
4962
4963
4964
4965
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977QDomText QDomText::splitText(
int offset)
4981 return QDomText(IMPL->splitText(offset));
4987
4988
4989
4990
4992QDomCommentPrivate::QDomCommentPrivate(QDomDocumentPrivate* d, QDomNodePrivate* parent,
const QString& val)
4993 : QDomCharacterDataPrivate(d, parent, val)
4995 name = u"#comment"_s;
4998QDomCommentPrivate::QDomCommentPrivate(QDomCommentPrivate* n,
bool deep)
4999 : QDomCharacterDataPrivate(n, deep)
5004QDomNodePrivate* QDomCommentPrivate::cloneNode(
bool deep)
5006 QDomNodePrivate* p =
new QDomCommentPrivate(
this, deep);
5012void QDomCommentPrivate::save(QTextStream& s,
int depth,
int indent)
const
5015 if (!(prev && prev->isText()))
5016 s << QString(indent < 1 ? 0 : depth * indent, u' ');
5018 s <<
"<!--" << value;
5019 if (value.endsWith(u'-'))
5023 if (!(next && next->isText()))
5028
5029
5030
5031
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5055
5056
5057
5058QDomComment::QDomComment()
5059 : QDomCharacterData()
5064
5065
5066
5067
5068
5069
5070QDomComment::QDomComment(
const QDomComment &comment)
5071 : QDomCharacterData(comment)
5075QDomComment::QDomComment(QDomCommentPrivate* n)
5076 : QDomCharacterData(n)
5081
5082
5083
5084
5085
5086
5087QDomComment &QDomComment::operator=(
const QDomComment &other) =
default;
5090
5091
5092
5093
5096
5097
5098
5099
5101QDomCDATASectionPrivate::QDomCDATASectionPrivate(QDomDocumentPrivate* d, QDomNodePrivate* parent,
5103 : QDomTextPrivate(d, parent, val)
5105 name = u"#cdata-section"_s;
5108QDomCDATASectionPrivate::QDomCDATASectionPrivate(QDomCDATASectionPrivate* n,
bool deep)
5109 : QDomTextPrivate(n, deep)
5113QDomNodePrivate* QDomCDATASectionPrivate::cloneNode(
bool deep)
5115 QDomNodePrivate* p =
new QDomCDATASectionPrivate(
this, deep);
5121void QDomCDATASectionPrivate::save(QTextStream& s,
int,
int)
const
5125 s <<
"<![CDATA[" << value <<
"]]>";
5129
5130
5131
5132
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5160
5161
5162
5163QDomCDATASection::QDomCDATASection()
5169
5170
5171
5172
5173
5174
5175QDomCDATASection::QDomCDATASection(
const QDomCDATASection &cdataSection)
5176 : QDomText(cdataSection)
5180QDomCDATASection::QDomCDATASection(QDomCDATASectionPrivate* n)
5186
5187
5188
5189
5190
5191
5192QDomCDATASection &QDomCDATASection::operator=(
const QDomCDATASection &other) =
default;
5195
5196
5197
5198
5201
5202
5203
5204
5206QDomNotationPrivate::QDomNotationPrivate(QDomDocumentPrivate* d, QDomNodePrivate* parent,
5207 const QString& aname,
5208 const QString& pub,
const QString& sys)
5209 : QDomNodePrivate(d, parent)
5216QDomNotationPrivate::QDomNotationPrivate(QDomNotationPrivate* n,
bool deep)
5217 : QDomNodePrivate(n, deep)
5223QDomNodePrivate* QDomNotationPrivate::cloneNode(
bool deep)
5225 QDomNodePrivate* p =
new QDomNotationPrivate(
this, deep);
5231void QDomNotationPrivate::save(QTextStream& s,
int,
int)
const
5233 s <<
"<!NOTATION " << name <<
' ';
5234 if (!m_pub.isNull()) {
5235 s <<
"PUBLIC " << quotedValue(m_pub);
5236 if (!m_sys.isNull())
5237 s <<
' ' << quotedValue(m_sys);
5239 s <<
"SYSTEM " << quotedValue(m_sys);
5241 s <<
'>' << Qt::endl;
5245
5246
5247
5248
5250#define IMPL static_cast<QDomNotationPrivate *>(impl)
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5282
5283
5284QDomNotation::QDomNotation()
5290
5291
5292
5293
5294
5295
5296QDomNotation::QDomNotation(
const QDomNotation ¬ation)
5297 : QDomNode(notation)
5301QDomNotation::QDomNotation(QDomNotationPrivate* n)
5307
5308
5309
5310
5311
5312
5313QDomNotation &QDomNotation::operator=(
const QDomNotation &other) =
default;
5316
5317
5318
5319
5322
5323
5324QString QDomNotation::publicId()
const
5332
5333
5334QString QDomNotation::systemId()
const
5344
5345
5346
5347
5349QDomEntityPrivate::QDomEntityPrivate(QDomDocumentPrivate* d, QDomNodePrivate* parent,
5350 const QString& aname,
5351 const QString& pub,
const QString& sys,
const QString& notation)
5352 : QDomNodePrivate(d, parent)
5357 m_notationName = notation;
5360QDomEntityPrivate::QDomEntityPrivate(QDomEntityPrivate* n,
bool deep)
5361 : QDomNodePrivate(n, deep)
5365 m_notationName = n->m_notationName;
5368QDomNodePrivate* QDomEntityPrivate::cloneNode(
bool deep)
5370 QDomNodePrivate* p =
new QDomEntityPrivate(
this, deep);
5377
5378
5379static QByteArray encodeEntity(
const QByteArray& str)
5381 QByteArray tmp(str);
5382 int len = tmp.size();
5384 const char* d = tmp.constData();
5387 tmp.replace(i, 1,
"<");
5388 d = tmp.constData();
5392 else if (d[i] ==
'"') {
5393 tmp.replace(i, 1,
""");
5394 d = tmp.constData();
5397 }
else if (d[i] ==
'&' && i + 1 < len && d[i+1] ==
'#') {
5400 tmp.replace(i, 1,
"&");
5401 d = tmp.constData();
5412void QDomEntityPrivate::save(QTextStream& s,
int,
int)
const
5414 QString _name = name;
5415 if (_name.startsWith(u'%'))
5416 _name = u"% "_s + _name.mid(1);
5418 if (m_sys.isNull() && m_pub.isNull()) {
5419 s <<
"<!ENTITY " << _name <<
" \"" << encodeEntity(value.toUtf8()) <<
"\">" << Qt::endl;
5421 s <<
"<!ENTITY " << _name <<
' ';
5422 if (m_pub.isNull()) {
5423 s <<
"SYSTEM " << quotedValue(m_sys);
5425 s <<
"PUBLIC " << quotedValue(m_pub) <<
' ' << quotedValue(m_sys);
5427 if (! m_notationName.isNull()) {
5428 s <<
" NDATA " << m_notationName;
5430 s <<
'>' << Qt::endl;
5435
5436
5437
5438
5440#define IMPL static_cast<QDomEntityPrivate *>(impl)
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5475
5476
5477QDomEntity::QDomEntity()
5484
5485
5486
5487
5488
5489
5490QDomEntity::QDomEntity(
const QDomEntity &entity)
5495QDomEntity::QDomEntity(QDomEntityPrivate* n)
5501
5502
5503
5504
5505
5506
5507QDomEntity &QDomEntity::operator=(
const QDomEntity &other) =
default;
5510
5511
5512
5513
5516
5517
5518
5519QString QDomEntity::publicId()
const
5527
5528
5529
5530QString QDomEntity::systemId()
const
5538
5539
5540
5541
5542QString QDomEntity::notationName()
const
5546 return IMPL->m_notationName;
5552
5553
5554
5555
5557QDomEntityReferencePrivate::QDomEntityReferencePrivate(QDomDocumentPrivate* d, QDomNodePrivate* parent,
const QString& aname)
5558 : QDomNodePrivate(d, parent)
5563QDomEntityReferencePrivate::QDomEntityReferencePrivate(QDomNodePrivate* n,
bool deep)
5564 : QDomNodePrivate(n, deep)
5568QDomNodePrivate* QDomEntityReferencePrivate::cloneNode(
bool deep)
5570 QDomNodePrivate* p =
new QDomEntityReferencePrivate(
this, deep);
5576void QDomEntityReferencePrivate::save(QTextStream& s,
int,
int)
const
5578 s <<
'&' << name <<
';';
5582
5583
5584
5585
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5623
5624
5625
5626
5627QDomEntityReference::QDomEntityReference()
5633
5634
5635
5636
5637
5638
5639QDomEntityReference::QDomEntityReference(
const QDomEntityReference &entityReference)
5640 : QDomNode(entityReference)
5644QDomEntityReference::QDomEntityReference(QDomEntityReferencePrivate* n)
5650
5651
5652
5653
5654
5655
5656QDomEntityReference &QDomEntityReference::operator=(
const QDomEntityReference &other) =
default;
5659
5660
5661
5662
5665
5666
5667
5668
5670QDomProcessingInstructionPrivate::QDomProcessingInstructionPrivate(QDomDocumentPrivate* d,
5671 QDomNodePrivate* parent,
const QString& target,
const QString& data)
5672 : QDomNodePrivate(d, parent)
5678QDomProcessingInstructionPrivate::QDomProcessingInstructionPrivate(QDomProcessingInstructionPrivate* n,
bool deep)
5679 : QDomNodePrivate(n, deep)
5684QDomNodePrivate* QDomProcessingInstructionPrivate::cloneNode(
bool deep)
5686 QDomNodePrivate* p =
new QDomProcessingInstructionPrivate(
this, deep);
5692void QDomProcessingInstructionPrivate::save(QTextStream& s,
int,
int)
const
5694 s <<
"<?" << name <<
' ' << value <<
"?>" << Qt::endl;
5698
5699
5700
5701
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
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5745
5746
5747
5748
5749QDomProcessingInstruction::QDomProcessingInstruction()
5755
5756
5757
5758
5759
5760
5761QDomProcessingInstruction::QDomProcessingInstruction(
const QDomProcessingInstruction &processingInstruction)
5762 : QDomNode(processingInstruction)
5766QDomProcessingInstruction::QDomProcessingInstruction(QDomProcessingInstructionPrivate* n)
5772
5773
5774
5775
5776
5777
5778QDomProcessingInstruction &
5779QDomProcessingInstruction::operator=(
const QDomProcessingInstruction &other) =
default;
5782
5783
5784
5785
5788
5789
5790
5791
5792QString QDomProcessingInstruction::target()
const
5796 return impl->nodeName();
5800
5801
5802
5803
5804QString QDomProcessingInstruction::data()
const
5808 return impl->nodeValue();
5812
5813
5814
5815
5816void QDomProcessingInstruction::setData(
const QString &data)
5819 impl->setNodeValue(data);
5823
5824
5825
5826
5828QDomDocumentPrivate::QDomDocumentPrivate()
5829 : QDomNodePrivate(
nullptr),
5830 impl(
new QDomImplementationPrivate),
5833 type =
new QDomDocumentTypePrivate(
this,
this);
5836 name = u"#document"_s;
5839QDomDocumentPrivate::QDomDocumentPrivate(
const QString& aname)
5840 : QDomNodePrivate(
nullptr),
5841 impl(
new QDomImplementationPrivate),
5844 type =
new QDomDocumentTypePrivate(
this,
this);
5848 name = u"#document"_s;
5851QDomDocumentPrivate::QDomDocumentPrivate(QDomDocumentTypePrivate* dt)
5852 : QDomNodePrivate(
nullptr),
5853 impl(
new QDomImplementationPrivate),
5856 if (dt !=
nullptr) {
5859 type =
new QDomDocumentTypePrivate(
this,
this);
5863 name = u"#document"_s;
5866QDomDocumentPrivate::QDomDocumentPrivate(QDomDocumentPrivate* n,
bool deep)
5867 : QDomNodePrivate(n, deep),
5868 impl(n->impl->clone()),
5871 type =
static_cast<QDomDocumentTypePrivate*>(n->type->cloneNode());
5872 type->setParent(
this);
5875QDomDocumentPrivate::~QDomDocumentPrivate()
5879void QDomDocumentPrivate::clear()
5883 QDomNodePrivate::clear();
5886QDomDocument::ParseResult QDomDocumentPrivate::setContent(QXmlStreamReader *reader,
5887 QDomDocument::ParseOptions options)
5890 impl =
new QDomImplementationPrivate;
5891 type =
new QDomDocumentTypePrivate(
this,
this);
5895 const auto error = u"Failed to set content, XML reader is not initialized"_s;
5896 qWarning(
"%s", qPrintable(error));
5900 QDomParser domParser(
this, reader, options);
5902 if (!domParser.parse())
5903 return domParser.result();
5907QDomNodePrivate* QDomDocumentPrivate::cloneNode(
bool deep)
5909 QDomNodePrivate *p =
new QDomDocumentPrivate(
this, deep);
5915QDomElementPrivate* QDomDocumentPrivate::documentElement()
5917 QDomNodePrivate *p = first;
5918 while (p && !p->isElement())
5921 return static_cast<QDomElementPrivate *>(p);
5924QDomElementPrivate* QDomDocumentPrivate::createElement(
const QString &tagName)
5927 QString fixedName = fixedXmlName(tagName, &ok);
5931 QDomElementPrivate *e =
new QDomElementPrivate(
this,
nullptr, fixedName);
5936QDomElementPrivate* QDomDocumentPrivate::createElementNS(
const QString &nsURI,
const QString &qName)
5939 QString fixedName = fixedXmlName(qName, &ok,
true);
5943 QDomElementPrivate *e =
new QDomElementPrivate(
this,
nullptr, nsURI, fixedName);
5948QDomDocumentFragmentPrivate* QDomDocumentPrivate::createDocumentFragment()
5950 QDomDocumentFragmentPrivate *f =
new QDomDocumentFragmentPrivate(
this,
nullptr);
5955QDomTextPrivate* QDomDocumentPrivate::createTextNode(
const QString &data)
5958 QString fixedData = fixedCharData(data, &ok);
5962 QDomTextPrivate *t =
new QDomTextPrivate(
this,
nullptr, fixedData);
5967QDomCommentPrivate* QDomDocumentPrivate::createComment(
const QString &data)
5970 QString fixedData = fixedComment(data, &ok);
5974 QDomCommentPrivate *c =
new QDomCommentPrivate(
this,
nullptr, fixedData);
5979QDomCDATASectionPrivate* QDomDocumentPrivate::createCDATASection(
const QString &data)
5982 QString fixedData = fixedCDataSection(data, &ok);
5986 QDomCDATASectionPrivate *c =
new QDomCDATASectionPrivate(
this,
nullptr, fixedData);
5991QDomProcessingInstructionPrivate* QDomDocumentPrivate::createProcessingInstruction(
const QString &target,
5992 const QString &data)
5995 QString fixedData = fixedPIData(data, &ok);
5999 QString fixedTarget = fixedXmlName(target, &ok);
6003 QDomProcessingInstructionPrivate *p =
new QDomProcessingInstructionPrivate(
this,
nullptr, fixedTarget, fixedData);
6007QDomAttrPrivate* QDomDocumentPrivate::createAttribute(
const QString &aname)
6010 QString fixedName = fixedXmlName(aname, &ok);
6014 QDomAttrPrivate *a =
new QDomAttrPrivate(
this,
nullptr, fixedName);
6019QDomAttrPrivate* QDomDocumentPrivate::createAttributeNS(
const QString &nsURI,
const QString &qName)
6022 QString fixedName = fixedXmlName(qName, &ok,
true);
6026 QDomAttrPrivate *a =
new QDomAttrPrivate(
this,
nullptr, nsURI, fixedName);
6031QDomEntityReferencePrivate* QDomDocumentPrivate::createEntityReference(
const QString &aname)
6034 QString fixedName = fixedXmlName(aname, &ok);
6038 QDomEntityReferencePrivate *e =
new QDomEntityReferencePrivate(
this,
nullptr, fixedName);
6043QDomNodePrivate* QDomDocumentPrivate::importNode(QDomNodePrivate *importedNode,
bool deep)
6045 QDomNodePrivate *node =
nullptr;
6046 switch (importedNode->nodeType()) {
6047 case QDomNode::AttributeNode:
6048 node =
new QDomAttrPrivate(
static_cast<QDomAttrPrivate *>(importedNode),
true);
6050 case QDomNode::DocumentFragmentNode:
6051 node =
new QDomDocumentFragmentPrivate(
6052 static_cast<QDomDocumentFragmentPrivate *>(importedNode), deep);
6054 case QDomNode::ElementNode:
6055 node =
new QDomElementPrivate(
static_cast<QDomElementPrivate *>(importedNode), deep);
6057 case QDomNode::EntityNode:
6058 node =
new QDomEntityPrivate(
static_cast<QDomEntityPrivate *>(importedNode), deep);
6060 case QDomNode::EntityReferenceNode:
6061 node =
new QDomEntityReferencePrivate(
6062 static_cast<QDomEntityReferencePrivate *>(importedNode),
false);
6064 case QDomNode::NotationNode:
6065 node =
new QDomNotationPrivate(
static_cast<QDomNotationPrivate *>(importedNode), deep);
6067 case QDomNode::ProcessingInstructionNode:
6068 node =
new QDomProcessingInstructionPrivate(
6069 static_cast<QDomProcessingInstructionPrivate *>(importedNode), deep);
6071 case QDomNode::TextNode:
6072 node =
new QDomTextPrivate(
static_cast<QDomTextPrivate *>(importedNode), deep);
6074 case QDomNode::CDATASectionNode:
6075 node =
new QDomCDATASectionPrivate(
static_cast<QDomCDATASectionPrivate *>(importedNode),
6078 case QDomNode::CommentNode:
6079 node =
new QDomCommentPrivate(
static_cast<QDomCommentPrivate *>(importedNode), deep);
6085 node->setOwnerDocument(
this);
6093void QDomDocumentPrivate::saveDocument(QTextStream& s,
const int indent, QDomNode::EncodingPolicy encUsed)
const
6095 const QDomNodePrivate* n = first;
6097 if (encUsed == QDomNode::EncodingFromDocument) {
6098#if QT_CONFIG(regularexpression)
6099 const QDomNodePrivate* n = first;
6101 if (n && n->isProcessingInstruction() && n->nodeName() ==
"xml"_L1) {
6103 QString data = n->nodeValue();
6104 QRegularExpression encoding(QString::fromLatin1(
"encoding\\s*=\\s*((\"([^\"]*)\")|('([^']*)'))"));
6105 auto match = encoding.match(data);
6106 QString enc = match.captured(3);
6108 enc = match.captured(5);
6109 if (!enc.isEmpty()) {
6110 auto encoding = QStringConverter::encodingForName(enc.toUtf8().constData());
6112 qWarning() <<
"QDomDocument::save(): Unsupported encoding" << enc <<
"specified.";
6114 s.setEncoding(encoding.value());
6121 if (!doc && !(n->isProcessingInstruction() && n->nodeName() ==
"xml"_L1)) {
6123 type->save(s, 0, indent);
6126 n->saveSubTree(n, s, 0, indent);
6133 const QByteArray codecName = QStringConverter::nameForEncoding(s.encoding());
6135 s <<
"<?xml version=\"1.0\" encoding=\""
6140 const QDomNodePrivate* startNode = n;
6144 if (n->isProcessingInstruction() && n->nodeName() ==
"xml"_L1) {
6145 startNode = n->next;
6154 startNode->saveSubTree(startNode, s, 0, indent);
6155 startNode = startNode->next;
6161
6162
6163
6164
6166#define IMPL static_cast<QDomDocumentPrivate *>(impl)
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
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6247
6248
6249QDomDocument::QDomDocument()
6255
6256
6257
6258QDomDocument::QDomDocument(
const QString& name)
6261 impl =
new QDomDocumentPrivate(name);
6265
6266
6267
6268
6269QDomDocument::QDomDocument(
const QDomDocumentType& doctype)
6271 impl =
new QDomDocumentPrivate(
static_cast<QDomDocumentTypePrivate *>(doctype.impl));
6275
6276
6277
6278
6279
6280
6281QDomDocument::QDomDocument(
const QDomDocument &document)
6282 : QDomNode(document)
6286QDomDocument::QDomDocument(QDomDocumentPrivate *pimpl)
6292
6293
6294
6295
6296
6297
6298QDomDocument &QDomDocument::operator=(
const QDomDocument &other) =
default;
6301
6302
6303QDomDocument::~QDomDocument()
6307#if QT_DEPRECATED_SINCE(6
, 8
)
6309QT_WARNING_DISABLE_DEPRECATED
6311
6312
6313
6314
6315
6316
6317
6318
6319bool QDomDocument::setContent(
const QString& text,
bool namespaceProcessing,
6320 QString *errorMsg,
int *errorLine,
int *errorColumn)
6322 QXmlStreamReader reader(text);
6323 reader.setNamespaceProcessing(namespaceProcessing);
6324 return setContent(&reader, namespaceProcessing, errorMsg, errorLine, errorColumn);
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
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379bool QDomDocument::setContent(
const QByteArray &data,
bool namespaceProcessing,
6380 QString *errorMsg,
int *errorLine,
int *errorColumn)
6382 QXmlStreamReader reader(data);
6383 reader.setNamespaceProcessing(namespaceProcessing);
6384 return setContent(&reader, namespaceProcessing, errorMsg, errorLine, errorColumn);
6387static inline QDomDocument::ParseOptions toParseOptions(
bool namespaceProcessing)
6389 return namespaceProcessing ? QDomDocument::ParseOption::UseNamespaceProcessing
6390 : QDomDocument::ParseOption::Default;
6393static inline void unpackParseResult(
const QDomDocument::ParseResult &parseResult,
6394 QString *errorMsg,
int *errorLine,
int *errorColumn)
6398 *errorMsg = parseResult.errorMessage;
6400 *errorLine =
static_cast<
int>(parseResult.errorLine);
6402 *errorColumn =
static_cast<
int>(parseResult.errorColumn);
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418bool QDomDocument::setContent(QIODevice* dev,
bool namespaceProcessing,
6419 QString *errorMsg,
int *errorLine,
int *errorColumn)
6421 ParseResult result = setContent(dev, toParseOptions(namespaceProcessing));
6422 unpackParseResult(result, errorMsg, errorLine, errorColumn);
6423 return bool(result);
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437bool QDomDocument::setContent(
const QString& text, QString *errorMsg,
int *errorLine,
int *errorColumn)
6439 return setContent(text,
false, errorMsg, errorLine, errorColumn);
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452bool QDomDocument::setContent(
const QByteArray& buffer, QString *errorMsg,
int *errorLine,
int *errorColumn )
6454 return setContent(buffer,
false, errorMsg, errorLine, errorColumn);
6458
6459
6460
6461
6462
6463
6464
6465
6466bool QDomDocument::setContent(QIODevice* dev, QString *errorMsg,
int *errorLine,
int *errorColumn )
6468 return setContent(dev,
false, errorMsg, errorLine, errorColumn);
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491bool QDomDocument::setContent(QXmlStreamReader *reader,
bool namespaceProcessing,
6492 QString *errorMsg,
int *errorLine,
int *errorColumn)
6494 ParseResult result = setContent(reader, toParseOptions(namespaceProcessing));
6495 unpackParseResult(result, errorMsg, errorLine, errorColumn);
6496 return bool(result);
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6532
6533
6534
6535
6536
6537
6538
6541
6542
6543
6544
6545
6546
6547
6550
6551
6552
6553
6554
6555
6556
6559
6560
6561
6562
6563
6564
6565
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
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612QDomDocument::ParseResult QDomDocument::setContentImpl(
const QByteArray &data, ParseOptions options)
6614 QXmlStreamReader reader(data);
6615 reader.setNamespaceProcessing(options.testFlag(ParseOption::UseNamespaceProcessing));
6616 return setContent(&reader, options);
6619QDomDocument::ParseResult QDomDocument::setContent(QAnyStringView data, ParseOptions options)
6621 QXmlStreamReader reader(data);
6622 reader.setNamespaceProcessing(options.testFlag(ParseOption::UseNamespaceProcessing));
6623 return setContent(&reader, options);
6626QDomDocument::ParseResult QDomDocument::setContent(QIODevice *device, ParseOptions options)
6628#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
6629 if (!device->isOpen()) {
6630 qWarning(
"QDomDocument called with unopened QIODevice. "
6631 "This will not be supported in future Qt versions.");
6632 if (!device->open(QIODevice::ReadOnly)) {
6633 const auto error = u"QDomDocument::setContent: Failed to open device."_s;
6634 qWarning(
"%s", qPrintable(error));
6640 QXmlStreamReader reader(device);
6641 reader.setNamespaceProcessing(options.testFlag(ParseOption::UseNamespaceProcessing));
6642 return setContent(&reader, options);
6645QDomDocument::ParseResult QDomDocument::setContent(QXmlStreamReader *reader, ParseOptions options)
6648 impl =
new QDomDocumentPrivate();
6649 return IMPL->setContent(reader, options);
6653
6654
6655
6656
6657
6658
6659
6660QString QDomDocument::toString(
int indent)
const
6663 QTextStream s(&str, QIODevice::WriteOnly);
6669
6670
6671
6672
6673
6674
6675
6676
6677QByteArray QDomDocument::toByteArray(
int indent)
const
6681 return toString(indent).toUtf8();
6686
6687
6688QDomDocumentType QDomDocument::doctype()
const
6691 return QDomDocumentType();
6692 return QDomDocumentType(IMPL->doctype());
6696
6697
6698QDomImplementation QDomDocument::implementation()
const
6701 return QDomImplementation();
6702 return QDomImplementation(IMPL->implementation());
6706
6707
6708QDomElement QDomDocument::documentElement()
const
6711 return QDomElement();
6712 return QDomElement(IMPL->documentElement());
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725QDomElement QDomDocument::createElement(
const QString& tagName)
6728 impl =
new QDomDocumentPrivate();
6729 return QDomElement(IMPL->createElement(tagName));
6733
6734
6735
6736
6737QDomDocumentFragment QDomDocument::createDocumentFragment()
6740 impl =
new QDomDocumentPrivate();
6741 return QDomDocumentFragment(IMPL->createDocumentFragment());
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754QDomText QDomDocument::createTextNode(
const QString& value)
6757 impl =
new QDomDocumentPrivate();
6758 return QDomText(IMPL->createTextNode(value));
6762
6763
6764
6765
6766
6767
6768
6769
6770QDomComment QDomDocument::createComment(
const QString& value)
6773 impl =
new QDomDocumentPrivate();
6774 return QDomComment(IMPL->createComment(value));
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787QDomCDATASection QDomDocument::createCDATASection(
const QString& value)
6790 impl =
new QDomDocumentPrivate();
6791 return QDomCDATASection(IMPL->createCDATASection(value));
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806QDomProcessingInstruction QDomDocument::createProcessingInstruction(
const QString& target,
6807 const QString& data)
6810 impl =
new QDomDocumentPrivate();
6811 return QDomProcessingInstruction(IMPL->createProcessingInstruction(target, data));
6816
6817
6818
6819
6820
6821
6822
6823
6824QDomAttr QDomDocument::createAttribute(
const QString& name)
6827 impl =
new QDomDocumentPrivate();
6828 return QDomAttr(IMPL->createAttribute(name));
6832
6833
6834
6835
6836
6837
6838
6839
6840QDomEntityReference QDomDocument::createEntityReference(
const QString& name)
6843 impl =
new QDomDocumentPrivate();
6844 return QDomEntityReference(IMPL->createEntityReference(name));
6848
6849
6850
6851
6852
6853
6854
6855QDomNodeList QDomDocument::elementsByTagName(
const QString& tagname)
const
6857 return QDomNodeList(
new QDomNodeListPrivate(impl, tagname));
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
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929QDomNode QDomDocument::importNode(
const QDomNode& importedNode,
bool deep)
6931 if (importedNode.isNull())
6934 impl =
new QDomDocumentPrivate();
6935 return QDomNode(IMPL->importNode(importedNode.impl, deep));
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950QDomElement QDomDocument::createElementNS(
const QString& nsURI,
const QString& qName)
6953 impl =
new QDomDocumentPrivate();
6954 return QDomElement(IMPL->createElementNS(nsURI, qName));
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969QDomAttr QDomDocument::createAttributeNS(
const QString& nsURI,
const QString& qName)
6972 impl =
new QDomDocumentPrivate();
6973 return QDomAttr(IMPL->createAttributeNS(nsURI, qName));
6977
6978
6979
6980
6981
6982
6983
6984QDomNodeList QDomDocument::elementsByTagNameNS(
const QString& nsURI,
const QString& localName)
6986 return QDomNodeList(
new QDomNodeListPrivate(impl, nsURI, localName));
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999QDomElement QDomDocument::elementById(
const QString& )
7001 qWarning(
"elementById() is not implemented and will always return a null node.");
7002 return QDomElement();
7006
7007
7008
7009
7014
7015
7016
7017
7020
7021
7022
7023
7024
7025QDomAttr QDomNode::toAttr()
const
7027 if (impl && impl->isAttr())
7028 return QDomAttr(
static_cast<QDomAttrPrivate *>(impl));
7033
7034
7035
7036
7037
7038QDomCDATASection QDomNode::toCDATASection()
const
7040 if (impl && impl->isCDATASection())
7041 return QDomCDATASection(
static_cast<QDomCDATASectionPrivate *>(impl));
7042 return QDomCDATASection();
7046
7047
7048
7049
7050
7051QDomDocumentFragment QDomNode::toDocumentFragment()
const
7053 if (impl && impl->isDocumentFragment())
7054 return QDomDocumentFragment(
static_cast<QDomDocumentFragmentPrivate *>(impl));
7055 return QDomDocumentFragment();
7059
7060
7061
7062
7063
7064QDomDocument QDomNode::toDocument()
const
7066 if (impl && impl->isDocument())
7067 return QDomDocument(
static_cast<QDomDocumentPrivate *>(impl));
7068 return QDomDocument();
7072
7073
7074
7075
7076
7077QDomDocumentType QDomNode::toDocumentType()
const
7079 if (impl && impl->isDocumentType())
7080 return QDomDocumentType(
static_cast<QDomDocumentTypePrivate *>(impl));
7081 return QDomDocumentType();
7085
7086
7087
7088
7089
7090QDomElement QDomNode::toElement()
const
7092 if (impl && impl->isElement())
7093 return QDomElement(
static_cast<QDomElementPrivate *>(impl));
7094 return QDomElement();
7098
7099
7100
7101
7102
7103QDomEntityReference QDomNode::toEntityReference()
const
7105 if (impl && impl->isEntityReference())
7106 return QDomEntityReference(
static_cast<QDomEntityReferencePrivate *>(impl));
7107 return QDomEntityReference();
7111
7112
7113
7114
7115
7116QDomText QDomNode::toText()
const
7118 if (impl && impl->isText())
7119 return QDomText(
static_cast<QDomTextPrivate *>(impl));
7124
7125
7126
7127
7128
7129QDomEntity QDomNode::toEntity()
const
7131 if (impl && impl->isEntity())
7132 return QDomEntity(
static_cast<QDomEntityPrivate *>(impl));
7133 return QDomEntity();
7137
7138
7139
7140
7141
7142QDomNotation QDomNode::toNotation()
const
7144 if (impl && impl->isNotation())
7145 return QDomNotation(
static_cast<QDomNotationPrivate *>(impl));
7146 return QDomNotation();
7150
7151
7152
7153
7154
7155QDomProcessingInstruction QDomNode::toProcessingInstruction()
const
7157 if (impl && impl->isProcessingInstruction())
7158 return QDomProcessingInstruction(
static_cast<QDomProcessingInstructionPrivate *>(impl));
7159 return QDomProcessingInstruction();
7163
7164
7165
7166
7167
7168QDomCharacterData QDomNode::toCharacterData()
const
7170 if (impl && impl->isCharacterData())
7171 return QDomCharacterData(
static_cast<QDomCharacterDataPrivate *>(impl));
7172 return QDomCharacterData();
7176
7177
7178
7179
7180
7181QDomComment QDomNode::toComment()
const
7183 if (impl && impl->isComment())
7184 return QDomComment(
static_cast<QDomCommentPrivate *>(impl));
7185 return QDomComment();
7189
7190
7191
7192