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::AcceptInvalidChars;
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
555
556
557
558
559
560
561
562
563
564
565
568
569
570
571
572
573
574
575
577QDomImplementation::InvalidDataPolicy QDomImplementation::invalidDataPolicy()
579 return QDomImplementationPrivate::invalidDataPolicy;
583
584
585
586
587
588
589
590
591
592
593
594
595
597void QDomImplementation::setInvalidDataPolicy(InvalidDataPolicy policy)
599 QDomImplementationPrivate::invalidDataPolicy = policy;
603
604
605
606
608QDomNodeListPrivate::QDomNodeListPrivate(QDomNodePrivate *n_impl) : ref(1)
612 node_impl->ref.ref();
616QDomNodeListPrivate::QDomNodeListPrivate(QDomNodePrivate *n_impl,
const QString &name) :
621 node_impl->ref.ref();
626QDomNodeListPrivate::QDomNodeListPrivate(QDomNodePrivate *n_impl,
const QString &_nsURI,
const QString &localName) :
631 node_impl->ref.ref();
637QDomNodeListPrivate::~QDomNodeListPrivate()
639 if (node_impl && !node_impl->ref.deref())
643bool QDomNodeListPrivate::operator==(
const QDomNodeListPrivate &other)
const noexcept
645 return (node_impl == other.node_impl) && (tagname == other.tagname);
648void QDomNodeListPrivate::createList()
const
654 const QDomDocumentPrivate *
const doc = node_impl->ownerDocument();
655 if (doc && timestamp != doc->nodeListTime)
656 timestamp = doc->nodeListTime;
657 forEachNode([&](QDomNodePrivate *p){ list.append(p); });
661
662
663
664
665bool QDomNodeListPrivate::checkNode(QDomNodePrivate *p)
const
667 return p && p->isElement() && (nsURI.isNull()
668 ? p->nodeName() == tagname
669 : p->name == tagname && p->namespaceURI == nsURI);
673
674
675
676
677
678
679
680
681QDomNodePrivate *QDomNodeListPrivate::findNextInOrder(QDomNodePrivate *p)
const
686 if (tagname.isNull()) {
689 else if (p && p->next)
693 if (p == node_impl) {
698 while (p && p != node_impl) {
701 }
else if (p->next) {
705 while (p && p != node_impl && !p->next)
707 if (p && p != node_impl)
717
718
719
720
721
722QDomNodePrivate *QDomNodeListPrivate::findPrevInOrder(QDomNodePrivate *p)
const
727 if (tagname.isNull() && p == node_impl)
729 if (tagname.isNull())
734 if (p == node_impl) {
756void QDomNodeListPrivate::forEachNode(qxp::function_ref<
void(QDomNodePrivate*)> yield)
const
761 QDomNodePrivate *current = findNextInOrder(node_impl);
762 while (current && current != node_impl) {
764 current = findNextInOrder(current);
768bool QDomNodeListPrivate::maybeCreateList()
const
773 const QDomDocumentPrivate *
const doc = node_impl->ownerDocument();
774 if (!doc || timestamp != doc->nodeListTime)
780QDomNodePrivate *QDomNodeListPrivate::item(
int index)
782 if (!maybeCreateList() || index >= list.size() || index < 0)
785 return list.at(index);
788int QDomNodeListPrivate::length()
const
790 if (!maybeCreateList())
796int QDomNodeListPrivate::noexceptLength()
const noexcept
799 forEachNode([&](QDomNodePrivate*){ ++count; });
804
805
806
807
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
835
836
837QDomNodeList::QDomNodeList()
842QDomNodeList::QDomNodeList(QDomNodeListPrivate *pimpl)
848
849
850QDomNodeList::QDomNodeList(
const QDomNodeList &nodeList)
851 : impl(nodeList.impl)
858
859
860QDomNodeList& QDomNodeList::operator=(
const QDomNodeList &other)
863 other.impl->ref.ref();
864 if (impl && !impl->ref.deref())
871
872
873
874
875
876bool comparesEqual(
const QDomNodeList &lhs,
const QDomNodeList &rhs)
noexcept
878 if (lhs.impl == rhs.impl)
880 if (!lhs.impl || !rhs.impl)
882 return *lhs.impl == *rhs.impl;
886
887
888
889
890
893
894
895QDomNodeList::~QDomNodeList()
897 if (impl && !impl->ref.deref())
902
903
904
905
906
907
908
909
910QDomNode QDomNodeList::item(
int index)
const
915 return QDomNode(impl->item(index));
919
920
921int QDomNodeList::length()
const
925 return impl->length();
929
930
931int QDomNodeList::noexceptLength()
const noexcept
935 return impl->noexceptLength();
939
940
941
942
943
946
947
948
949
952
953
954
955
958
959
960
961
962
963
964
965
966
969
970
971
972
973
974
975
976
977
978
981
982
983
984
985
986
987
988
989
990
991
992
993
994
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1016QDomNodeList::It::It(
const QDomNodeListPrivate *lp,
bool start)
noexcept
1019 if (!lp || !lp->node_impl)
1022 current = lp->findNextInOrder(lp->node_impl);
1024 current = lp->node_impl;
1027QDomNodePrivate *QDomNodeList::It::findNextInOrder(
const QDomNodeListPrivate *parent, QDomNodePrivate *current)
1029 return parent->findNextInOrder(current);
1032QDomNodePrivate *QDomNodeList::It::findPrevInOrder(
const QDomNodeListPrivate *parent, QDomNodePrivate *current)
1034 return parent->findPrevInOrder(current);
1038
1039
1040
1041
1043inline void QDomNodePrivate::setOwnerDocument(QDomDocumentPrivate *doc)
1049QDomNodePrivate::QDomNodePrivate(QDomDocumentPrivate *doc, QDomNodePrivate *par) : ref(1)
1054 setOwnerDocument(doc);
1059 createdWithDom1Interface =
true;
1064QDomNodePrivate::QDomNodePrivate(QDomNodePrivate *n,
bool deep) : ref(1)
1066 setOwnerDocument(n->ownerDocument());
1075 namespaceURI = n->namespaceURI;
1076 createdWithDom1Interface = n->createdWithDom1Interface;
1083 for (QDomNodePrivate* x = n->first; x; x = x->next)
1084 appendChild(x->cloneNode(
true));
1087QDomNodePrivate::~QDomNodePrivate()
1089 QDomNodePrivate* p = first;
1094 if (!p->ref.deref())
1102void QDomNodePrivate::clear()
1104 QDomNodePrivate* p = first;
1109 if (!p->ref.deref())
1117QDomNodePrivate* QDomNodePrivate::namedItem(
const QString &n)
1119 QDomNodePrivate* p = first;
1121 if (p->nodeName() == n)
1129QDomNodePrivate* QDomNodePrivate::insertBefore(QDomNodePrivate* newChild, QDomNodePrivate* refChild)
1136 if (newChild == refChild)
1140 if (refChild && refChild->parent() !=
this)
1144 QDomDocumentPrivate *
const doc = ownerDocument();
1146 doc->nodeListTime++;
1150 if (newChild->isDocumentFragment()) {
1152 if (newChild->first ==
nullptr)
1156 QDomNodePrivate* n = newChild->first;
1163 if (!refChild || refChild->prev ==
nullptr) {
1165 first->prev = newChild->last;
1166 newChild->last->next = first;
1168 last = newChild->last;
1169 first = newChild->first;
1172 newChild->last->next = refChild;
1173 newChild->first->prev = refChild->prev;
1174 refChild->prev->next = newChild->first;
1175 refChild->prev = newChild->last;
1182 newChild->first =
nullptr;
1183 newChild->last =
nullptr;
1189 newChild->ref.ref();
1191 if (newChild->parent())
1192 newChild->parent()->removeChild(newChild);
1194 newChild->setParent(
this);
1198 first->prev = newChild;
1199 newChild->next = first;
1206 if (refChild->prev ==
nullptr) {
1208 first->prev = newChild;
1209 newChild->next = first;
1216 newChild->next = refChild;
1217 newChild->prev = refChild->prev;
1218 refChild->prev->next = newChild;
1219 refChild->prev = newChild;
1224QDomNodePrivate* QDomNodePrivate::insertAfter(QDomNodePrivate* newChild, QDomNodePrivate* refChild)
1231 if (newChild == refChild)
1235 if (refChild && refChild->parent() !=
this)
1239 QDomDocumentPrivate *
const doc = ownerDocument();
1241 doc->nodeListTime++;
1245 if (newChild->isDocumentFragment()) {
1247 if (newChild->first ==
nullptr)
1251 QDomNodePrivate* n = newChild->first;
1258 if (!refChild || refChild->next ==
nullptr) {
1260 last->next = newChild->first;
1261 newChild->first->prev = last;
1263 first = newChild->first;
1264 last = newChild->last;
1266 newChild->first->prev = refChild;
1267 newChild->last->next = refChild->next;
1268 refChild->next->prev = newChild->last;
1269 refChild->next = newChild->first;
1276 newChild->first =
nullptr;
1277 newChild->last =
nullptr;
1282 if (newChild->parent())
1283 newChild->parent()->removeChild(newChild);
1287 newChild->ref.ref();
1289 newChild->setParent(
this);
1294 last->next = newChild;
1295 newChild->prev = last;
1302 if (refChild->next ==
nullptr) {
1304 last->next = newChild;
1305 newChild->prev = last;
1312 newChild->prev = refChild;
1313 newChild->next = refChild->next;
1314 refChild->next->prev = newChild;
1315 refChild->next = newChild;
1320QDomNodePrivate* QDomNodePrivate::replaceChild(QDomNodePrivate* newChild, QDomNodePrivate* oldChild)
1322 if (!newChild || !oldChild)
1324 if (oldChild->parent() !=
this)
1326 if (newChild == oldChild)
1330 QDomDocumentPrivate *
const doc = ownerDocument();
1332 doc->nodeListTime++;
1336 if (newChild->isDocumentFragment()) {
1338 if (newChild->first ==
nullptr)
1342 QDomNodePrivate* n = newChild->first;
1350 oldChild->next->prev = newChild->last;
1352 oldChild->prev->next = newChild->first;
1354 newChild->last->next = oldChild->next;
1355 newChild->first->prev = oldChild->prev;
1357 if (first == oldChild)
1358 first = newChild->first;
1359 if (last == oldChild)
1360 last = newChild->last;
1362 oldChild->setNoParent();
1363 oldChild->next =
nullptr;
1364 oldChild->prev =
nullptr;
1370 newChild->first =
nullptr;
1371 newChild->last =
nullptr;
1374 oldChild->ref.deref();
1381 newChild->ref.ref();
1384 if (newChild->parent())
1385 newChild->parent()->removeChild(newChild);
1387 newChild->setParent(
this);
1390 oldChild->next->prev = newChild;
1392 oldChild->prev->next = newChild;
1394 newChild->next = oldChild->next;
1395 newChild->prev = oldChild->prev;
1397 if (first == oldChild)
1399 if (last == oldChild)
1402 oldChild->setNoParent();
1403 oldChild->next =
nullptr;
1404 oldChild->prev =
nullptr;
1407 oldChild->ref.deref();
1412QDomNodePrivate* QDomNodePrivate::removeChild(QDomNodePrivate* oldChild)
1415 if (oldChild->parent() !=
this)
1419 QDomDocumentPrivate *
const doc = ownerDocument();
1421 doc->nodeListTime++;
1425 if (oldChild->next ==
nullptr && oldChild->prev ==
nullptr && first != oldChild)
1429 oldChild->next->prev = oldChild->prev;
1431 oldChild->prev->next = oldChild->next;
1433 if (last == oldChild)
1434 last = oldChild->prev;
1435 if (first == oldChild)
1436 first = oldChild->next;
1438 oldChild->setNoParent();
1439 oldChild->next =
nullptr;
1440 oldChild->prev =
nullptr;
1443 oldChild->ref.deref();
1448QDomNodePrivate* QDomNodePrivate::appendChild(QDomNodePrivate* newChild)
1451 return insertAfter(newChild,
nullptr);
1454QDomDocumentPrivate* QDomNodePrivate::ownerDocument()
1456 QDomNodePrivate* p =
this;
1457 while (p && !p->isDocument()) {
1459 return static_cast<QDomDocumentPrivate *>(p->ownerNode);
1463 return static_cast<QDomDocumentPrivate *>(p);
1466QDomNodePrivate* QDomNodePrivate::cloneNode(
bool deep)
1468 QDomNodePrivate* p =
new QDomNodePrivate(
this, deep);
1474static void qNormalizeNode(QDomNodePrivate* n)
1476 QDomNodePrivate* p = n->first;
1477 QDomTextPrivate* t =
nullptr;
1482 QDomNodePrivate* tmp = p->next;
1483 t->appendData(p->nodeValue());
1487 t =
static_cast<QDomTextPrivate *>(p);
1496void QDomNodePrivate::normalize()
1500 qNormalizeNode(
this);
1503void QDomNodePrivate::saveSubTree(
const QDomNodePrivate *n, QTextStream &s,
1504 int depth,
int indent)
const
1509 const QDomNodePrivate *root = n->first;
1510 n->save(s, depth, indent);
1512 const int branchDepth = depth + 1;
1515 root->save(s, layerDepth + branchDepth, indent);
1522 root->afterSave(s, layerDepth + branchDepth, indent);
1523 const QDomNodePrivate *prev = root;
1526 while (!root && (layerDepth > 0)) {
1527 root = prev->parent();
1529 root->afterSave(s, layerDepth + branchDepth, indent);
1534 Q_ASSERT(layerDepth == 0);
1536 n->afterSave(s, depth, indent);
1539void QDomNodePrivate::setLocation(
int lineNumber,
int columnNumber)
1541 this->lineNumber = lineNumber;
1542 this->columnNumber = columnNumber;
1546
1547
1548
1549
1551#define IMPL static_cast<QDomNodePrivate *>(impl)
1554
1555
1556
1557
1558
1559
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
1638
1639
1646
1647
1648
1649
1650
1651
1652QDomNode::QDomNode(
const QDomNode &node)
1660
1661
1662QDomNode::QDomNode(QDomNodePrivate *pimpl)
1670
1671
1672
1673
1674
1675
1676QDomNode& QDomNode::operator=(
const QDomNode &other)
1679 other.impl->ref.ref();
1680 if (impl && !impl->ref.deref())
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706bool QDomNode::operator==(
const QDomNode &other)
const
1708 return impl == other.impl;
1712
1713
1714
1715bool QDomNode::operator!=(
const QDomNode &other)
const
1717 return !operator==(other);
1721
1722
1723QDomNode::~QDomNode()
1725 if (impl && !impl->ref.deref())
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758QString QDomNode::nodeName()
const
1763 if (!IMPL->prefix.isEmpty())
1764 return IMPL->prefix + u':' + IMPL->name;
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786QString QDomNode::nodeValue()
const
1794
1795
1796
1797
1798void QDomNode::setNodeValue(
const QString& value)
1801 IMPL->setNodeValue(value);
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1825
1826
1827
1828
1829
1830
1831
1832QDomNode::NodeType QDomNode::nodeType()
const
1835 return QDomNode::BaseNode;
1836 return IMPL->nodeType();
1840
1841
1842
1843QDomNode QDomNode::parentNode()
const
1847 return QDomNode(IMPL->parent());
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868QDomNodeList QDomNode::childNodes()
const
1871 return QDomNodeList();
1872 return QDomNodeList(
new QDomNodeListPrivate(impl));
1876
1877
1878
1879
1880
1881
1882QDomNode QDomNode::firstChild()
const
1886 return QDomNode(IMPL->first);
1890
1891
1892
1893
1894
1895
1896QDomNode QDomNode::lastChild()
const
1900 return QDomNode(IMPL->last);
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916QDomNode QDomNode::previousSibling()
const
1920 return QDomNode(IMPL->prev);
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936QDomNode QDomNode::nextSibling()
const
1940 return QDomNode(IMPL->next);
1946
1947
1948
1949
1950
1951
1952QDomNamedNodeMap QDomNode::attributes()
const
1954 if (!impl || !impl->isElement())
1955 return QDomNamedNodeMap();
1957 return QDomNamedNodeMap(
static_cast<QDomElementPrivate *>(impl)->attributes());
1961
1962
1963QDomDocument QDomNode::ownerDocument()
const
1966 return QDomDocument();
1967 return QDomDocument(IMPL->ownerDocument());
1971
1972
1973
1974
1975
1976
1977
1978QDomNode QDomNode::cloneNode(
bool deep)
const
1982 return QDomNode(IMPL->cloneNode(deep));
1986
1987
1988
1989
1990
1991void QDomNode::normalize()
1999
2000
2001
2002
2003
2004
2005bool QDomNode::isSupported(
const QString& feature,
const QString& version)
const
2007 QDomImplementation i;
2008 return i.hasFeature(feature, version);
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023QString QDomNode::namespaceURI()
const
2027 return IMPL->namespaceURI;
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052QString QDomNode::prefix()
const
2056 return IMPL->prefix;
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073void QDomNode::setPrefix(
const QString& pre)
2075 if (!impl || IMPL->prefix.isNull())
2077 if (isAttr() || isElement())
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093QString QDomNode::localName()
const
2095 if (!impl || IMPL->createdWithDom1Interface)
2101
2102
2103
2104
2105bool QDomNode::hasAttributes()
const
2107 if (!impl || !impl->isElement())
2109 return static_cast<QDomElementPrivate *>(impl)->hasAttributes();
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133QDomNode QDomNode::insertBefore(
const QDomNode& newChild,
const QDomNode& refChild)
2137 return QDomNode(IMPL->insertBefore(newChild.impl, refChild.impl));
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161QDomNode QDomNode::insertAfter(
const QDomNode& newChild,
const QDomNode& refChild)
2165 return QDomNode(IMPL->insertAfter(newChild.impl, refChild.impl));
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183QDomNode QDomNode::replaceChild(
const QDomNode& newChild,
const QDomNode& oldChild)
2185 if (!impl || !newChild.impl || !oldChild.impl)
2187 return QDomNode(IMPL->replaceChild(newChild.impl, oldChild.impl));
2191
2192
2193
2194
2195
2196
2197
2198QDomNode QDomNode::removeChild(
const QDomNode& oldChild)
2203 if (oldChild.isNull())
2206 return QDomNode(IMPL->removeChild(oldChild.impl));
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233QDomNode QDomNode::appendChild(
const QDomNode& newChild)
2236 qWarning(
"Calling appendChild() on a null node does nothing.");
2239 return QDomNode(IMPL->appendChild(newChild.impl));
2243
2244
2245
2246bool QDomNode::hasChildNodes()
const
2250 return IMPL->first !=
nullptr;
2254
2255
2256
2257bool QDomNode::isNull()
const
2259 return (impl ==
nullptr);
2263
2264
2265
2266
2267
2268void QDomNode::clear()
2270 if (impl && !impl->ref.deref())
2276
2277
2278
2279
2280
2281
2282
2283
2284QDomNode QDomNode::namedItem(
const QString& name)
const
2288 return QDomNode(impl->namedItem(name));
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316void QDomNode::save(QTextStream& stream,
int indent, EncodingPolicy encodingPolicy)
const
2322 static_cast<
const QDomDocumentPrivate *>(impl)->saveDocument(stream, indent, encodingPolicy);
2324 IMPL->saveSubTree(IMPL, stream, 1, indent);
2328
2329
2330
2331
2332
2333QTextStream& operator<<(QTextStream& str,
const QDomNode& node)
2341
2342
2343
2344
2345
2346
2347
2348
2349bool QDomNode::isAttr()
const
2352 return impl->isAttr();
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366bool QDomNode::isCDATASection()
const
2369 return impl->isCDATASection();
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383bool QDomNode::isDocumentFragment()
const
2386 return impl->isDocumentFragment();
2391
2392
2393
2394
2395
2396
2397
2398bool QDomNode::isDocument()
const
2401 return impl->isDocument();
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415bool QDomNode::isDocumentType()
const
2418 return impl->isDocumentType();
2423
2424
2425
2426
2427
2428
2429
2430bool QDomNode::isElement()
const
2433 return impl->isElement();
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447bool QDomNode::isEntityReference()
const
2450 return impl->isEntityReference();
2455
2456
2457
2458
2459
2460
2461
2462bool QDomNode::isText()
const
2465 return impl->isText();
2470
2471
2472
2473
2474
2475
2476
2477bool QDomNode::isEntity()
const
2480 return impl->isEntity();
2485
2486
2487
2488
2489
2490
2491
2492bool QDomNode::isNotation()
const
2495 return impl->isNotation();
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509bool QDomNode::isProcessingInstruction()
const
2512 return impl->isProcessingInstruction();
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526bool QDomNode::isCharacterData()
const
2529 return impl->isCharacterData();
2534
2535
2536
2537
2538
2539
2540
2541bool QDomNode::isComment()
const
2544 return impl->isComment();
2551
2552
2553
2554
2555
2556
2557
2558
2560QDomElement QDomNode::firstChildElement(
const QString &tagName,
const QString &namespaceURI)
const
2562 for (QDomNode child = firstChild(); !child.isNull(); child = child.nextSibling()) {
2563 if (child.isElement() && (namespaceURI.isEmpty() || child.namespaceURI() == namespaceURI)) {
2564 QDomElement elt = child.toElement();
2565 if (tagName.isEmpty() || elt.tagName() == tagName)
2569 return QDomElement();
2573
2574
2575
2576
2577
2578
2579
2580
2582QDomElement QDomNode::lastChildElement(
const QString &tagName,
const QString &namespaceURI)
const
2584 for (QDomNode child = lastChild(); !child.isNull(); child = child.previousSibling()) {
2585 if (child.isElement() && (namespaceURI.isEmpty() || child.namespaceURI() == namespaceURI)) {
2586 QDomElement elt = child.toElement();
2587 if (tagName.isEmpty() || elt.tagName() == tagName)
2591 return QDomElement();
2595
2596
2597
2598
2599
2600
2601
2602
2603
2605QDomElement QDomNode::nextSiblingElement(
const QString &tagName,
const QString &namespaceURI)
const
2607 for (QDomNode sib = nextSibling(); !sib.isNull(); sib = sib.nextSibling()) {
2608 if (sib.isElement() && (namespaceURI.isEmpty() || sib.namespaceURI() == namespaceURI)) {
2609 QDomElement elt = sib.toElement();
2610 if (tagName.isEmpty() || elt.tagName() == tagName)
2614 return QDomElement();
2618
2619
2620
2621
2622
2623
2624
2625
2626
2628QDomElement QDomNode::previousSiblingElement(
const QString &tagName,
const QString &namespaceURI)
const
2630 for (QDomNode sib = previousSibling(); !sib.isNull(); sib = sib.previousSibling()) {
2631 if (sib.isElement() && (namespaceURI.isEmpty() || sib.namespaceURI() == namespaceURI)) {
2632 QDomElement elt = sib.toElement();
2633 if (tagName.isEmpty() || elt.tagName() == tagName)
2637 return QDomElement();
2641
2642
2643
2644
2645
2646
2647
2648
2649int QDomNode::lineNumber()
const
2651 return impl ? impl->lineNumber : -1;
2655
2656
2657
2658
2659
2660
2661
2662
2663int QDomNode::columnNumber()
const
2665 return impl ? impl->columnNumber : -1;
2670
2671
2672
2673
2675QDomNamedNodeMapPrivate::QDomNamedNodeMapPrivate(QDomNodePrivate *pimpl)
2679 , appendToParent(
false)
2683QDomNamedNodeMapPrivate::~QDomNamedNodeMapPrivate()
2688QDomNamedNodeMapPrivate* QDomNamedNodeMapPrivate::clone(QDomNodePrivate *pimpl)
2690 std::unique_ptr<QDomNamedNodeMapPrivate> m(
new QDomNamedNodeMapPrivate(pimpl));
2691 m->readonly = readonly;
2692 m->appendToParent = appendToParent;
2694 auto it = map.constBegin();
2695 for (; it != map.constEnd(); ++it) {
2696 QDomNodePrivate *new_node = it.value()->cloneNode();
2697 new_node->setParent(pimpl);
2698 m->setNamedItem(new_node);
2706void QDomNamedNodeMapPrivate::clearMap()
2709 if (!appendToParent) {
2710 auto it = map.constBegin();
2711 for (; it != map.constEnd(); ++it)
2712 if (!it.value()->ref.deref())
2718QDomNodePrivate* QDomNamedNodeMapPrivate::namedItem(
const QString& name)
const
2720 auto it = map.find(name);
2721 return it == map.end() ?
nullptr : it.value();
2724QDomNodePrivate* QDomNamedNodeMapPrivate::namedItemNS(
const QString& nsURI,
const QString& localName)
const
2726 auto it = map.constBegin();
2728 for (; it != map.constEnd(); ++it) {
2730 if (!n->prefix.isNull()) {
2732 if (n->namespaceURI == nsURI && n->name == localName)
2739QDomNodePrivate* QDomNamedNodeMapPrivate::setNamedItem(QDomNodePrivate* arg)
2741 if (readonly || !arg)
2745 return parent->appendChild(arg);
2747 QDomNodePrivate *n = map.value(arg->nodeName());
2750 map.insert(arg->nodeName(), arg);
2754QDomNodePrivate* QDomNamedNodeMapPrivate::setNamedItemNS(QDomNodePrivate* arg)
2756 if (readonly || !arg)
2760 return parent->appendChild(arg);
2762 if (!arg->prefix.isNull()) {
2764 QDomNodePrivate *n = namedItemNS(arg->namespaceURI, arg->name);
2767 map.insert(arg->nodeName(), arg);
2771 return setNamedItem(arg);
2775QDomNodePrivate* QDomNamedNodeMapPrivate::removeNamedItem(
const QString& name)
2780 QDomNodePrivate* p = namedItem(name);
2784 return parent->removeChild(p);
2786 map.remove(p->nodeName());
2792QDomNodePrivate* QDomNamedNodeMapPrivate::item(
int index)
const
2794 if (index >= length() || index < 0)
2796 return std::next(map.begin(), index).value();
2799int QDomNamedNodeMapPrivate::length()
const
2804bool QDomNamedNodeMapPrivate::contains(
const QString& name)
const
2806 return map.contains(name);
2809bool QDomNamedNodeMapPrivate::containsNS(
const QString& nsURI,
const QString & localName)
const
2811 return namedItemNS(nsURI, localName) !=
nullptr;
2815
2816
2817
2818
2820#define IMPL static_cast<QDomNamedNodeMapPrivate *>(impl)
2823
2824
2825
2826
2827
2828
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
2861
2862
2863QDomNamedNodeMap::QDomNamedNodeMap()
2869
2870
2871QDomNamedNodeMap::QDomNamedNodeMap(
const QDomNamedNodeMap &namedNodeMap)
2872 : impl(namedNodeMap.impl)
2878QDomNamedNodeMap::QDomNamedNodeMap(QDomNamedNodeMapPrivate *pimpl)
2886
2887
2888QDomNamedNodeMap& QDomNamedNodeMap::operator=(
const QDomNamedNodeMap &other)
2891 other.impl->ref.ref();
2892 if (impl && !impl->ref.deref())
2899
2900
2901
2902bool QDomNamedNodeMap::operator==(
const QDomNamedNodeMap &other)
const
2904 return impl == other.impl;
2908
2909
2910
2911bool QDomNamedNodeMap::operator!=(
const QDomNamedNodeMap &other)
const
2913 return !operator==(other);
2917
2918
2919QDomNamedNodeMap::~QDomNamedNodeMap()
2921 if (impl && !impl->ref.deref())
2926
2927
2928
2929
2930
2931
2932
2933
2934QDomNode QDomNamedNodeMap::namedItem(
const QString& name)
const
2938 return QDomNode(IMPL->namedItem(name));
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951QDomNode QDomNamedNodeMap::setNamedItem(
const QDomNode& newNode)
2955 return QDomNode(IMPL->setNamedItem(
static_cast<QDomNodePrivate *>(newNode.impl)));
2959
2960
2961
2962
2963
2964
2965
2966
2967QDomNode QDomNamedNodeMap::removeNamedItem(
const QString& name)
2971 return QDomNode(IMPL->removeNamedItem(name));
2975
2976
2977
2978
2979
2980
2981
2982QDomNode QDomNamedNodeMap::item(
int index)
const
2986 return QDomNode(IMPL->item(index));
2990
2991
2992
2993
2994
2995
2996
2997
2998QDomNode QDomNamedNodeMap::namedItemNS(
const QString& nsURI,
const QString& localName)
const
3002 return QDomNode(IMPL->namedItemNS(nsURI, localName));
3006
3007
3008
3009
3010
3011
3012
3013QDomNode QDomNamedNodeMap::setNamedItemNS(
const QDomNode& newNode)
3017 return QDomNode(IMPL->setNamedItemNS(
static_cast<QDomNodePrivate *>(newNode.impl)));
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031QDomNode QDomNamedNodeMap::removeNamedItemNS(
const QString& nsURI,
const QString& localName)
3035 QDomNodePrivate *n = IMPL->namedItemNS(nsURI, localName);
3038 return QDomNode(IMPL->removeNamedItem(n->name));
3042
3043
3044
3045
3046int QDomNamedNodeMap::length()
const
3050 return IMPL->length();
3054
3055
3056
3057
3058
3061
3062
3063
3064
3067
3068
3069
3070
3073
3074
3075
3076
3077
3078
3079
3080bool QDomNamedNodeMap::contains(
const QString& name)
const
3084 return IMPL->contains(name);
3090
3091
3092
3093
3095QDomDocumentTypePrivate::QDomDocumentTypePrivate(QDomDocumentPrivate* doc, QDomNodePrivate* parent)
3096 : QDomNodePrivate(doc, parent)
3101QDomDocumentTypePrivate::QDomDocumentTypePrivate(QDomDocumentTypePrivate* n,
bool deep)
3102 : QDomNodePrivate(n, deep)
3106 QDomNodePrivate* p = first;
3110 entities->map.insert(p->nodeName(), p);
3111 if (p->isNotation())
3113 notations->map.insert(p->nodeName(), p);
3118QDomDocumentTypePrivate::~QDomDocumentTypePrivate()
3120 if (!entities->ref.deref())
3122 if (!notations->ref.deref())
3126void QDomDocumentTypePrivate::init()
3128 entities =
new QDomNamedNodeMapPrivate(
this);
3130 notations =
new QDomNamedNodeMapPrivate(
this);
3133 internalSubset.clear();
3135 entities->setAppendToParent(
true);
3136 notations->setAppendToParent(
true);
3143QDomNodePrivate* QDomDocumentTypePrivate::cloneNode(
bool deep)
3145 QDomNodePrivate* p =
new QDomDocumentTypePrivate(
this, deep);
3151QDomNodePrivate* QDomDocumentTypePrivate::insertBefore(QDomNodePrivate* newChild, QDomNodePrivate* refChild)
3154 QDomNodePrivate* p = QDomNodePrivate::insertBefore(newChild, refChild);
3156 if (p && p->isEntity())
3157 entities->map.insert(p->nodeName(), p);
3158 else if (p && p->isNotation())
3159 notations->map.insert(p->nodeName(), p);
3164QDomNodePrivate* QDomDocumentTypePrivate::insertAfter(QDomNodePrivate* newChild, QDomNodePrivate* refChild)
3167 QDomNodePrivate* p = QDomNodePrivate::insertAfter(newChild, refChild);
3169 if (p && p->isEntity())
3170 entities->map.insert(p->nodeName(), p);
3171 else if (p && p->isNotation())
3172 notations->map.insert(p->nodeName(), p);
3177QDomNodePrivate* QDomDocumentTypePrivate::replaceChild(QDomNodePrivate* newChild, QDomNodePrivate* oldChild)
3180 QDomNodePrivate* p = QDomNodePrivate::replaceChild(newChild, oldChild);
3183 if (oldChild && oldChild->isEntity())
3184 entities->map.remove(oldChild->nodeName());
3185 else if (oldChild && oldChild->isNotation())
3186 notations->map.remove(oldChild->nodeName());
3189 entities->map.insert(p->nodeName(), p);
3190 else if (p->isNotation())
3191 notations->map.insert(p->nodeName(), p);
3197QDomNodePrivate* QDomDocumentTypePrivate::removeChild(QDomNodePrivate* oldChild)
3200 QDomNodePrivate* p = QDomNodePrivate::removeChild( oldChild);
3202 if (p && p->isEntity())
3203 entities->map.remove(p->nodeName());
3204 else if (p && p->isNotation())
3205 notations->map.remove(p ->nodeName());
3210QDomNodePrivate* QDomDocumentTypePrivate::appendChild(QDomNodePrivate* newChild)
3212 return insertAfter(newChild,
nullptr);
3215static QString quotedValue(
const QString &data)
3217 QChar quote = data.indexOf(u'\'') == -1 ? u'\'' : u'"';
3218 return quote + data + quote;
3221void QDomDocumentTypePrivate::save(QTextStream& s,
int,
int indent)
const
3226 s <<
"<!DOCTYPE " << name;
3228 if (!publicId.isNull()) {
3229 s <<
" PUBLIC " << quotedValue(publicId);
3230 if (!systemId.isNull()) {
3231 s <<
' ' << quotedValue(systemId);
3233 }
else if (!systemId.isNull()) {
3234 s <<
" SYSTEM " << quotedValue(systemId);
3237 if (entities->length()>0 || notations->length()>0) {
3238 s <<
" [" << Qt::endl;
3240 auto it2 = notations->map.constBegin();
3241 for (; it2 != notations->map.constEnd(); ++it2)
3242 it2.value()->saveSubTree(it2.value(), s, 0, indent);
3244 auto it = entities->map.constBegin();
3245 for (; it != entities->map.constEnd(); ++it)
3246 it.value()->saveSubTree(it.value(), s, 0, indent);
3251 s <<
'>' << Qt::endl;
3255
3256
3257
3258
3260#define IMPL static_cast<QDomDocumentTypePrivate *>(impl)
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3282
3283
3284QDomDocumentType::QDomDocumentType() : QDomNode()
3289
3290
3291
3292
3293
3294
3295QDomDocumentType::QDomDocumentType(
const QDomDocumentType &documentType)
3296 : QDomNode(documentType)
3300QDomDocumentType::QDomDocumentType(QDomDocumentTypePrivate *pimpl)
3306
3307
3308
3309
3310
3311
3312QDomDocumentType &QDomDocumentType::operator=(
const QDomDocumentType &other) =
default;
3314
3315
3316
3317
3318
3319QString QDomDocumentType::name()
const
3323 return IMPL->nodeName();
3327
3328
3329QDomNamedNodeMap QDomDocumentType::entities()
const
3332 return QDomNamedNodeMap();
3333 return QDomNamedNodeMap(IMPL->entities);
3337
3338
3339QDomNamedNodeMap QDomDocumentType::notations()
const
3342 return QDomNamedNodeMap();
3343 return QDomNamedNodeMap(IMPL->notations);
3347
3348
3349
3350
3351
3352QString QDomDocumentType::publicId()
const
3356 return IMPL->publicId;
3360
3361
3362
3363
3364
3365QString QDomDocumentType::systemId()
const
3369 return IMPL->systemId;
3373
3374
3375
3376
3377
3378QString QDomDocumentType::internalSubset()
const
3382 return IMPL->internalSubset;
3386
3387
3388
3389
3392
3393
3394
3395
3396
3397
3402
3403
3404
3405
3407QDomDocumentFragmentPrivate::QDomDocumentFragmentPrivate(QDomDocumentPrivate* doc, QDomNodePrivate* parent)
3408 : QDomNodePrivate(doc, parent)
3410 name = u"#document-fragment"_s;
3413QDomDocumentFragmentPrivate::QDomDocumentFragmentPrivate(QDomNodePrivate* n,
bool deep)
3414 : QDomNodePrivate(n, deep)
3418QDomNodePrivate* QDomDocumentFragmentPrivate::cloneNode(
bool deep)
3420 QDomNodePrivate* p =
new QDomDocumentFragmentPrivate(
this, deep);
3427
3428
3429
3430
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3458
3459
3460QDomDocumentFragment::QDomDocumentFragment()
3464QDomDocumentFragment::QDomDocumentFragment(QDomDocumentFragmentPrivate* n)
3470
3471
3472
3473
3474
3475
3476QDomDocumentFragment::QDomDocumentFragment(
const QDomDocumentFragment &documentFragment)
3477 : QDomNode(documentFragment)
3482
3483
3484
3485
3486
3487
3488QDomDocumentFragment &QDomDocumentFragment::operator=(
const QDomDocumentFragment &other) =
default;
3491
3492
3493
3494
3495
3496
3499
3500
3501
3502
3504QDomCharacterDataPrivate::QDomCharacterDataPrivate(QDomDocumentPrivate* d, QDomNodePrivate* p,
3505 const QString& data)
3506 : QDomNodePrivate(d, p)
3509 name = u"#character-data"_s;
3512QDomCharacterDataPrivate::QDomCharacterDataPrivate(QDomCharacterDataPrivate* n,
bool deep)
3513 : QDomNodePrivate(n, deep)
3517QDomNodePrivate* QDomCharacterDataPrivate::cloneNode(
bool deep)
3519 QDomNodePrivate* p =
new QDomCharacterDataPrivate(
this, deep);
3525int QDomCharacterDataPrivate::dataLength()
const
3527 return value.size();
3530QString QDomCharacterDataPrivate::substringData(
unsigned long offset,
unsigned long n)
const
3532 return value.mid(offset, n);
3535void QDomCharacterDataPrivate::insertData(
unsigned long offset,
const QString& arg)
3537 value.insert(offset, arg);
3540void QDomCharacterDataPrivate::deleteData(
unsigned long offset,
unsigned long n)
3542 value.remove(offset, n);
3545void QDomCharacterDataPrivate::replaceData(
unsigned long offset,
unsigned long n,
const QString& arg)
3547 value.replace(offset, n, arg);
3550void QDomCharacterDataPrivate::appendData(
const QString& arg)
3556
3557
3558
3559
3561#define IMPL static_cast<QDomCharacterDataPrivate *>(impl)
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3589
3590
3591QDomCharacterData::QDomCharacterData()
3596
3597
3598
3599
3600
3601
3602QDomCharacterData::QDomCharacterData(
const QDomCharacterData &characterData)
3603 : QDomNode(characterData)
3607QDomCharacterData::QDomCharacterData(QDomCharacterDataPrivate* n)
3613
3614
3615
3616
3617
3618
3619QDomCharacterData &QDomCharacterData::operator=(
const QDomCharacterData &other) =
default;
3622
3623
3624
3625
3626
3627QString QDomCharacterData::data()
const
3631 return impl->nodeValue();
3635
3636
3637void QDomCharacterData::setData(
const QString &data)
3640 impl->setNodeValue(data);
3644
3645
3646int QDomCharacterData::length()
const
3649 return IMPL->dataLength();
3654
3655
3656QString QDomCharacterData::substringData(
unsigned long offset,
unsigned long count)
3660 return IMPL->substringData(offset, count);
3664
3665
3666void QDomCharacterData::appendData(
const QString& arg)
3669 IMPL->appendData(arg);
3673
3674
3675void QDomCharacterData::insertData(
unsigned long offset,
const QString& arg)
3678 IMPL->insertData(offset, arg);
3682
3683
3684void QDomCharacterData::deleteData(
unsigned long offset,
unsigned long count)
3687 IMPL->deleteData(offset, count);
3691
3692
3693
3694void QDomCharacterData::replaceData(
unsigned long offset,
unsigned long count,
const QString& arg)
3697 IMPL->replaceData(offset, count, arg);
3701
3702
3703
3704
3705QDomNode::NodeType QDomCharacterData::nodeType()
const
3708 return CharacterDataNode;
3709 return QDomNode::nodeType();
3715
3716
3717
3718
3720QDomAttrPrivate::QDomAttrPrivate(QDomDocumentPrivate* d, QDomNodePrivate* parent,
const QString& name_)
3721 : QDomNodePrivate(d, parent)
3724 m_specified =
false;
3727QDomAttrPrivate::QDomAttrPrivate(QDomDocumentPrivate* d, QDomNodePrivate* p,
const QString& nsURI,
const QString& qName)
3728 : QDomNodePrivate(d, p)
3730 qt_split_namespace(prefix, name, qName, !nsURI.isNull());
3731 namespaceURI = nsURI;
3732 createdWithDom1Interface =
false;
3733 m_specified =
false;
3736QDomAttrPrivate::QDomAttrPrivate(QDomAttrPrivate* n,
bool deep)
3737 : QDomNodePrivate(n, deep)
3739 m_specified = n->specified();
3742void QDomAttrPrivate::setNodeValue(
const QString& v)
3745 QDomTextPrivate *t =
new QDomTextPrivate(
nullptr,
this, v);
3749 auto removed = removeChild(first);
3750 if (removed && !removed->ref.loadRelaxed())
3756QDomNodePrivate* QDomAttrPrivate::cloneNode(
bool deep)
3758 QDomNodePrivate* p =
new QDomAttrPrivate(
this, deep);
3764bool QDomAttrPrivate::specified()
const
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779static QString encodeText(
const QString &str,
3780 const bool encodeQuotes =
true,
3781 const bool performAVN =
false,
3782 const bool encodeEOLs =
false)
3785 qsizetype start = 0;
3786 auto appendToOutput = [&](qsizetype cur,
const auto &replacement)
3789 retval.reserve(str.size() + replacement.size());
3790 retval.append(QStringView(str).first(cur).sliced(start));
3794 retval.append(replacement);
3797 const qsizetype len = str.size();
3798 for (qsizetype cur = 0; cur < len; ++cur) {
3799 switch (str[cur].unicode()) {
3801 appendToOutput(cur,
"<"_L1);
3805 appendToOutput(cur,
"""_L1);
3808 appendToOutput(cur,
"&"_L1);
3811 if (cur >= 2 && str[cur - 1] == u']' && str[cur - 2] == u']')
3812 appendToOutput(cur,
">"_L1);
3815 if (performAVN || encodeEOLs)
3816 appendToOutput(cur,
"
"_L1);
3820 appendToOutput(cur,
"
"_L1);
3824 appendToOutput(cur,
"	"_L1);
3831 retval.append(QStringView(str).first(len).sliced(start));
3837void QDomAttrPrivate::save(QTextStream& s,
int,
int)
const
3839 if (namespaceURI.isNull()) {
3840 s << name <<
"=\"" << encodeText(value,
true,
true) <<
'\"';
3842 s << prefix <<
':' << name <<
"=\"" << encodeText(value,
true,
true) <<
'\"';
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3855 ownerNode->prefix != prefix) {
3856 s <<
" xmlns:" << prefix <<
"=\"" << encodeText(namespaceURI,
true,
true) <<
'\"';
3862
3863
3864
3865
3867#define IMPL static_cast<QDomAttrPrivate *>(impl)
3870
3871
3872
3873
3874
3875
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
3905
3906
3912
3913
3914
3915
3916
3917
3918QDomAttr::QDomAttr(
const QDomAttr &attr)
3923QDomAttr::QDomAttr(QDomAttrPrivate* n)
3929
3930
3931
3932
3933
3934
3935QDomAttr &QDomAttr::operator=(
const QDomAttr &other) =
default;
3938
3939
3940QString QDomAttr::name()
const
3944 return impl->nodeName();
3948
3949
3950
3951
3952
3953bool QDomAttr::specified()
const
3957 return IMPL->specified();
3961
3962
3963
3964
3965QDomElement QDomAttr::ownerElement()
const
3967 Q_ASSERT(impl->parent());
3968 if (!impl->parent()->isElement())
3969 return QDomElement();
3970 return QDomElement(
static_cast<QDomElementPrivate *>(impl->parent()));
3974
3975
3976
3977
3978
3979QString QDomAttr::value()
const
3983 return impl->nodeValue();
3987
3988
3989
3990
3991void QDomAttr::setValue(
const QString &value)
3995 impl->setNodeValue(value);
3996 IMPL->m_specified =
true;
4000
4001
4002
4003
4008
4009
4010
4011
4013QDomElementPrivate::QDomElementPrivate(QDomDocumentPrivate* d, QDomNodePrivate* p,
4014 const QString& tagname)
4015 : QDomNodePrivate(d, p)
4018 m_attr =
new QDomNamedNodeMapPrivate(
this);
4021QDomElementPrivate::QDomElementPrivate(QDomDocumentPrivate* d, QDomNodePrivate* p,
4022 const QString& nsURI,
const QString& qName)
4023 : QDomNodePrivate(d, p)
4025 qt_split_namespace(prefix, name, qName, !nsURI.isNull());
4026 namespaceURI = nsURI;
4027 createdWithDom1Interface =
false;
4028 m_attr =
new QDomNamedNodeMapPrivate(
this);
4031QDomElementPrivate::QDomElementPrivate(QDomElementPrivate* n,
bool deep) :
4032 QDomNodePrivate(n, deep)
4034 m_attr = n->m_attr->clone(
this);
4039QDomElementPrivate::~QDomElementPrivate()
4041 if (!m_attr->ref.deref())
4045QDomNodePrivate* QDomElementPrivate::cloneNode(
bool deep)
4047 QDomNodePrivate* p =
new QDomElementPrivate(
this, deep);
4053QString QDomElementPrivate::attribute(
const QString& name_,
const QString& defValue)
const
4055 QDomNodePrivate* n = m_attr->namedItem(name_);
4059 return n->nodeValue();
4062QString QDomElementPrivate::attributeNS(
const QString& nsURI,
const QString& localName,
const QString& defValue)
const
4064 QDomNodePrivate* n = m_attr->namedItemNS(nsURI, localName);
4068 return n->nodeValue();
4071void QDomElementPrivate::setAttribute(
const QString& aname,
const QString& newValue)
4073 QDomNodePrivate* n = m_attr->namedItem(aname);
4075 n =
new QDomAttrPrivate(ownerDocument(),
this, aname);
4076 n->setNodeValue(newValue);
4081 m_attr->setNamedItem(n);
4083 n->setNodeValue(newValue);
4087void QDomElementPrivate::setAttributeNS(
const QString& nsURI,
const QString& qName,
const QString& newValue)
4089 QString prefix, localName;
4090 qt_split_namespace(prefix, localName, qName,
true);
4091 QDomNodePrivate* n = m_attr->namedItemNS(nsURI, localName);
4093 n =
new QDomAttrPrivate(ownerDocument(),
this, nsURI, qName);
4094 n->setNodeValue(newValue);
4099 m_attr->setNamedItem(n);
4101 n->setNodeValue(newValue);
4102 n->prefix = std::move(prefix);
4106void QDomElementPrivate::removeAttribute(
const QString& aname)
4108 QDomNodePrivate* p = m_attr->removeNamedItem(aname);
4109 if (p && p->ref.loadRelaxed() == 0)
4113QDomAttrPrivate* QDomElementPrivate::attributeNode(
const QString& aname)
4115 return static_cast<QDomAttrPrivate *>(m_attr->namedItem(aname));
4118QDomAttrPrivate* QDomElementPrivate::attributeNodeNS(
const QString& nsURI,
const QString& localName)
4120 return static_cast<QDomAttrPrivate *>(m_attr->namedItemNS(nsURI, localName));
4123QDomAttrPrivate* QDomElementPrivate::setAttributeNode(QDomAttrPrivate* newAttr)
4128 QDomNodePrivate* foundAttr = m_attr->namedItem(newAttr->nodeName());
4130 m_attr->removeNamedItem(newAttr->nodeName());
4133 m_attr->setNamedItem(newAttr);
4134 newAttr->setParent(
this);
4136 return static_cast<QDomAttrPrivate *>(foundAttr);
4139QDomAttrPrivate* QDomElementPrivate::setAttributeNodeNS(QDomAttrPrivate* newAttr)
4141 QDomNodePrivate* n =
nullptr;
4142 if (!newAttr->prefix.isNull())
4143 n = m_attr->namedItemNS(newAttr->namespaceURI, newAttr->name);
4146 m_attr->setNamedItem(newAttr);
4148 return static_cast<QDomAttrPrivate *>(n);
4151QDomAttrPrivate* QDomElementPrivate::removeAttributeNode(QDomAttrPrivate* oldAttr)
4153 return static_cast<QDomAttrPrivate *>(m_attr->removeNamedItem(oldAttr->nodeName()));
4156bool QDomElementPrivate::hasAttribute(
const QString& aname)
4158 return m_attr->contains(aname);
4161bool QDomElementPrivate::hasAttributeNS(
const QString& nsURI,
const QString& localName)
4163 return m_attr->containsNS(nsURI, localName);
4166QString QDomElementPrivate::text()
4170 QDomNodePrivate* p = first;
4172 if (p->isText() || p->isCDATASection())
4173 t += p->nodeValue();
4174 else if (p->isElement())
4175 t +=
static_cast<QDomElementPrivate *>(p)->text();
4182void QDomElementPrivate::save(QTextStream& s,
int depth,
int indent)
const
4184 if (!(prev && prev->isText()))
4185 s << QString(indent < 1 ? 0 : depth * indent, u' ');
4187 QString qName(name);
4188 QString nsDecl(u""_s);
4189 if (!namespaceURI.isNull()) {
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200 if (prefix.isEmpty()) {
4201 nsDecl = u" xmlns"_s;
4203 qName = prefix + u':' + name;
4204 nsDecl = u" xmlns:"_s + prefix;
4206 nsDecl += u"=\""_s + encodeText(namespaceURI) + u'\"';
4208 s <<
'<' << qName << nsDecl;
4212 if (!m_attr->map.isEmpty()) {
4214
4215
4216
4217
4218
4219
4220
4221 struct SavedAttribute {
4224 QString encodedValue;
4228 QVarLengthArray<SavedAttribute, 8> attributesToSave;
4229 attributesToSave.reserve(m_attr->map.size());
4231 QDuplicateTracker<QString> outputtedPrefixes;
4232 for (
const auto &[key, value] : std::as_const(m_attr->map).asKeyValueRange()) {
4234 bool mayNeedXmlNS =
false;
4236 SavedAttribute attr;
4237 attr.name = value->name;
4238 attr.encodedValue = encodeText(value->value,
true,
true);
4239 if (!value->namespaceURI.isNull()) {
4240 attr.prefix = value->prefix;
4241 mayNeedXmlNS =
true;
4244 attributesToSave.push_back(std::move(attr));
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4263 && ((!value->ownerNode || value->ownerNode->prefix != value->prefix)
4264 && !outputtedPrefixes.hasSeen(value->prefix)))
4266 SavedAttribute nsAttr;
4267 nsAttr.prefix = QStringLiteral(
"xmlns");
4268 nsAttr.name = value->prefix;
4269 nsAttr.encodedValue = encodeText(value->namespaceURI,
true,
true);
4270 attributesToSave.push_back(std::move(nsAttr));
4275 const auto savedAttributeComparator = [](
const SavedAttribute &lhs,
const SavedAttribute &rhs)
4277 const int cmp = QString::compare(lhs.prefix, rhs.prefix);
4278 return (cmp < 0) || ((cmp == 0) && (lhs.name < rhs.name));
4281 std::sort(attributesToSave.begin(), attributesToSave.end(), savedAttributeComparator);
4284 for (
const auto &attr : attributesToSave) {
4286 if (!attr.prefix.isEmpty())
4287 s << attr.prefix <<
':';
4288 s << attr.name <<
"=\"" << attr.encodedValue <<
'\"';
4294 if (first->isText())
4308void QDomElementPrivate::afterSave(QTextStream &s,
int depth,
int indent)
const
4311 QString qName(name);
4313 if (!prefix.isEmpty())
4314 qName = prefix + u':' + name;
4316 if (!last->isText())
4317 s << QString(indent < 1 ? 0 : depth * indent, u' ');
4319 s <<
"</" << qName <<
'>';
4322 if (!(next && next->isText())) {
4330
4331
4332
4333
4335#define IMPL static_cast<QDomElementPrivate *>(impl)
4338
4339
4340
4341
4342
4343
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
4390
4391
4392
4393QDomElement::QDomElement()
4399
4400
4401
4402
4403
4404
4405QDomElement::QDomElement(
const QDomElement &element)
4410QDomElement::QDomElement(QDomElementPrivate* n)
4416
4417
4418
4419
4420
4421
4422QDomElement &QDomElement::operator=(
const QDomElement &other) =
default;
4425
4426
4427
4428
4431
4432
4433
4434
4435void QDomElement::setTagName(
const QString& name)
4442
4443
4444
4445
4446
4447
4448
4449
4450QString QDomElement::tagName()
const
4454 return impl->nodeName();
4459
4460
4461
4462
4463QDomNamedNodeMap QDomElement::attributes()
const
4466 return QDomNamedNodeMap();
4467 return QDomNamedNodeMap(IMPL->attributes());
4471
4472
4473
4474
4475
4476QString QDomElement::attribute(
const QString& name,
const QString& defValue)
const
4480 return IMPL->attribute(name, defValue);
4484
4485
4486
4487
4488
4489
4490void QDomElement::setAttribute(
const QString& name,
const QString& value)
4494 IMPL->setAttribute(name, value);
4498
4499
4500
4501
4502
4505
4506
4507
4508
4509
4512
4513
4514
4515
4516void QDomElement::setAttribute(
const QString& name, qlonglong value)
4522 IMPL->setAttribute(name, x);
4526
4527
4528
4529
4530void QDomElement::setAttribute(
const QString& name, qulonglong value)
4536 IMPL->setAttribute(name, x);
4540
4541
4542
4543
4544void QDomElement::setAttribute(
const QString& name,
float value)
4549 x.setNum(value,
'g', 8);
4550 IMPL->setAttribute(name, x);
4554
4555
4556
4557
4558void QDomElement::setAttribute(
const QString& name,
double value)
4563 x.setNum(value,
'g', 17);
4564 IMPL->setAttribute(name, x);
4568
4569
4570
4571
4572void QDomElement::removeAttribute(
const QString& name)
4576 IMPL->removeAttribute(name);
4580
4581
4582
4583
4584
4585
4586QDomAttr QDomElement::attributeNode(
const QString& name)
4590 return QDomAttr(IMPL->attributeNode(name));
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603QDomAttr QDomElement::setAttributeNode(
const QDomAttr& newAttr)
4607 return QDomAttr(IMPL->setAttributeNode(
static_cast<QDomAttrPrivate *>(newAttr.impl)));
4611
4612
4613
4614
4615QDomAttr QDomElement::removeAttributeNode(
const QDomAttr& oldAttr)
4619 return QDomAttr(IMPL->removeAttributeNode(
static_cast<QDomAttrPrivate *>(oldAttr.impl)));
4623
4624
4625
4626
4627
4628
4629
4630
4631QDomNodeList QDomElement::elementsByTagName(
const QString& tagname)
const
4633 return QDomNodeList(
new QDomNodeListPrivate(impl, tagname));
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648bool QDomElement::hasAttribute(
const QString& name)
const
4652 return IMPL->hasAttribute(name);
4656
4657
4658
4659
4660
4661
4662QString QDomElement::attributeNS(
const QString& nsURI,
const QString& localName,
const QString& defValue)
const
4666 return IMPL->attributeNS(nsURI, localName, defValue);
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681void QDomElement::setAttributeNS(
const QString& nsURI,
const QString& qName,
const QString& value)
4685 IMPL->setAttributeNS(nsURI, qName, value);
4689
4690
4691
4692
4695
4696
4697
4698
4701
4702
4703void QDomElement::setAttributeNS(
const QString& nsURI,
const QString& qName, qlonglong value)
4709 IMPL->setAttributeNS(nsURI, qName, x);
4713
4714
4715void QDomElement::setAttributeNS(
const QString& nsURI,
const QString& qName, qulonglong value)
4721 IMPL->setAttributeNS(nsURI, qName, x);
4725
4726
4727void QDomElement::setAttributeNS(
const QString& nsURI,
const QString& qName,
double value)
4732 x.setNum(value,
'g', 17);
4733 IMPL->setAttributeNS(nsURI, qName, x);
4737
4738
4739
4740
4741
4742void QDomElement::removeAttributeNS(
const QString& nsURI,
const QString& localName)
4746 QDomNodePrivate *n = IMPL->attributeNodeNS(nsURI, localName);
4749 IMPL->removeAttribute(n->nodeName());
4753
4754
4755
4756
4757
4758
4759
4760QDomAttr QDomElement::attributeNodeNS(
const QString& nsURI,
const QString& localName)
4764 return QDomAttr(IMPL->attributeNodeNS(nsURI, localName));
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777QDomAttr QDomElement::setAttributeNodeNS(
const QDomAttr& newAttr)
4781 return QDomAttr(IMPL->setAttributeNodeNS(
static_cast<QDomAttrPrivate *>(newAttr.impl)));
4785
4786
4787
4788
4789
4790
4791
4792
4793QDomNodeList QDomElement::elementsByTagNameNS(
const QString& nsURI,
const QString& localName)
const
4795 return QDomNodeList(
new QDomNodeListPrivate(impl, nsURI, localName));
4799
4800
4801
4802
4803bool QDomElement::hasAttributeNS(
const QString& nsURI,
const QString& localName)
const
4807 return IMPL->hasAttributeNS(nsURI, localName);
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824QString QDomElement::text()
const
4828 return IMPL->text();
4834
4835
4836
4837
4839QDomTextPrivate::QDomTextPrivate(QDomDocumentPrivate* d, QDomNodePrivate* parent,
const QString& val)
4840 : QDomCharacterDataPrivate(d, parent, val)
4845QDomTextPrivate::QDomTextPrivate(QDomTextPrivate* n,
bool deep)
4846 : QDomCharacterDataPrivate(n, deep)
4850QDomNodePrivate* QDomTextPrivate::cloneNode(
bool deep)
4852 QDomNodePrivate* p =
new QDomTextPrivate(
this, deep);
4858QDomTextPrivate* QDomTextPrivate::splitText(
int offset)
4861 qWarning(
"QDomText::splitText The node has no parent. So I cannot split");
4865 QDomTextPrivate* t =
new QDomTextPrivate(ownerDocument(),
nullptr, value.mid(offset));
4866 value.truncate(offset);
4868 parent()->insertAfter(t,
this);
4869 Q_ASSERT(t->ref.loadRelaxed() == 2);
4877void QDomTextPrivate::save(QTextStream& s,
int,
int)
const
4879 QDomTextPrivate *that =
const_cast<QDomTextPrivate*>(
this);
4880 s << encodeText(value, !(that->parent() && that->parent()->isElement()),
false,
true);
4884
4885
4886
4887
4889#define IMPL static_cast<QDomTextPrivate *>(impl)
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4910
4911
4912
4913
4915 : QDomCharacterData()
4920
4921
4922
4923
4924
4925
4926QDomText::QDomText(
const QDomText &text)
4927 : QDomCharacterData(text)
4931QDomText::QDomText(QDomTextPrivate* n)
4932 : QDomCharacterData(n)
4937
4938
4939
4940
4941
4942
4943QDomText &QDomText::operator=(
const QDomText &other) =
default;
4946
4947
4948
4949
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961QDomText QDomText::splitText(
int offset)
4965 return QDomText(IMPL->splitText(offset));
4971
4972
4973
4974
4976QDomCommentPrivate::QDomCommentPrivate(QDomDocumentPrivate* d, QDomNodePrivate* parent,
const QString& val)
4977 : QDomCharacterDataPrivate(d, parent, val)
4979 name = u"#comment"_s;
4982QDomCommentPrivate::QDomCommentPrivate(QDomCommentPrivate* n,
bool deep)
4983 : QDomCharacterDataPrivate(n, deep)
4988QDomNodePrivate* QDomCommentPrivate::cloneNode(
bool deep)
4990 QDomNodePrivate* p =
new QDomCommentPrivate(
this, deep);
4996void QDomCommentPrivate::save(QTextStream& s,
int depth,
int indent)
const
4999 if (!(prev && prev->isText()))
5000 s << QString(indent < 1 ? 0 : depth * indent, u' ');
5002 s <<
"<!--" << value;
5003 if (value.endsWith(u'-'))
5007 if (!(next && next->isText()))
5012
5013
5014
5015
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5039
5040
5041
5042QDomComment::QDomComment()
5043 : QDomCharacterData()
5048
5049
5050
5051
5052
5053
5054QDomComment::QDomComment(
const QDomComment &comment)
5055 : QDomCharacterData(comment)
5059QDomComment::QDomComment(QDomCommentPrivate* n)
5060 : QDomCharacterData(n)
5065
5066
5067
5068
5069
5070
5071QDomComment &QDomComment::operator=(
const QDomComment &other) =
default;
5074
5075
5076
5077
5080
5081
5082
5083
5085QDomCDATASectionPrivate::QDomCDATASectionPrivate(QDomDocumentPrivate* d, QDomNodePrivate* parent,
5087 : QDomTextPrivate(d, parent, val)
5089 name = u"#cdata-section"_s;
5092QDomCDATASectionPrivate::QDomCDATASectionPrivate(QDomCDATASectionPrivate* n,
bool deep)
5093 : QDomTextPrivate(n, deep)
5097QDomNodePrivate* QDomCDATASectionPrivate::cloneNode(
bool deep)
5099 QDomNodePrivate* p =
new QDomCDATASectionPrivate(
this, deep);
5105void QDomCDATASectionPrivate::save(QTextStream& s,
int,
int)
const
5109 s <<
"<![CDATA[" << value <<
"]]>";
5113
5114
5115
5116
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5144
5145
5146
5147QDomCDATASection::QDomCDATASection()
5153
5154
5155
5156
5157
5158
5159QDomCDATASection::QDomCDATASection(
const QDomCDATASection &cdataSection)
5160 : QDomText(cdataSection)
5164QDomCDATASection::QDomCDATASection(QDomCDATASectionPrivate* n)
5170
5171
5172
5173
5174
5175
5176QDomCDATASection &QDomCDATASection::operator=(
const QDomCDATASection &other) =
default;
5179
5180
5181
5182
5185
5186
5187
5188
5190QDomNotationPrivate::QDomNotationPrivate(QDomDocumentPrivate* d, QDomNodePrivate* parent,
5191 const QString& aname,
5192 const QString& pub,
const QString& sys)
5193 : QDomNodePrivate(d, parent)
5200QDomNotationPrivate::QDomNotationPrivate(QDomNotationPrivate* n,
bool deep)
5201 : QDomNodePrivate(n, deep)
5207QDomNodePrivate* QDomNotationPrivate::cloneNode(
bool deep)
5209 QDomNodePrivate* p =
new QDomNotationPrivate(
this, deep);
5215void QDomNotationPrivate::save(QTextStream& s,
int,
int)
const
5217 s <<
"<!NOTATION " << name <<
' ';
5218 if (!m_pub.isNull()) {
5219 s <<
"PUBLIC " << quotedValue(m_pub);
5220 if (!m_sys.isNull())
5221 s <<
' ' << quotedValue(m_sys);
5223 s <<
"SYSTEM " << quotedValue(m_sys);
5225 s <<
'>' << Qt::endl;
5229
5230
5231
5232
5234#define IMPL static_cast<QDomNotationPrivate *>(impl)
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5266
5267
5268QDomNotation::QDomNotation()
5274
5275
5276
5277
5278
5279
5280QDomNotation::QDomNotation(
const QDomNotation ¬ation)
5281 : QDomNode(notation)
5285QDomNotation::QDomNotation(QDomNotationPrivate* n)
5291
5292
5293
5294
5295
5296
5297QDomNotation &QDomNotation::operator=(
const QDomNotation &other) =
default;
5300
5301
5302
5303
5306
5307
5308QString QDomNotation::publicId()
const
5316
5317
5318QString QDomNotation::systemId()
const
5328
5329
5330
5331
5333QDomEntityPrivate::QDomEntityPrivate(QDomDocumentPrivate* d, QDomNodePrivate* parent,
5334 const QString& aname,
5335 const QString& pub,
const QString& sys,
const QString& notation)
5336 : QDomNodePrivate(d, parent)
5341 m_notationName = notation;
5344QDomEntityPrivate::QDomEntityPrivate(QDomEntityPrivate* n,
bool deep)
5345 : QDomNodePrivate(n, deep)
5349 m_notationName = n->m_notationName;
5352QDomNodePrivate* QDomEntityPrivate::cloneNode(
bool deep)
5354 QDomNodePrivate* p =
new QDomEntityPrivate(
this, deep);
5361
5362
5363static QByteArray encodeEntity(
const QByteArray& str)
5365 QByteArray tmp(str);
5366 int len = tmp.size();
5368 const char* d = tmp.constData();
5371 tmp.replace(i, 1,
"<");
5372 d = tmp.constData();
5376 else if (d[i] ==
'"') {
5377 tmp.replace(i, 1,
""");
5378 d = tmp.constData();
5381 }
else if (d[i] ==
'&' && i + 1 < len && d[i+1] ==
'#') {
5384 tmp.replace(i, 1,
"&");
5385 d = tmp.constData();
5396void QDomEntityPrivate::save(QTextStream& s,
int,
int)
const
5398 QString _name = name;
5399 if (_name.startsWith(u'%'))
5400 _name = u"% "_s + _name.mid(1);
5402 if (m_sys.isNull() && m_pub.isNull()) {
5403 s <<
"<!ENTITY " << _name <<
" \"" << encodeEntity(value.toUtf8()) <<
"\">" << Qt::endl;
5405 s <<
"<!ENTITY " << _name <<
' ';
5406 if (m_pub.isNull()) {
5407 s <<
"SYSTEM " << quotedValue(m_sys);
5409 s <<
"PUBLIC " << quotedValue(m_pub) <<
' ' << quotedValue(m_sys);
5411 if (! m_notationName.isNull()) {
5412 s <<
" NDATA " << m_notationName;
5414 s <<
'>' << Qt::endl;
5419
5420
5421
5422
5424#define IMPL static_cast<QDomEntityPrivate *>(impl)
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5459
5460
5461QDomEntity::QDomEntity()
5468
5469
5470
5471
5472
5473
5474QDomEntity::QDomEntity(
const QDomEntity &entity)
5479QDomEntity::QDomEntity(QDomEntityPrivate* n)
5485
5486
5487
5488
5489
5490
5491QDomEntity &QDomEntity::operator=(
const QDomEntity &other) =
default;
5494
5495
5496
5497
5500
5501
5502
5503QString QDomEntity::publicId()
const
5511
5512
5513
5514QString QDomEntity::systemId()
const
5522
5523
5524
5525
5526QString QDomEntity::notationName()
const
5530 return IMPL->m_notationName;
5536
5537
5538
5539
5541QDomEntityReferencePrivate::QDomEntityReferencePrivate(QDomDocumentPrivate* d, QDomNodePrivate* parent,
const QString& aname)
5542 : QDomNodePrivate(d, parent)
5547QDomEntityReferencePrivate::QDomEntityReferencePrivate(QDomNodePrivate* n,
bool deep)
5548 : QDomNodePrivate(n, deep)
5552QDomNodePrivate* QDomEntityReferencePrivate::cloneNode(
bool deep)
5554 QDomNodePrivate* p =
new QDomEntityReferencePrivate(
this, deep);
5560void QDomEntityReferencePrivate::save(QTextStream& s,
int,
int)
const
5562 s <<
'&' << name <<
';';
5566
5567
5568
5569
5572
5573
5574
5575
5576
5577
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
5607
5608
5609
5610
5611QDomEntityReference::QDomEntityReference()
5617
5618
5619
5620
5621
5622
5623QDomEntityReference::QDomEntityReference(
const QDomEntityReference &entityReference)
5624 : QDomNode(entityReference)
5628QDomEntityReference::QDomEntityReference(QDomEntityReferencePrivate* n)
5634
5635
5636
5637
5638
5639
5640QDomEntityReference &QDomEntityReference::operator=(
const QDomEntityReference &other) =
default;
5643
5644
5645
5646
5649
5650
5651
5652
5654QDomProcessingInstructionPrivate::QDomProcessingInstructionPrivate(QDomDocumentPrivate* d,
5655 QDomNodePrivate* parent,
const QString& target,
const QString& data)
5656 : QDomNodePrivate(d, parent)
5662QDomProcessingInstructionPrivate::QDomProcessingInstructionPrivate(QDomProcessingInstructionPrivate* n,
bool deep)
5663 : QDomNodePrivate(n, deep)
5668QDomNodePrivate* QDomProcessingInstructionPrivate::cloneNode(
bool deep)
5670 QDomNodePrivate* p =
new QDomProcessingInstructionPrivate(
this, deep);
5676void QDomProcessingInstructionPrivate::save(QTextStream& s,
int,
int)
const
5678 s <<
"<?" << name <<
' ' << value <<
"?>" << Qt::endl;
5682
5683
5684
5685
5688
5689
5690
5691
5692
5693
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
5729
5730
5731
5732
5733QDomProcessingInstruction::QDomProcessingInstruction()
5739
5740
5741
5742
5743
5744
5745QDomProcessingInstruction::QDomProcessingInstruction(
const QDomProcessingInstruction &processingInstruction)
5746 : QDomNode(processingInstruction)
5750QDomProcessingInstruction::QDomProcessingInstruction(QDomProcessingInstructionPrivate* n)
5756
5757
5758
5759
5760
5761
5762QDomProcessingInstruction &
5763QDomProcessingInstruction::operator=(
const QDomProcessingInstruction &other) =
default;
5766
5767
5768
5769
5772
5773
5774
5775
5776QString QDomProcessingInstruction::target()
const
5780 return impl->nodeName();
5784
5785
5786
5787
5788QString QDomProcessingInstruction::data()
const
5792 return impl->nodeValue();
5796
5797
5798
5799
5800void QDomProcessingInstruction::setData(
const QString &data)
5803 impl->setNodeValue(data);
5807
5808
5809
5810
5812QDomDocumentPrivate::QDomDocumentPrivate()
5813 : QDomNodePrivate(
nullptr),
5814 impl(
new QDomImplementationPrivate),
5817 type =
new QDomDocumentTypePrivate(
this,
this);
5820 name = u"#document"_s;
5823QDomDocumentPrivate::QDomDocumentPrivate(
const QString& aname)
5824 : QDomNodePrivate(
nullptr),
5825 impl(
new QDomImplementationPrivate),
5828 type =
new QDomDocumentTypePrivate(
this,
this);
5832 name = u"#document"_s;
5835QDomDocumentPrivate::QDomDocumentPrivate(QDomDocumentTypePrivate* dt)
5836 : QDomNodePrivate(
nullptr),
5837 impl(
new QDomImplementationPrivate),
5840 if (dt !=
nullptr) {
5843 type =
new QDomDocumentTypePrivate(
this,
this);
5847 name = u"#document"_s;
5850QDomDocumentPrivate::QDomDocumentPrivate(QDomDocumentPrivate* n,
bool deep)
5851 : QDomNodePrivate(n, deep),
5852 impl(n->impl->clone()),
5855 type =
static_cast<QDomDocumentTypePrivate*>(n->type->cloneNode());
5856 type->setParent(
this);
5859QDomDocumentPrivate::~QDomDocumentPrivate()
5863void QDomDocumentPrivate::clear()
5867 QDomNodePrivate::clear();
5870QDomDocument::ParseResult QDomDocumentPrivate::setContent(QXmlStreamReader *reader,
5871 QDomDocument::ParseOptions options)
5874 impl =
new QDomImplementationPrivate;
5875 type =
new QDomDocumentTypePrivate(
this,
this);
5879 const auto error = u"Failed to set content, XML reader is not initialized"_s;
5880 qWarning(
"%s", qPrintable(error));
5884 QDomParser domParser(
this, reader, options);
5886 if (!domParser.parse())
5887 return domParser.result();
5891QDomNodePrivate* QDomDocumentPrivate::cloneNode(
bool deep)
5893 QDomNodePrivate *p =
new QDomDocumentPrivate(
this, deep);
5899QDomElementPrivate* QDomDocumentPrivate::documentElement()
5901 QDomNodePrivate *p = first;
5902 while (p && !p->isElement())
5905 return static_cast<QDomElementPrivate *>(p);
5908QDomElementPrivate* QDomDocumentPrivate::createElement(
const QString &tagName)
5911 QString fixedName = fixedXmlName(tagName, &ok);
5915 QDomElementPrivate *e =
new QDomElementPrivate(
this,
nullptr, fixedName);
5920QDomElementPrivate* QDomDocumentPrivate::createElementNS(
const QString &nsURI,
const QString &qName)
5923 QString fixedName = fixedXmlName(qName, &ok,
true);
5927 QDomElementPrivate *e =
new QDomElementPrivate(
this,
nullptr, nsURI, fixedName);
5932QDomDocumentFragmentPrivate* QDomDocumentPrivate::createDocumentFragment()
5934 QDomDocumentFragmentPrivate *f =
new QDomDocumentFragmentPrivate(
this,
nullptr);
5939QDomTextPrivate* QDomDocumentPrivate::createTextNode(
const QString &data)
5942 QString fixedData = fixedCharData(data, &ok);
5946 QDomTextPrivate *t =
new QDomTextPrivate(
this,
nullptr, fixedData);
5951QDomCommentPrivate* QDomDocumentPrivate::createComment(
const QString &data)
5954 QString fixedData = fixedComment(data, &ok);
5958 QDomCommentPrivate *c =
new QDomCommentPrivate(
this,
nullptr, fixedData);
5963QDomCDATASectionPrivate* QDomDocumentPrivate::createCDATASection(
const QString &data)
5966 QString fixedData = fixedCDataSection(data, &ok);
5970 QDomCDATASectionPrivate *c =
new QDomCDATASectionPrivate(
this,
nullptr, fixedData);
5975QDomProcessingInstructionPrivate* QDomDocumentPrivate::createProcessingInstruction(
const QString &target,
5976 const QString &data)
5979 QString fixedData = fixedPIData(data, &ok);
5983 QString fixedTarget = fixedXmlName(target, &ok);
5987 QDomProcessingInstructionPrivate *p =
new QDomProcessingInstructionPrivate(
this,
nullptr, fixedTarget, fixedData);
5991QDomAttrPrivate* QDomDocumentPrivate::createAttribute(
const QString &aname)
5994 QString fixedName = fixedXmlName(aname, &ok);
5998 QDomAttrPrivate *a =
new QDomAttrPrivate(
this,
nullptr, fixedName);
6003QDomAttrPrivate* QDomDocumentPrivate::createAttributeNS(
const QString &nsURI,
const QString &qName)
6006 QString fixedName = fixedXmlName(qName, &ok,
true);
6010 QDomAttrPrivate *a =
new QDomAttrPrivate(
this,
nullptr, nsURI, fixedName);
6015QDomEntityReferencePrivate* QDomDocumentPrivate::createEntityReference(
const QString &aname)
6018 QString fixedName = fixedXmlName(aname, &ok);
6022 QDomEntityReferencePrivate *e =
new QDomEntityReferencePrivate(
this,
nullptr, fixedName);
6027QDomNodePrivate* QDomDocumentPrivate::importNode(QDomNodePrivate *importedNode,
bool deep)
6029 QDomNodePrivate *node =
nullptr;
6030 switch (importedNode->nodeType()) {
6031 case QDomNode::AttributeNode:
6032 node =
new QDomAttrPrivate(
static_cast<QDomAttrPrivate *>(importedNode),
true);
6034 case QDomNode::DocumentFragmentNode:
6035 node =
new QDomDocumentFragmentPrivate(
6036 static_cast<QDomDocumentFragmentPrivate *>(importedNode), deep);
6038 case QDomNode::ElementNode:
6039 node =
new QDomElementPrivate(
static_cast<QDomElementPrivate *>(importedNode), deep);
6041 case QDomNode::EntityNode:
6042 node =
new QDomEntityPrivate(
static_cast<QDomEntityPrivate *>(importedNode), deep);
6044 case QDomNode::EntityReferenceNode:
6045 node =
new QDomEntityReferencePrivate(
6046 static_cast<QDomEntityReferencePrivate *>(importedNode),
false);
6048 case QDomNode::NotationNode:
6049 node =
new QDomNotationPrivate(
static_cast<QDomNotationPrivate *>(importedNode), deep);
6051 case QDomNode::ProcessingInstructionNode:
6052 node =
new QDomProcessingInstructionPrivate(
6053 static_cast<QDomProcessingInstructionPrivate *>(importedNode), deep);
6055 case QDomNode::TextNode:
6056 node =
new QDomTextPrivate(
static_cast<QDomTextPrivate *>(importedNode), deep);
6058 case QDomNode::CDATASectionNode:
6059 node =
new QDomCDATASectionPrivate(
static_cast<QDomCDATASectionPrivate *>(importedNode),
6062 case QDomNode::CommentNode:
6063 node =
new QDomCommentPrivate(
static_cast<QDomCommentPrivate *>(importedNode), deep);
6069 node->setOwnerDocument(
this);
6077void QDomDocumentPrivate::saveDocument(QTextStream& s,
const int indent, QDomNode::EncodingPolicy encUsed)
const
6079 const QDomNodePrivate* n = first;
6081 if (encUsed == QDomNode::EncodingFromDocument) {
6082#if QT_CONFIG(regularexpression)
6083 const QDomNodePrivate* n = first;
6085 if (n && n->isProcessingInstruction() && n->nodeName() ==
"xml"_L1) {
6087 QString data = n->nodeValue();
6088 QRegularExpression encoding(QString::fromLatin1(
"encoding\\s*=\\s*((\"([^\"]*)\")|('([^']*)'))"));
6089 auto match = encoding.match(data);
6090 QString enc = match.captured(3);
6092 enc = match.captured(5);
6093 if (!enc.isEmpty()) {
6094 auto encoding = QStringConverter::encodingForName(enc.toUtf8().constData());
6096 qWarning() <<
"QDomDocument::save(): Unsupported encoding" << enc <<
"specified.";
6098 s.setEncoding(encoding.value());
6105 if (!doc && !(n->isProcessingInstruction() && n->nodeName() ==
"xml"_L1)) {
6107 type->save(s, 0, indent);
6110 n->saveSubTree(n, s, 0, indent);
6117 const QByteArray codecName = QStringConverter::nameForEncoding(s.encoding());
6119 s <<
"<?xml version=\"1.0\" encoding=\""
6124 const QDomNodePrivate* startNode = n;
6128 if (n->isProcessingInstruction() && n->nodeName() ==
"xml"_L1) {
6129 startNode = n->next;
6138 startNode->saveSubTree(startNode, s, 0, indent);
6139 startNode = startNode->next;
6145
6146
6147
6148
6150#define IMPL static_cast<QDomDocumentPrivate *>(impl)
6153
6154
6155
6156
6157
6158
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
6231
6232
6233QDomDocument::QDomDocument()
6239
6240
6241
6242QDomDocument::QDomDocument(
const QString& name)
6245 impl =
new QDomDocumentPrivate(name);
6249
6250
6251
6252
6253QDomDocument::QDomDocument(
const QDomDocumentType& doctype)
6255 impl =
new QDomDocumentPrivate(
static_cast<QDomDocumentTypePrivate *>(doctype.impl));
6259
6260
6261
6262
6263
6264
6265QDomDocument::QDomDocument(
const QDomDocument &document)
6266 : QDomNode(document)
6270QDomDocument::QDomDocument(QDomDocumentPrivate *pimpl)
6276
6277
6278
6279
6280
6281
6282QDomDocument &QDomDocument::operator=(
const QDomDocument &other) =
default;
6285
6286
6287QDomDocument::~QDomDocument()
6291#if QT_DEPRECATED_SINCE(6
, 8
)
6293QT_WARNING_DISABLE_DEPRECATED
6295
6296
6297
6298
6299
6300
6301
6302
6303bool QDomDocument::setContent(
const QString& text,
bool namespaceProcessing,
6304 QString *errorMsg,
int *errorLine,
int *errorColumn)
6306 QXmlStreamReader reader(text);
6307 reader.setNamespaceProcessing(namespaceProcessing);
6308 return setContent(&reader, namespaceProcessing, errorMsg, errorLine, errorColumn);
6312
6313
6314
6315
6316
6317
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
6363bool QDomDocument::setContent(
const QByteArray &data,
bool namespaceProcessing,
6364 QString *errorMsg,
int *errorLine,
int *errorColumn)
6366 QXmlStreamReader reader(data);
6367 reader.setNamespaceProcessing(namespaceProcessing);
6368 return setContent(&reader, namespaceProcessing, errorMsg, errorLine, errorColumn);
6371static inline QDomDocument::ParseOptions toParseOptions(
bool namespaceProcessing)
6373 return namespaceProcessing ? QDomDocument::ParseOption::UseNamespaceProcessing
6374 : QDomDocument::ParseOption::Default;
6377static inline void unpackParseResult(
const QDomDocument::ParseResult &parseResult,
6378 QString *errorMsg,
int *errorLine,
int *errorColumn)
6382 *errorMsg = parseResult.errorMessage;
6384 *errorLine =
static_cast<
int>(parseResult.errorLine);
6386 *errorColumn =
static_cast<
int>(parseResult.errorColumn);
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402bool QDomDocument::setContent(QIODevice* dev,
bool namespaceProcessing,
6403 QString *errorMsg,
int *errorLine,
int *errorColumn)
6405 ParseResult result = setContent(dev, toParseOptions(namespaceProcessing));
6406 unpackParseResult(result, errorMsg, errorLine, errorColumn);
6407 return bool(result);
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421bool QDomDocument::setContent(
const QString& text, QString *errorMsg,
int *errorLine,
int *errorColumn)
6423 return setContent(text,
false, errorMsg, errorLine, errorColumn);
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436bool QDomDocument::setContent(
const QByteArray& buffer, QString *errorMsg,
int *errorLine,
int *errorColumn )
6438 return setContent(buffer,
false, errorMsg, errorLine, errorColumn);
6442
6443
6444
6445
6446
6447
6448
6449
6450bool QDomDocument::setContent(QIODevice* dev, QString *errorMsg,
int *errorLine,
int *errorColumn )
6452 return setContent(dev,
false, errorMsg, errorLine, errorColumn);
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475bool QDomDocument::setContent(QXmlStreamReader *reader,
bool namespaceProcessing,
6476 QString *errorMsg,
int *errorLine,
int *errorColumn)
6478 ParseResult result = setContent(reader, toParseOptions(namespaceProcessing));
6479 unpackParseResult(result, errorMsg, errorLine, errorColumn);
6480 return bool(result);
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6516
6517
6518
6519
6520
6521
6522
6525
6526
6527
6528
6529
6530
6531
6534
6535
6536
6537
6538
6539
6540
6543
6544
6545
6546
6547
6548
6549
6552
6553
6554
6555
6556
6557
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
6596QDomDocument::ParseResult QDomDocument::setContentImpl(
const QByteArray &data, ParseOptions options)
6598 QXmlStreamReader reader(data);
6599 reader.setNamespaceProcessing(options.testFlag(ParseOption::UseNamespaceProcessing));
6600 return setContent(&reader, options);
6603QDomDocument::ParseResult QDomDocument::setContent(QAnyStringView data, ParseOptions options)
6605 QXmlStreamReader reader(data);
6606 reader.setNamespaceProcessing(options.testFlag(ParseOption::UseNamespaceProcessing));
6607 return setContent(&reader, options);
6610QDomDocument::ParseResult QDomDocument::setContent(QIODevice *device, ParseOptions options)
6612#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
6613 if (!device->isOpen()) {
6614 qWarning(
"QDomDocument called with unopened QIODevice. "
6615 "This will not be supported in future Qt versions.");
6616 if (!device->open(QIODevice::ReadOnly)) {
6617 const auto error = u"QDomDocument::setContent: Failed to open device."_s;
6618 qWarning(
"%s", qPrintable(error));
6624 QXmlStreamReader reader(device);
6625 reader.setNamespaceProcessing(options.testFlag(ParseOption::UseNamespaceProcessing));
6626 return setContent(&reader, options);
6629QDomDocument::ParseResult QDomDocument::setContent(QXmlStreamReader *reader, ParseOptions options)
6632 impl =
new QDomDocumentPrivate();
6633 return IMPL->setContent(reader, options);
6637
6638
6639
6640
6641
6642
6643
6644QString QDomDocument::toString(
int indent)
const
6647 QTextStream s(&str, QIODevice::WriteOnly);
6653
6654
6655
6656
6657
6658
6659
6660
6661QByteArray QDomDocument::toByteArray(
int indent)
const
6665 return toString(indent).toUtf8();
6670
6671
6672QDomDocumentType QDomDocument::doctype()
const
6675 return QDomDocumentType();
6676 return QDomDocumentType(IMPL->doctype());
6680
6681
6682QDomImplementation QDomDocument::implementation()
const
6685 return QDomImplementation();
6686 return QDomImplementation(IMPL->implementation());
6690
6691
6692QDomElement QDomDocument::documentElement()
const
6695 return QDomElement();
6696 return QDomElement(IMPL->documentElement());
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709QDomElement QDomDocument::createElement(
const QString& tagName)
6712 impl =
new QDomDocumentPrivate();
6713 return QDomElement(IMPL->createElement(tagName));
6717
6718
6719
6720
6721QDomDocumentFragment QDomDocument::createDocumentFragment()
6724 impl =
new QDomDocumentPrivate();
6725 return QDomDocumentFragment(IMPL->createDocumentFragment());
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738QDomText QDomDocument::createTextNode(
const QString& value)
6741 impl =
new QDomDocumentPrivate();
6742 return QDomText(IMPL->createTextNode(value));
6746
6747
6748
6749
6750
6751
6752
6753
6754QDomComment QDomDocument::createComment(
const QString& value)
6757 impl =
new QDomDocumentPrivate();
6758 return QDomComment(IMPL->createComment(value));
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771QDomCDATASection QDomDocument::createCDATASection(
const QString& value)
6774 impl =
new QDomDocumentPrivate();
6775 return QDomCDATASection(IMPL->createCDATASection(value));
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790QDomProcessingInstruction QDomDocument::createProcessingInstruction(
const QString& target,
6791 const QString& data)
6794 impl =
new QDomDocumentPrivate();
6795 return QDomProcessingInstruction(IMPL->createProcessingInstruction(target, data));
6800
6801
6802
6803
6804
6805
6806
6807
6808QDomAttr QDomDocument::createAttribute(
const QString& name)
6811 impl =
new QDomDocumentPrivate();
6812 return QDomAttr(IMPL->createAttribute(name));
6816
6817
6818
6819
6820
6821
6822
6823
6824QDomEntityReference QDomDocument::createEntityReference(
const QString& name)
6827 impl =
new QDomDocumentPrivate();
6828 return QDomEntityReference(IMPL->createEntityReference(name));
6832
6833
6834
6835
6836
6837
6838
6839QDomNodeList QDomDocument::elementsByTagName(
const QString& tagname)
const
6841 return QDomNodeList(
new QDomNodeListPrivate(impl, tagname));
6845
6846
6847
6848
6849
6850
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
6913QDomNode QDomDocument::importNode(
const QDomNode& importedNode,
bool deep)
6915 if (importedNode.isNull())
6918 impl =
new QDomDocumentPrivate();
6919 return QDomNode(IMPL->importNode(importedNode.impl, deep));
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934QDomElement QDomDocument::createElementNS(
const QString& nsURI,
const QString& qName)
6937 impl =
new QDomDocumentPrivate();
6938 return QDomElement(IMPL->createElementNS(nsURI, qName));
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953QDomAttr QDomDocument::createAttributeNS(
const QString& nsURI,
const QString& qName)
6956 impl =
new QDomDocumentPrivate();
6957 return QDomAttr(IMPL->createAttributeNS(nsURI, qName));
6961
6962
6963
6964
6965
6966
6967
6968QDomNodeList QDomDocument::elementsByTagNameNS(
const QString& nsURI,
const QString& localName)
6970 return QDomNodeList(
new QDomNodeListPrivate(impl, nsURI, localName));
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983QDomElement QDomDocument::elementById(
const QString& )
6985 qWarning(
"elementById() is not implemented and will always return a null node.");
6986 return QDomElement();
6990
6991
6992
6993
6998
6999
7000
7001
7004
7005
7006
7007
7008
7009QDomAttr QDomNode::toAttr()
const
7011 if (impl && impl->isAttr())
7012 return QDomAttr(
static_cast<QDomAttrPrivate *>(impl));
7017
7018
7019
7020
7021
7022QDomCDATASection QDomNode::toCDATASection()
const
7024 if (impl && impl->isCDATASection())
7025 return QDomCDATASection(
static_cast<QDomCDATASectionPrivate *>(impl));
7026 return QDomCDATASection();
7030
7031
7032
7033
7034
7035QDomDocumentFragment QDomNode::toDocumentFragment()
const
7037 if (impl && impl->isDocumentFragment())
7038 return QDomDocumentFragment(
static_cast<QDomDocumentFragmentPrivate *>(impl));
7039 return QDomDocumentFragment();
7043
7044
7045
7046
7047
7048QDomDocument QDomNode::toDocument()
const
7050 if (impl && impl->isDocument())
7051 return QDomDocument(
static_cast<QDomDocumentPrivate *>(impl));
7052 return QDomDocument();
7056
7057
7058
7059
7060
7061QDomDocumentType QDomNode::toDocumentType()
const
7063 if (impl && impl->isDocumentType())
7064 return QDomDocumentType(
static_cast<QDomDocumentTypePrivate *>(impl));
7065 return QDomDocumentType();
7069
7070
7071
7072
7073
7074QDomElement QDomNode::toElement()
const
7076 if (impl && impl->isElement())
7077 return QDomElement(
static_cast<QDomElementPrivate *>(impl));
7078 return QDomElement();
7082
7083
7084
7085
7086
7087QDomEntityReference QDomNode::toEntityReference()
const
7089 if (impl && impl->isEntityReference())
7090 return QDomEntityReference(
static_cast<QDomEntityReferencePrivate *>(impl));
7091 return QDomEntityReference();
7095
7096
7097
7098
7099
7100QDomText QDomNode::toText()
const
7102 if (impl && impl->isText())
7103 return QDomText(
static_cast<QDomTextPrivate *>(impl));
7108
7109
7110
7111
7112
7113QDomEntity QDomNode::toEntity()
const
7115 if (impl && impl->isEntity())
7116 return QDomEntity(
static_cast<QDomEntityPrivate *>(impl));
7117 return QDomEntity();
7121
7122
7123
7124
7125
7126QDomNotation QDomNode::toNotation()
const
7128 if (impl && impl->isNotation())
7129 return QDomNotation(
static_cast<QDomNotationPrivate *>(impl));
7130 return QDomNotation();
7134
7135
7136
7137
7138
7139QDomProcessingInstruction QDomNode::toProcessingInstruction()
const
7141 if (impl && impl->isProcessingInstruction())
7142 return QDomProcessingInstruction(
static_cast<QDomProcessingInstructionPrivate *>(impl));
7143 return QDomProcessingInstruction();
7147
7148
7149
7150
7151
7152QDomCharacterData QDomNode::toCharacterData()
const
7154 if (impl && impl->isCharacterData())
7155 return QDomCharacterData(
static_cast<QDomCharacterDataPrivate *>(impl));
7156 return QDomCharacterData();
7160
7161
7162
7163
7164
7165QDomComment QDomNode::toComment()
const
7167 if (impl && impl->isComment())
7168 return QDomComment(
static_cast<QDomCommentPrivate *>(impl));
7169 return QDomComment();
7173
7174
7175
7176