summaryrefslogtreecommitdiffstats
path: root/src/xml
diff options
context:
space:
mode:
Diffstat (limited to 'src/xml')
-rw-r--r--src/xml/CMakeLists.txt6
-rw-r--r--src/xml/configure.cmake3
-rw-r--r--src/xml/configure.json16
-rw-r--r--src/xml/doc/qtxml.qdocconf10
-rw-r--r--src/xml/doc/snippets/CMakeLists.txt5
-rw-r--r--src/xml/doc/snippets/code/doc_src_qtxml.qdoc51
-rw-r--r--src/xml/doc/snippets/code/src_xml_dom_qdom.cpp62
-rw-r--r--src/xml/doc/snippets/code/src_xml_dom_qdom_snippet.cpp51
-rw-r--r--src/xml/doc/snippets/code/src_xml_sax_qxml.cpp53
-rw-r--r--src/xml/doc/snippets/rsslisting/handler.cpp192
-rw-r--r--src/xml/doc/snippets/rsslisting/listing.cpp261
-rw-r--r--src/xml/doc/snippets/snippets.pro3
-rw-r--r--src/xml/doc/src/dontdocument.qdoc28
-rw-r--r--src/xml/doc/src/external-resources.qdoc28
-rw-r--r--src/xml/doc/src/qt6-changes.qdoc49
-rw-r--r--src/xml/doc/src/qtxml-index.qdoc34
-rw-r--r--src/xml/doc/src/qtxml.qdoc30
-rw-r--r--src/xml/doc/src/xml-processing.qdoc74
-rw-r--r--src/xml/dom/qdom.cpp1073
-rw-r--r--src/xml/dom/qdom.h190
-rw-r--r--src/xml/dom/qdom_p.h55
-rw-r--r--src/xml/dom/qdomhelpers.cpp185
-rw-r--r--src/xml/dom/qdomhelpers_p.h99
-rw-r--r--src/xml/qtxmlglobal.h59
24 files changed, 891 insertions, 1726 deletions
diff --git a/src/xml/CMakeLists.txt b/src/xml/CMakeLists.txt
index b2db149f8d..38b52e3a08 100644
--- a/src/xml/CMakeLists.txt
+++ b/src/xml/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from xml.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## Xml Module:
@@ -10,14 +11,17 @@ qt_internal_add_module(Xml
dom/qdomhelpers.cpp dom/qdomhelpers_p.h
qtxmlglobal.h
DEFINES
+ QT_NO_CONTEXTLESS_CONNECT
QT_NO_FOREACH
QT_NO_USING_NAMESPACE
+ QT_USE_NODISCARD_FILE_OPEN
LIBRARIES
Qt::CorePrivate
PUBLIC_LIBRARIES
Qt::Core
PRIVATE_MODULE_INTERFACE
Qt::CorePrivate
+ GENERATE_CPP_EXPORTS
)
## Scopes:
diff --git a/src/xml/configure.cmake b/src/xml/configure.cmake
index 25a7de5aa2..05cec04937 100644
--- a/src/xml/configure.cmake
+++ b/src/xml/configure.cmake
@@ -1,3 +1,6 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
#### Inputs
diff --git a/src/xml/configure.json b/src/xml/configure.json
deleted file mode 100644
index 345eb8544b..0000000000
--- a/src/xml/configure.json
+++ /dev/null
@@ -1,16 +0,0 @@
-{
- "module": "xml",
- "depends": [
- "core"
- ],
- "testDir": "../../config.tests",
-
- "features": {
- "dom": {
- "label": "DOM",
- "purpose": "Supports the Document Object Model.",
- "section": "File I/O",
- "output": [ "publicFeature", "feature" ]
- }
- }
-}
diff --git a/src/xml/doc/qtxml.qdocconf b/src/xml/doc/qtxml.qdocconf
index 0890d528c3..63d934943b 100644
--- a/src/xml/doc/qtxml.qdocconf
+++ b/src/xml/doc/qtxml.qdocconf
@@ -15,10 +15,6 @@ qhp.QtXml.virtualFolder = qtxml
qhp.QtXml.indexTitle = Qt XML
qhp.QtXml.indexRoot =
-qhp.QtXml.filterAttributes = qtxml $QT_VERSION qtrefdoc
-qhp.QtXml.customFilters.Qt.name = QtXml $QT_VERSION
-qhp.QtXml.customFilters.Qt.filterAttributes = qtxml $QT_VERSION
-
qhp.QtXml.subprojects = classes
qhp.QtXml.subprojects.classes.title = C++ Classes
qhp.QtXml.subprojects.classes.indexTitle = Qt XML C++ Classes
@@ -37,11 +33,11 @@ exampledirs += ../../../examples/xml \
. \
snippets
-imagedirs += images \
- ../../../examples/xml/images
-
navigation.landingpage = "Qt XML"
navigation.cppclassespage = "Qt XML C++ Classes"
# Add a thumbnail for examples that do not have images
manifestmeta.thumbnail.names = "QtXml/XML Stream Lint Example"
+
+# Enforce zero documentation warnings
+warninglimit = 0
diff --git a/src/xml/doc/snippets/CMakeLists.txt b/src/xml/doc/snippets/CMakeLists.txt
index 134f6c2589..57b98440d4 100644
--- a/src/xml/doc/snippets/CMakeLists.txt
+++ b/src/xml/doc/snippets/CMakeLists.txt
@@ -1,4 +1,7 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
#! [cmake_use]
-find_package(Qt6 COMPONENTS Xml REQUIRED)
+find_package(Qt6 REQUIRED COMPONENTS Xml)
target_link_libraries(mytarget PRIVATE Qt6::Xml)
#! [cmake_use]
diff --git a/src/xml/doc/snippets/code/doc_src_qtxml.qdoc b/src/xml/doc/snippets/code/doc_src_qtxml.qdoc
index c09b4bdde4..b1f24df7e1 100644
--- a/src/xml/doc/snippets/code/doc_src_qtxml.qdoc
+++ b/src/xml/doc/snippets/code/doc_src_qtxml.qdoc
@@ -1,52 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
//! [3]
<quote>A quotation.</quote>
diff --git a/src/xml/doc/snippets/code/src_xml_dom_qdom.cpp b/src/xml/doc/snippets/code/src_xml_dom_qdom.cpp
index cc5d7c0b13..7c7a59745b 100644
--- a/src/xml/doc/snippets/code/src_xml_dom_qdom.cpp
+++ b/src/xml/doc/snippets/code/src_xml_dom_qdom.cpp
@@ -1,52 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include <iostream>
#include <cstring>
#include <QFile>
@@ -136,17 +89,6 @@ for(QDomNode n = element.firstChild(); !n.isNull(); n = n.nextSibling())
//! [10]
}
-void FirstElement()
-{
-//! [11]
-QDomDocument doc;
-QDomElement root = doc.firstChildElement("database");
-QDomElement elt = root.firstChildElement("entry");
-for (; !elt.isNull(); elt = elt.nextSiblingElement("entry")) {
- // ...
-}
-//! [11]
-}
void FileContent()
{
diff --git a/src/xml/doc/snippets/code/src_xml_dom_qdom_snippet.cpp b/src/xml/doc/snippets/code/src_xml_dom_qdom_snippet.cpp
index 233cdac8d7..7bc8ec2b04 100644
--- a/src/xml/doc/snippets/code/src_xml_dom_qdom_snippet.cpp
+++ b/src/xml/doc/snippets/code/src_xml_dom_qdom_snippet.cpp
@@ -1,52 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
//! [4]
<body>
<h1>Heading</h1>
diff --git a/src/xml/doc/snippets/code/src_xml_sax_qxml.cpp b/src/xml/doc/snippets/code/src_xml_sax_qxml.cpp
deleted file mode 100644
index 7838dc9827..0000000000
--- a/src/xml/doc/snippets/code/src_xml_sax_qxml.cpp
+++ /dev/null
@@ -1,53 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-//! [0]
-xmlReader.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
-//! [0]
diff --git a/src/xml/doc/snippets/rsslisting/handler.cpp b/src/xml/doc/snippets/rsslisting/handler.cpp
deleted file mode 100644
index e1cc7a55fe..0000000000
--- a/src/xml/doc/snippets/rsslisting/handler.cpp
+++ /dev/null
@@ -1,192 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-/*
-handler.cpp
-
-Provides a handler for processing XML elements found by the reader.
-
-The handler looks for <title> and <link> elements within <item> elements,
-and records the text found within them. Link information stored within
-rdf:about attributes of <item> elements is also recorded when it is
-available.
-
-For each item found, a signal is emitted which specifies its title and
-link information. This may be used by user interfaces for the purpose of
-displaying items as they are read.
-*/
-
-#include <QtGui>
-
-#include "handler.h"
-
-/*
- Reset the state of the handler to ensure that new documents are
- read correctly.
-
- We return true to indicate that parsing should continue.
-*/
-
-bool Handler::startDocument()
-{
- inItem = false;
- inTitle = false;
- inLink = false;
-
- return true;
-}
-
-/*
- Process each starting element in the XML document.
-
- Nested item, title, or link elements are not allowed, so we return false
- if we encounter any of these. We also prohibit multiple definitions of
- title strings.
-
- Link destinations are read by this function if they are specified as
- attributes in item elements.
-
- For all cases not explicitly checked for, we return true to indicate that
- the element is acceptable, and that parsing should continue. By doing
- this, we can ignore elements in which we are not interested.
-*/
-
-bool Handler::startElement(const QString &, const QString &,
- const QString & qName, const QXmlAttributes &attr)
-{
- if (qName == "item") {
-
- if (inItem)
- return false;
- else {
- inItem = true;
- linkString = attr.value("rdf:about");
- }
- }
- else if (qName == "title") {
-
- if (inTitle)
- return false;
- else if (!titleString.isEmpty())
- return false;
- else if (inItem)
- inTitle = true;
- }
- else if (qName == "link") {
-
- if (inLink)
- return false;
- else if (inItem)
- inLink = true;
- }
-
- return true;
-}
-
-/*
- Process each ending element in the XML document.
-
- For recognized elements, we reset flags to ensure that we can read new
- instances of these elements. If we have read an item element, emit a
- signal to indicate that a new item is available for display.
-
- We return true to indicate that parsing should continue.
-*/
-
-bool Handler::endElement(const QString &, const QString &,
- const QString & qName)
-{
- if (qName == "title" && inTitle)
- inTitle = false;
- else if (qName == "link" && inLink)
- inLink = false;
- else if (qName == "item") {
- if (!titleString.isEmpty() && !linkString.isEmpty())
- emit newItem(titleString, linkString);
- inItem = false;
- titleString = "";
- linkString = "";
- }
-
- return true;
-}
-
-/*
- Collect characters when reading the contents of title or link elements
- when they occur within an item element.
-
- We return true to indicate that parsing should continue.
-*/
-
-bool Handler::characters (const QString &chars)
-{
- if (inTitle)
- titleString += chars;
- else if (inLink)
- linkString += chars;
-
- return true;
-}
-
-/*
- Report a fatal parsing error, and return false to indicate to the reader
- that parsing should stop.
-*/
-
-//! [0]
-bool Handler::fatalError (const QXmlParseException & exception)
-{
- qWarning() << "Fatal error on line" << exception.lineNumber()
- << ", column" << exception.columnNumber() << ':'
- << exception.message();
-
- return false;
-}
-//! [0]
diff --git a/src/xml/doc/snippets/rsslisting/listing.cpp b/src/xml/doc/snippets/rsslisting/listing.cpp
deleted file mode 100644
index e027dc076a..0000000000
--- a/src/xml/doc/snippets/rsslisting/listing.cpp
+++ /dev/null
@@ -1,261 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-/*
-rsslisting.cpp
-
-Provides a widget for displaying news items from RDF news sources.
-RDF is an XML-based format for storing items of information (see
-http://www.w3.org/RDF/ for details).
-
-The widget itself provides a simple user interface for specifying
-the URL of a news source, and controlling the downloading of news.
-
-The widget downloads and parses the XML asynchronously, feeding the
-data to an XML reader in pieces. This allows the user to interrupt
-its operation, and also allows very large data sources to be read.
-*/
-
-
-#include <QtCore>
-#include <QtGui>
-#include <QtNetwork>
-#include <QtXml>
-
-#include "rsslisting.h"
-
-
-/*
- Constructs an RSSListing widget with a simple user interface, and sets
- up the XML reader to use a custom handler class.
-
- The user interface consists of a line edit, two push buttons, and a
- list view widget. The line edit is used for entering the URLs of news
- sources; the push buttons start and abort the process of reading the
- news.
-*/
-
-RSSListing::RSSListing(QWidget *parent)
- : QWidget(parent)
-{
- lineEdit = new QLineEdit(this);
-
- fetchButton = new QPushButton(tr("Fetch"), this);
- abortButton = new QPushButton(tr("Abort"), this);
- abortButton->setEnabled(false);
-
- treeWidget = new QTreeWidget(this);
- QStringList headerLabels;
- headerLabels << tr("Title") << tr("Link");
- treeWidget->setHeaderLabels(headerLabels);
-
- handler = 0;
-
- connect(&http, SIGNAL(readyRead(QHttpResponseHeader)),
- this, SLOT(readData(QHttpResponseHeader)));
-
- connect(&http, SIGNAL(requestFinished(int,bool)),
- this, SLOT(finished(int,bool)));
-
- connect(lineEdit, SIGNAL(returnPressed()), this, SLOT(fetch()));
- connect(fetchButton, SIGNAL(clicked()), this, SLOT(fetch()));
- connect(abortButton, SIGNAL(clicked()), &http, SLOT(abort()));
-
- QVBoxLayout *layout = new QVBoxLayout(this);
-
- QHBoxLayout *hboxLayout = new QHBoxLayout;
-
- hboxLayout->addWidget(lineEdit);
- hboxLayout->addWidget(fetchButton);
- hboxLayout->addWidget(abortButton);
-
- layout->addLayout(hboxLayout);
- layout->addWidget(treeWidget);
-
- setWindowTitle(tr("RSS listing example"));
-}
-
-/*
- Starts fetching data from a news source specified in the line
- edit widget.
-
- The line edit is made read only to prevent the user from modifying its
- contents during the fetch; this is only for cosmetic purposes.
- The fetch button is disabled, and the abort button is enabled to allow
- the user to interrupt processing. The list view is cleared, and we
- define the last list view item to be 0, meaning that there are no
- existing items in the list.
-
- We reset the flag used to determine whether parsing should begin again
- or continue. A new handler is created, if required, and made available
- to the reader.
-
- The HTTP handler is supplied with the raw contents of the line edit and
- a fetch is initiated. We keep the ID value returned by the HTTP handler
- for future reference.
-*/
-
-void RSSListing::fetch()
-{
- lineEdit->setReadOnly(true);
- fetchButton->setEnabled(false);
- abortButton->setEnabled(true);
- treeWidget->clear();
-
- lastItemCreated = 0;
-
- newInformation = true;
-
- if (handler != 0)
- delete handler;
- handler = new Handler;
-
-//! [0]
- xmlReader.setContentHandler(handler);
- xmlReader.setErrorHandler(handler);
-//! [0]
-
- connect(handler, SIGNAL(newItem(QString&,QString&)),
- this, SLOT(addItem(QString&,QString&)));
-
- QUrl url(lineEdit->text());
-
- http.setHost(url.host());
- connectionId = http.get(url.path());
-}
-
-/*
- Reads data received from the RDF source.
-
- We read all the available data, and pass it to the XML
- input source. The first time we receive new information,
- the reader is set up for a new incremental parse;
- we continue parsing using a different function on
- subsequent calls involving the same data source.
-
- If parsing fails for any reason, we abort the fetch.
-*/
-
-//! [1]
-void RSSListing::readData(const QHttpResponseHeader &resp)
-{
- bool ok;
-
- if (resp.statusCode() != 200)
- http.abort();
- else {
- xmlInput.setData(http.readAll());
-
- if (newInformation) {
- ok = xmlReader.parse(&xmlInput, true);
- newInformation = false;
- }
- else
- ok = xmlReader.parseContinue();
-
- if (!ok)
- http.abort();
- }
-}
-//! [1]
-
-/*
- Finishes processing an HTTP request.
-
- The default behavior is to keep the text edit read only.
-
- If an error has occurred, the user interface is made available
- to the user for further input, allowing a new fetch to be
- started.
-
- If the HTTP get request has finished, we perform a final
- parsing operation on the data returned to ensure that it was
- well-formed. Whether this is successful or not, we make the
- user interface available to the user for further input.
-*/
-
-void RSSListing::finished(int id, bool error)
-{
- if (error) {
- qWarning("Received error during HTTP fetch.");
- lineEdit->setReadOnly(false);
- abortButton->setEnabled(false);
- fetchButton->setEnabled(true);
- }
- else if (id == connectionId) {
-
- bool ok = xmlReader.parseContinue();
- if (!ok)
- qWarning("Parse error at the end of input.");
-
- lineEdit->setReadOnly(false);
- abortButton->setEnabled(false);
- fetchButton->setEnabled(true);
- }
-}
-
-/*
- Adds an item to the list view as it is reported by the handler.
-
- We keep a record of the last item created to ensure that the
- items are created in sequence.
-*/
-
-void RSSListing::addItem(QString &title, QString &link)
-{
- QTreeWidgetItem *item;
-
- item = new QTreeWidgetItem(treeWidget, lastItemCreated);
- item->setText(0, title);
- item->setText(1, link);
-
- lastItemCreated = item;
-}
-
diff --git a/src/xml/doc/snippets/snippets.pro b/src/xml/doc/snippets/snippets.pro
new file mode 100644
index 0000000000..e08373a539
--- /dev/null
+++ b/src/xml/doc/snippets/snippets.pro
@@ -0,0 +1,3 @@
+#! [qmake_use]
+QT += xml
+#! [qmake_use]
diff --git a/src/xml/doc/src/dontdocument.qdoc b/src/xml/doc/src/dontdocument.qdoc
index 0193ace4b4..3601a9841a 100644
--- a/src/xml/doc/src/dontdocument.qdoc
+++ b/src/xml/doc/src/dontdocument.qdoc
@@ -1,29 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2019 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2019 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
\dontdocument (QTypeInfo)
diff --git a/src/xml/doc/src/external-resources.qdoc b/src/xml/doc/src/external-resources.qdoc
index 092e4f80b3..89c30a84c4 100644
--- a/src/xml/doc/src/external-resources.qdoc
+++ b/src/xml/doc/src/external-resources.qdoc
@@ -1,29 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
diff --git a/src/xml/doc/src/qt6-changes.qdoc b/src/xml/doc/src/qt6-changes.qdoc
index 7a19649fb2..f3ff82130a 100644
--- a/src/xml/doc/src/qt6-changes.qdoc
+++ b/src/xml/doc/src/qt6-changes.qdoc
@@ -1,35 +1,11 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
\page xml-changes-qt6.html
\title Changes to Qt XML
\ingroup changes-qt-5-to-6
- \brief Migrate Qt XML to Qt 6.
+ \brief Use QXmlStreamReader for reading XML files.
Qt 6 is a result of the conscious effort to make the framework more
efficient and easy to use.
@@ -46,7 +22,9 @@
QXmlStreamReader for reading XML files. Here are some simple steps to
port your current code to QXmlStreamReader:
- \oldcode
+ For example, if you have code like
+
+ \code
QFile *file = new QFile(...);
QXmlInputSource *source = new QXmlInputSource(file);
@@ -61,7 +39,11 @@
} else {
... // do error handling
}
- \newcode
+ \endcode
+
+ you can rewrite it as
+
+ \code
QFile file = ...;
QXmlStreamReader reader(&file);
@@ -91,6 +73,15 @@
If you use QDomDocument and rely on any of these, you must update
your code and XML documents accordingly.
+ \section3 Spacing-only text nodes
+
+ By default, text nodes containing only spacing characters are stripped
+ and won't appear in the QDomDocument. The Qt 5 way of changing this behavior
+ was using the QDomDocument::setContent() overload that allowed a \c QXmlReader
+ to be supplied. That overload was removed in Qt 6.0, but since Qt 6.5,
+ you can pass QDomDocument::ParseOption::PreserveSpacingOnlyNodes as a parse
+ option, to specify that spacing-only text nodes must be preserved.
+
\section2 Qt Core5 compatibility library
If your application or library cannot be ported right now, the \l
diff --git a/src/xml/doc/src/qtxml-index.qdoc b/src/xml/doc/src/qtxml-index.qdoc
index 79d0ae4e09..7ad55350a5 100644
--- a/src/xml/doc/src/qtxml-index.qdoc
+++ b/src/xml/doc/src/qtxml-index.qdoc
@@ -1,38 +1,12 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
\page qtxml-index.html
\title Qt XML
- \brief The Qt XML module provides C++ implementations of the SAX and DOM standards for XML.
+ \brief The Qt XML module provides a C++ implementation of the DOM standard for XML.
-
- The Qt XML module provides implementations of the SAX and DOM standards for
- XML.
+ The Qt XML module provides an implementation of the DOM standard for XML.
\note Qt XML will no longer receive additional features. For reading or
writing XML documents iteratively (SAX), use the QXmlStreamReader and
diff --git a/src/xml/doc/src/qtxml.qdoc b/src/xml/doc/src/qtxml.qdoc
index 179244bc44..76394392be 100644
--- a/src/xml/doc/src/qtxml.qdoc
+++ b/src/xml/doc/src/qtxml.qdoc
@@ -1,29 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
\module QtXml
@@ -32,7 +8,7 @@
\qtcmakepackage Xml
\qtvariable xml
- \brief The Qt XML module provides C++ implementations of the SAX and DOM standards for XML.
+ \brief The Qt XML module provides a C++ implementation of the DOM standard for XML.
The \l{Qt XML} page contains information about how to use the module.
diff --git a/src/xml/doc/src/xml-processing.qdoc b/src/xml/doc/src/xml-processing.qdoc
index 226eeb196d..acca1b070b 100644
--- a/src/xml/doc/src/xml-processing.qdoc
+++ b/src/xml/doc/src/xml-processing.qdoc
@@ -1,29 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
\group xml-tools
@@ -31,7 +7,7 @@
\brief Classes that support XML.
- These classes are relevant to XML users.
+ These classes are relevant to \l{XML Processing}{XML} users.
\generatelist{related}
*/
@@ -39,6 +15,7 @@
/*!
\page xml-processing.html
\title XML Processing
+ \ingroup explanations-dataprocessingandio
\brief An Overview of the XML processing facilities in Qt.
@@ -204,7 +181,7 @@
namespace prefix. In this case the local part and the qualified name
are identical (i.e. \e chapter).
- \sa {DOM Bookmarks Example}
+ \sa {DOM Bookmarks Application}
*/
/*!
@@ -215,7 +192,8 @@
\nextpage Working with the DOM Tree
Qt provides two classes for reading and writing XML through a simple streaming
- API: QXmlStreamReader and QXmlStreamWriter.
+ API: QXmlStreamReader and QXmlStreamWriter. These classes are located in
+ \l{Qt Serialization}{Qt Serialization (part of QtCore)}.
A stream reader reports an XML document as a stream
of tokens. This differs from SAX as SAX applications provide handlers to
@@ -231,27 +209,14 @@
\l{QXmlStreamReader::error()}{error()} and \l{QXmlStreamReader::hasError()}
{hasError()} can be used to check and view the errors.
- An example of QXmlStreamReader implementation would be the \c XbelReader in
- \l{QXmlStream Bookmarks Example}, which wraps a QXmlStreamReader.
- The constructor takes \a treeWidget as a parameter and the class has Xbel
- specific functions:
-
- \snippet streambookmarks/xbelreader.h 1
-
- \dots
- \snippet streambookmarks/xbelreader.h 2
- \dots
+ An example of an implementation tha uses QXmlStreamReader would be the
+ \l{QXmlStream Bookmarks Example#xbelreader-class-definition}{XbelReader} in
+ \l{QXmlStream Bookmarks Example}, which wraps a QXmlStreamReader. Read the
+ \l{QXmlStream Bookmarks Example#xbelreader-class-implementation}{implementation}
+ to learn more about how to use the QXmlStreamReader class.
- The \c read() function accepts a QIODevice and sets it with
- \l{QXmlStreamReader::setDevice()}{setDevice()}. The
- \l{QXmlStreamReader::raiseError()}{raiseError()} function is used to
- display a custom error message, inidicating that the file's version
- is incorrect.
-
- \snippet streambookmarks/xbelreader.cpp 1
-
- The pendent to QXmlStreamReader is QXmlStreamWriter, which provides an XML
- writer with a simple streaming API. QXmlStreamWriter operates on a
+ Paired with QXmlStreamReader is the QXmlStreamWriter class, which provides
+ an XML writer with a simple streaming API. QXmlStreamWriter operates on a
QIODevice and has specialized functions for all XML tokens or events you
want to write, such as \l{QXmlStreamWriter::writeDTD()}{writeDTD()},
\l{QXmlStreamWriter::writeCharacters()}{writeCharacters()},
@@ -277,11 +242,10 @@
or subsequent calls to \l{QXmlStreamWriter::writeStartElement()}
{writeStartElement()}.
- The \c XbelWriter class from \l{QXmlStream Bookmarks Example} wraps a
- QXmlStreamWriter. Its \c writeFile() function illustrates the core
- functions of QXmlStreamWriter mentioned above:
-
- \snippet streambookmarks/xbelwriter.cpp 1
+ The \l{QXmlStream Bookmarks Example#xbelwriter-class-definition}{XbelWriter}
+ class from \l{QXmlStream Bookmarks Example} wraps a QXmlStreamWriter. View
+ the \l{QXmlStream Bookmarks Example#xbelwriter-class-implementation}{implementation}
+ to see how to use the QXmlStreamWriter class.
*/
/*!
@@ -376,7 +340,7 @@
DOM implementation.
To get started please refer to the \l QDomDocument documentation.
- You might also want to take a look at the \l{DOM Bookmarks Example},
+ You might also want to take a look at the \l{DOM Bookmarks Application},
which illustrates how to read and write an XML bookmark file (XBEL)
using DOM.
*/
diff --git a/src/xml/dom/qdom.cpp b/src/xml/dom/qdom.cpp
index b7c676dd09..b25cdf487f 100644
--- a/src/xml/dom/qdom.cpp
+++ b/src/xml/dom/qdom.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtXml module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include <qplatformdefs.h>
#include <qdom.h>
@@ -58,7 +22,8 @@
#include <qdebug.h>
#include <qxmlstream.h>
#include <private/qduplicatetracker_p.h>
-
+#include <private/qstringiterator_p.h>
+#include <qvarlengtharray.h>
#include <stdio.h>
#include <limits>
@@ -66,6 +31,8 @@
QT_BEGIN_NAMESPACE
+using namespace Qt::StringLiterals;
+
/*
### old todo comments -- I don't know if they still apply...
@@ -80,7 +47,7 @@ QT_BEGIN_NAMESPACE
/* ##### new TODOs:
- Remove emtpy emthods in the *Private classes
+ Remove empty methods in the *Private classes
Make a lot of the (mostly empty) methods in the public classes inline.
Specially constructors assignment operators and comparison operators are candidates.
@@ -105,10 +72,10 @@ QT_BEGIN_NAMESPACE
*/
static void qt_split_namespace(QString& prefix, QString& name, const QString& qName, bool hasURI)
{
- int i = qName.indexOf(QLatin1Char(':'));
+ qsizetype i = qName.indexOf(u':');
if (i == -1) {
if (hasURI)
- prefix = QLatin1String("");
+ prefix = u""_s;
else
prefix.clear();
name = qName;
@@ -175,7 +142,7 @@ static QString fixedXmlName(const QString &_name, bool *ok, bool namespaces = fa
*ok = true;
if (namespaces && !prefix.isEmpty())
- return prefix + QLatin1Char(':') + result;
+ return prefix + u':' + result;
return result;
}
@@ -190,10 +157,11 @@ static QString fixedCharData(const QString &data, bool *ok)
}
QString result;
- for (int i = 0; i < data.size(); ++i) {
- QChar c = data.at(i);
+ QStringIterator it(data);
+ while (it.hasNext()) {
+ const char32_t c = it.next(QChar::Null);
if (QXmlUtils::isChar(c)) {
- result.append(c);
+ result.append(QChar::fromUcs4(c));
} else if (QDomImplementationPrivate::invalidDataPolicy == QDomImplementation::ReturnNullNode) {
*ok = false;
return QString();
@@ -219,7 +187,7 @@ static QString fixedComment(const QString &data, bool *ok)
return QString();
for (;;) {
- int idx = fixedData.indexOf(QLatin1String("--"));
+ qsizetype idx = fixedData.indexOf("--"_L1);
if (idx == -1)
break;
if (QDomImplementationPrivate::invalidDataPolicy == QDomImplementation::ReturnNullNode) {
@@ -248,7 +216,7 @@ static QString fixedCDataSection(const QString &data, bool *ok)
return QString();
for (;;) {
- int idx = fixedData.indexOf(QLatin1String("]]>"));
+ qsizetype idx = fixedData.indexOf("]]>"_L1);
if (idx == -1)
break;
if (QDomImplementationPrivate::invalidDataPolicy == QDomImplementation::ReturnNullNode) {
@@ -276,7 +244,7 @@ static QString fixedPIData(const QString &data, bool *ok)
return QString();
for (;;) {
- int idx = fixedData.indexOf(QLatin1String("?>"));
+ qsizetype idx = fixedData.indexOf("?>"_L1);
if (idx == -1)
break;
if (QDomImplementationPrivate::invalidDataPolicy == QDomImplementation::ReturnNullNode) {
@@ -309,13 +277,12 @@ static QString fixedPubidLiteral(const QString &data, bool *ok)
return QString();
}
- if (result.indexOf(QLatin1Char('\'')) != -1
- && result.indexOf(QLatin1Char('"')) != -1) {
+ if (result.indexOf(u'\'') != -1 && result.indexOf(u'"') != -1) {
if (QDomImplementationPrivate::invalidDataPolicy == QDomImplementation::ReturnNullNode) {
*ok = false;
return QString();
} else {
- result.remove(QLatin1Char('\''));
+ result.remove(u'\'');
}
}
@@ -335,13 +302,12 @@ static QString fixedSystemLiteral(const QString &data, bool *ok)
QString result = data;
- if (result.indexOf(QLatin1Char('\'')) != -1
- && result.indexOf(QLatin1Char('"')) != -1) {
+ if (result.indexOf(u'\'') != -1 && result.indexOf(u'"') != -1) {
if (QDomImplementationPrivate::invalidDataPolicy == QDomImplementation::ReturnNullNode) {
*ok = false;
return QString();
} else {
- result.remove(QLatin1Char('\''));
+ result.remove(u'\'');
}
}
@@ -408,52 +374,52 @@ QDomImplementation::QDomImplementation()
}
/*!
- Constructs a copy of \a x.
+ Constructs a copy of \a implementation.
*/
-QDomImplementation::QDomImplementation(const QDomImplementation &x)
+QDomImplementation::QDomImplementation(const QDomImplementation &implementation)
+ : impl(implementation.impl)
{
- impl = x.impl;
if (impl)
impl->ref.ref();
}
-QDomImplementation::QDomImplementation(QDomImplementationPrivate *p)
+QDomImplementation::QDomImplementation(QDomImplementationPrivate *pimpl)
+ : impl(pimpl)
{
// We want to be co-owners, so increase the reference count
- impl = p;
if (impl)
impl->ref.ref();
}
/*!
- Assigns \a x to this DOM implementation.
+ Assigns \a other to this DOM implementation.
*/
-QDomImplementation& QDomImplementation::operator=(const QDomImplementation &x)
+QDomImplementation& QDomImplementation::operator=(const QDomImplementation &other)
{
- if (x.impl)
- x.impl->ref.ref();
+ if (other.impl)
+ other.impl->ref.ref();
if (impl && !impl->ref.deref())
delete impl;
- impl = x.impl;
+ impl = other.impl;
return *this;
}
/*!
- Returns \c true if \a x and this DOM implementation object were
+ Returns \c true if \a other and this DOM implementation object were
created from the same QDomDocument; otherwise returns \c false.
*/
-bool QDomImplementation::operator==(const QDomImplementation &x) const
+bool QDomImplementation::operator==(const QDomImplementation &other) const
{
- return (impl == x.impl);
+ return impl == other.impl;
}
/*!
- Returns \c true if \a x and this DOM implementation object were
+ Returns \c true if \a other and this DOM implementation object were
created from different QDomDocuments; otherwise returns \c false.
*/
-bool QDomImplementation::operator!=(const QDomImplementation &x) const
+bool QDomImplementation::operator!=(const QDomImplementation &other) const
{
- return (impl != x.impl);
+ return !operator==(other);
}
/*!
@@ -477,10 +443,9 @@ QDomImplementation::~QDomImplementation()
*/
bool QDomImplementation::hasFeature(const QString& feature, const QString& version) const
{
- if (feature == QLatin1String("XML")) {
- if (version.isEmpty() || version == QLatin1String("1.0")) {
+ if (feature == "XML"_L1) {
+ if (version.isEmpty() || version == "1.0"_L1)
return true;
- }
}
// ### add DOM level 2 features
return false;
@@ -681,10 +646,10 @@ bool QDomNodeListPrivate::operator==(const QDomNodeListPrivate &other) const
bool QDomNodeListPrivate::operator!=(const QDomNodeListPrivate &other) const
{
- return (node_impl != other.node_impl) || (tagname != other.tagname);
+ return !operator==(other);
}
-void QDomNodeListPrivate::createList()
+void QDomNodeListPrivate::createList() const
{
if (!node_impl)
return;
@@ -738,16 +703,21 @@ void QDomNodeListPrivate::createList()
}
}
-QDomNodePrivate* QDomNodeListPrivate::item(int index)
+bool QDomNodeListPrivate::maybeCreateList() const
{
if (!node_impl)
- return nullptr;
+ return false;
const QDomDocumentPrivate *const doc = node_impl->ownerDocument();
if (!doc || timestamp != doc->nodeListTime)
createList();
- if (index >= list.size())
+ return true;
+}
+
+QDomNodePrivate *QDomNodeListPrivate::item(int index)
+{
+ if (!maybeCreateList() || index >= list.size() || index < 0)
return nullptr;
return list.at(index);
@@ -755,16 +725,10 @@ QDomNodePrivate* QDomNodeListPrivate::item(int index)
int QDomNodeListPrivate::length() const
{
- if (!node_impl)
+ if (!maybeCreateList())
return 0;
- const QDomDocumentPrivate *const doc = node_impl->ownerDocument();
- if (!doc || timestamp != doc->nodeListTime) {
- QDomNodeListPrivate *that = const_cast<QDomNodeListPrivate *>(this);
- that->createList();
- }
-
- return list.count();
+ return list.size();
}
/**************************************************************
@@ -806,54 +770,54 @@ QDomNodeList::QDomNodeList()
{
}
-QDomNodeList::QDomNodeList(QDomNodeListPrivate* p)
- : impl(p)
+QDomNodeList::QDomNodeList(QDomNodeListPrivate *pimpl)
+ : impl(pimpl)
{
}
/*!
- Constructs a copy of \a n.
+ Constructs a copy of \a nodeList.
*/
-QDomNodeList::QDomNodeList(const QDomNodeList& n)
+QDomNodeList::QDomNodeList(const QDomNodeList &nodeList)
+ : impl(nodeList.impl)
{
- impl = n.impl;
if (impl)
impl->ref.ref();
}
/*!
- Assigns \a n to this node list.
+ Assigns \a other to this node list.
*/
-QDomNodeList& QDomNodeList::operator=(const QDomNodeList &n)
+QDomNodeList& QDomNodeList::operator=(const QDomNodeList &other)
{
- if (n.impl)
- n.impl->ref.ref();
+ if (other.impl)
+ other.impl->ref.ref();
if (impl && !impl->ref.deref())
delete impl;
- impl = n.impl;
+ impl = other.impl;
return *this;
}
/*!
- Returns \c true if the node list \a n and this node list are equal;
+ Returns \c true if the node list \a other and this node list are equal;
otherwise returns \c false.
*/
-bool QDomNodeList::operator==(const QDomNodeList &n) const
+bool QDomNodeList::operator==(const QDomNodeList &other) const
{
- if (impl == n.impl)
+ if (impl == other.impl)
return true;
- if (!impl || !n.impl)
+ if (!impl || !other.impl)
return false;
- return (*impl == *n.impl);
+ return (*impl == *other.impl);
}
/*!
- Returns \c true the node list \a n and this node list are not equal;
+ Returns \c true the node list \a other and this node list are not equal;
otherwise returns \c false.
*/
-bool QDomNodeList::operator!=(const QDomNodeList &n) const
+bool QDomNodeList::operator!=(const QDomNodeList &other) const
{
- return !operator==(n);
+ return !operator==(other);
}
/*!
@@ -1261,8 +1225,7 @@ QDomNodePrivate* QDomNodePrivate::replaceChild(QDomNodePrivate* newChild, QDomNo
newChild->last = nullptr;
// We are no longer interested in the old node
- if (oldChild)
- oldChild->ref.deref();
+ oldChild->ref.deref();
return oldChild;
}
@@ -1295,8 +1258,7 @@ QDomNodePrivate* QDomNodePrivate::replaceChild(QDomNodePrivate* newChild, QDomNo
oldChild->prev = nullptr;
// We are no longer interested in the old node
- if (oldChild)
- oldChild->ref.deref();
+ oldChild->ref.deref();
return oldChild;
}
@@ -1348,7 +1310,7 @@ QDomDocumentPrivate* QDomNodePrivate::ownerDocument()
QDomNodePrivate* p = this;
while (p && !p->isDocument()) {
if (!p->hasParent)
- return (QDomDocumentPrivate*)p->ownerNode;
+ return static_cast<QDomDocumentPrivate *>(p->ownerNode);
p = p->parent();
}
@@ -1376,7 +1338,7 @@ static void qNormalizeNode(QDomNodePrivate* n)
n->removeChild(p);
p = tmp;
} else {
- t = (QDomTextPrivate*)p;
+ t = static_cast<QDomTextPrivate *>(p);
p = p->next;
}
} else {
@@ -1416,7 +1378,7 @@ void QDomNodePrivate::setLocation(int lineNumber, int columnNumber)
*
**************************************************************/
-#define IMPL ((QDomNodePrivate*)impl)
+#define IMPL static_cast<QDomNodePrivate *>(impl)
/*!
\class QDomNode
@@ -1511,48 +1473,48 @@ QDomNode::QDomNode()
}
/*!
- Constructs a copy of \a n.
+ Constructs a copy of \a node.
The data of the copy is shared (shallow copy): modifying one node
will also change the other. If you want to make a deep copy, use
cloneNode().
*/
-QDomNode::QDomNode(const QDomNode &n)
+QDomNode::QDomNode(const QDomNode &node)
+ : impl(node.impl)
{
- impl = n.impl;
if (impl)
impl->ref.ref();
}
/*! \internal
- Constructs a new node for the data \a n.
+ Constructs a new node for the data \a pimpl.
*/
-QDomNode::QDomNode(QDomNodePrivate *n)
+QDomNode::QDomNode(QDomNodePrivate *pimpl)
+ : impl(pimpl)
{
- impl = n;
if (impl)
impl->ref.ref();
}
/*!
- Assigns a copy of \a n to this DOM node.
+ Assigns a copy of \a other to this DOM node.
The data of the copy is shared (shallow copy): modifying one node
will also change the other. If you want to make a deep copy, use
cloneNode().
*/
-QDomNode& QDomNode::operator=(const QDomNode &n)
+QDomNode& QDomNode::operator=(const QDomNode &other)
{
- if (n.impl)
- n.impl->ref.ref();
+ if (other.impl)
+ other.impl->ref.ref();
if (impl && !impl->ref.deref())
delete impl;
- impl = n.impl;
+ impl = other.impl;
return *this;
}
/*!
- Returns \c true if \a n and this DOM node are equal; otherwise
+ Returns \c true if \a other and this DOM node are equal; otherwise
returns \c false.
Any instance of QDomNode acts as a reference to an underlying data
@@ -1571,18 +1533,18 @@ QDomNode& QDomNode::operator=(const QDomNode &n)
\c {element3 == element4} will return false because they refer to
two different nodes in the underlying data structure.
*/
-bool QDomNode::operator== (const QDomNode& n) const
+bool QDomNode::operator==(const QDomNode &other) const
{
- return (impl == n.impl);
+ return impl == other.impl;
}
/*!
- Returns \c true if \a n and this DOM node are not equal; otherwise
+ Returns \c true if \a other and this DOM node are not equal; otherwise
returns \c false.
*/
-bool QDomNode::operator!= (const QDomNode& n) const
+bool QDomNode::operator!=(const QDomNode &other) const
{
- return (impl != n.impl);
+ return !operator==(other);
}
/*!
@@ -1629,7 +1591,7 @@ QString QDomNode::nodeName() const
return QString();
if (!IMPL->prefix.isEmpty())
- return IMPL->prefix + QLatin1Char(':') + IMPL->name;
+ return IMPL->prefix + u':' + IMPL->name;
return IMPL->name;
}
@@ -1659,15 +1621,14 @@ QString QDomNode::nodeValue() const
}
/*!
- Sets the node's value to \a v.
+ Sets the node's value to \a value.
\sa nodeValue()
*/
-void QDomNode::setNodeValue(const QString& v)
+void QDomNode::setNodeValue(const QString& value)
{
- if (!impl)
- return;
- IMPL->setNodeValue(v);
+ if (impl)
+ IMPL->setNodeValue(value);
}
/*!
@@ -2541,11 +2502,12 @@ int QDomNode::columnNumber() const
*
**************************************************************/
-QDomNamedNodeMapPrivate::QDomNamedNodeMapPrivate(QDomNodePrivate* n) : ref(1)
+QDomNamedNodeMapPrivate::QDomNamedNodeMapPrivate(QDomNodePrivate *pimpl)
+ : ref(1)
+ , parent(pimpl)
+ , readonly(false)
+ , appendToParent(false)
{
- readonly = false;
- parent = n;
- appendToParent = false;
}
QDomNamedNodeMapPrivate::~QDomNamedNodeMapPrivate()
@@ -2553,16 +2515,16 @@ QDomNamedNodeMapPrivate::~QDomNamedNodeMapPrivate()
clearMap();
}
-QDomNamedNodeMapPrivate* QDomNamedNodeMapPrivate::clone(QDomNodePrivate* p)
+QDomNamedNodeMapPrivate* QDomNamedNodeMapPrivate::clone(QDomNodePrivate *pimpl)
{
- std::unique_ptr<QDomNamedNodeMapPrivate> m(new QDomNamedNodeMapPrivate(p));
+ std::unique_ptr<QDomNamedNodeMapPrivate> m(new QDomNamedNodeMapPrivate(pimpl));
m->readonly = readonly;
m->appendToParent = appendToParent;
auto it = map.constBegin();
for (; it != map.constEnd(); ++it) {
- QDomNodePrivate *new_node = (*it)->cloneNode();
- new_node->setParent(p);
+ QDomNodePrivate *new_node = it.value()->cloneNode();
+ new_node->setParent(pimpl);
m->setNamedItem(new_node);
}
@@ -2577,16 +2539,16 @@ void QDomNamedNodeMapPrivate::clearMap()
if (!appendToParent) {
auto it = map.constBegin();
for (; it != map.constEnd(); ++it)
- if (!(*it)->ref.deref())
- delete *it;
+ if (!it.value()->ref.deref())
+ delete it.value();
}
map.clear();
}
QDomNodePrivate* QDomNamedNodeMapPrivate::namedItem(const QString& name) const
{
- auto it = map.constFind(name);
- return it == map.cend() ? nullptr : *it;
+ auto it = map.find(name);
+ return it == map.end() ? nullptr : it.value();
}
QDomNodePrivate* QDomNamedNodeMapPrivate::namedItemNS(const QString& nsURI, const QString& localName) const
@@ -2594,7 +2556,7 @@ QDomNodePrivate* QDomNamedNodeMapPrivate::namedItemNS(const QString& nsURI, cons
auto it = map.constBegin();
QDomNodePrivate *n;
for (; it != map.constEnd(); ++it) {
- n = *it;
+ n = it.value();
if (!n->prefix.isNull()) {
// node has a namespace
if (n->namespaceURI == nsURI && n->name == localName)
@@ -2661,12 +2623,12 @@ QDomNodePrivate* QDomNamedNodeMapPrivate::item(int index) const
{
if (index >= length() || index < 0)
return nullptr;
- return *std::next(map.cbegin(), index);
+ return std::next(map.begin(), index).value();
}
int QDomNamedNodeMapPrivate::length() const
{
- return map.count();
+ return map.size();
}
bool QDomNamedNodeMapPrivate::contains(const QString& name) const
@@ -2685,7 +2647,7 @@ bool QDomNamedNodeMapPrivate::containsNS(const QString& nsURI, const QString & l
*
**************************************************************/
-#define IMPL ((QDomNamedNodeMapPrivate*)impl)
+#define IMPL static_cast<QDomNamedNodeMapPrivate *>(impl)
/*!
\class QDomNamedNodeMap
@@ -2734,51 +2696,51 @@ QDomNamedNodeMap::QDomNamedNodeMap()
}
/*!
- Constructs a copy of \a n.
+ Constructs a copy of \a namedNodeMap.
*/
-QDomNamedNodeMap::QDomNamedNodeMap(const QDomNamedNodeMap &n)
+QDomNamedNodeMap::QDomNamedNodeMap(const QDomNamedNodeMap &namedNodeMap)
+ : impl(namedNodeMap.impl)
{
- impl = n.impl;
if (impl)
impl->ref.ref();
}
-QDomNamedNodeMap::QDomNamedNodeMap(QDomNamedNodeMapPrivate *n)
+QDomNamedNodeMap::QDomNamedNodeMap(QDomNamedNodeMapPrivate *pimpl)
+ : impl(pimpl)
{
- impl = n;
if (impl)
impl->ref.ref();
}
/*!
- Assigns \a n to this named node map.
+ Assigns \a other to this named node map.
*/
-QDomNamedNodeMap& QDomNamedNodeMap::operator=(const QDomNamedNodeMap &n)
+QDomNamedNodeMap& QDomNamedNodeMap::operator=(const QDomNamedNodeMap &other)
{
- if (n.impl)
- n.impl->ref.ref();
+ if (other.impl)
+ other.impl->ref.ref();
if (impl && !impl->ref.deref())
delete impl;
- impl = n.impl;
+ impl = other.impl;
return *this;
}
/*!
- Returns \c true if \a n and this named node map are equal; otherwise
+ Returns \c true if \a other and this named node map are equal; otherwise
returns \c false.
*/
-bool QDomNamedNodeMap::operator== (const QDomNamedNodeMap& n) const
+bool QDomNamedNodeMap::operator==(const QDomNamedNodeMap &other) const
{
- return (impl == n.impl);
+ return impl == other.impl;
}
/*!
- Returns \c true if \a n and this named node map are not equal;
+ Returns \c true if \a other and this named node map are not equal;
otherwise returns \c false.
*/
-bool QDomNamedNodeMap::operator!= (const QDomNamedNodeMap& n) const
+bool QDomNamedNodeMap::operator!=(const QDomNamedNodeMap &other) const
{
- return (impl != n.impl);
+ return !operator==(other);
}
/*!
@@ -2820,7 +2782,7 @@ QDomNode QDomNamedNodeMap::setNamedItem(const QDomNode& newNode)
{
if (!impl)
return QDomNode();
- return QDomNode(IMPL->setNamedItem((QDomNodePrivate*)newNode.impl));
+ return QDomNode(IMPL->setNamedItem(static_cast<QDomNodePrivate *>(newNode.impl)));
}
/*!
@@ -2882,7 +2844,7 @@ QDomNode QDomNamedNodeMap::setNamedItemNS(const QDomNode& newNode)
{
if (!impl)
return QDomNode();
- return QDomNode(IMPL->setNamedItemNS((QDomNodePrivate*)newNode.impl));
+ return QDomNode(IMPL->setNamedItemNS(static_cast<QDomNodePrivate *>(newNode.impl)));
}
/*!
@@ -3018,7 +2980,7 @@ QDomNodePrivate* QDomDocumentTypePrivate::cloneNode(bool deep)
QDomNodePrivate* QDomDocumentTypePrivate::insertBefore(QDomNodePrivate* newChild, QDomNodePrivate* refChild)
{
- // Call the origianl implementation
+ // Call the original implementation
QDomNodePrivate* p = QDomNodePrivate::insertBefore(newChild, refChild);
// Update the maps
if (p && p->isEntity())
@@ -3031,7 +2993,7 @@ QDomNodePrivate* QDomDocumentTypePrivate::insertBefore(QDomNodePrivate* newChild
QDomNodePrivate* QDomDocumentTypePrivate::insertAfter(QDomNodePrivate* newChild, QDomNodePrivate* refChild)
{
- // Call the origianl implementation
+ // Call the original implementation
QDomNodePrivate* p = QDomNodePrivate::insertAfter(newChild, refChild);
// Update the maps
if (p && p->isEntity())
@@ -3044,7 +3006,7 @@ QDomNodePrivate* QDomDocumentTypePrivate::insertAfter(QDomNodePrivate* newChild,
QDomNodePrivate* QDomDocumentTypePrivate::replaceChild(QDomNodePrivate* newChild, QDomNodePrivate* oldChild)
{
- // Call the origianl implementation
+ // Call the original implementation
QDomNodePrivate* p = QDomNodePrivate::replaceChild(newChild, oldChild);
// Update the maps
if (p) {
@@ -3064,7 +3026,7 @@ QDomNodePrivate* QDomDocumentTypePrivate::replaceChild(QDomNodePrivate* newChild
QDomNodePrivate* QDomDocumentTypePrivate::removeChild(QDomNodePrivate* oldChild)
{
- // Call the origianl implementation
+ // Call the original implementation
QDomNodePrivate* p = QDomNodePrivate::removeChild( oldChild);
// Update the maps
if (p && p->isEntity())
@@ -3082,9 +3044,7 @@ QDomNodePrivate* QDomDocumentTypePrivate::appendChild(QDomNodePrivate* newChild)
static QString quotedValue(const QString &data)
{
- QChar quote = data.indexOf(QLatin1Char('\'')) == -1
- ? QLatin1Char('\'')
- : QLatin1Char('"');
+ QChar quote = data.indexOf(u'\'') == -1 ? u'\'' : u'"';
return quote + data + quote;
}
@@ -3109,11 +3069,11 @@ void QDomDocumentTypePrivate::save(QTextStream& s, int, int indent) const
auto it2 = notations->map.constBegin();
for (; it2 != notations->map.constEnd(); ++it2)
- (*it2)->save(s, 0, indent);
+ it2.value()->save(s, 0, indent);
auto it = entities->map.constBegin();
for (; it != entities->map.constEnd(); ++it)
- (*it)->save(s, 0, indent);
+ it.value()->save(s, 0, indent);
s << ']';
}
@@ -3127,7 +3087,7 @@ void QDomDocumentTypePrivate::save(QTextStream& s, int, int indent) const
*
**************************************************************/
-#define IMPL ((QDomDocumentTypePrivate*)impl)
+#define IMPL static_cast<QDomDocumentTypePrivate *>(impl)
/*!
\class QDomDocumentType
@@ -3156,34 +3116,30 @@ QDomDocumentType::QDomDocumentType() : QDomNode()
}
/*!
- Constructs a copy of \a n.
+ Constructs a copy of \a documentType.
The data of the copy is shared (shallow copy): modifying one node
will also change the other. If you want to make a deep copy, use
cloneNode().
*/
-QDomDocumentType::QDomDocumentType(const QDomDocumentType& n)
- : QDomNode(n)
+QDomDocumentType::QDomDocumentType(const QDomDocumentType &documentType)
+ : QDomNode(documentType)
{
}
-QDomDocumentType::QDomDocumentType(QDomDocumentTypePrivate* n)
- : QDomNode(n)
+QDomDocumentType::QDomDocumentType(QDomDocumentTypePrivate *pimpl)
+ : QDomNode(pimpl)
{
}
/*!
- Assigns \a n to this document type.
+ Assigns \a other to this document type.
The data of the copy is shared (shallow copy): modifying one node
will also change the other. If you want to make a deep copy, use
cloneNode().
*/
-QDomDocumentType& QDomDocumentType::operator= (const QDomDocumentType& n)
-{
- return (QDomDocumentType&) QDomNode::operator=(n);
-}
-
+QDomDocumentType &QDomDocumentType::operator=(const QDomDocumentType &other) = default;
/*!
Returns the name of the document type as specified in the
&lt;!DOCTYPE name&gt; tag.
@@ -3281,7 +3237,7 @@ QString QDomDocumentType::internalSubset() const
QDomDocumentFragmentPrivate::QDomDocumentFragmentPrivate(QDomDocumentPrivate* doc, QDomNodePrivate* parent)
: QDomNodePrivate(doc, parent)
{
- name = QLatin1String("#document-fragment");
+ name = u"#document-fragment"_s;
}
QDomDocumentFragmentPrivate::QDomDocumentFragmentPrivate(QDomNodePrivate* n, bool deep)
@@ -3341,28 +3297,25 @@ QDomDocumentFragment::QDomDocumentFragment(QDomDocumentFragmentPrivate* n)
}
/*!
- Constructs a copy of \a x.
+ Constructs a copy of \a documentFragment.
The data of the copy is shared (shallow copy): modifying one node
will also change the other. If you want to make a deep copy, use
cloneNode().
*/
-QDomDocumentFragment::QDomDocumentFragment(const QDomDocumentFragment& x)
- : QDomNode(x)
+QDomDocumentFragment::QDomDocumentFragment(const QDomDocumentFragment &documentFragment)
+ : QDomNode(documentFragment)
{
}
/*!
- Assigns \a x to this DOM document fragment.
+ Assigns \a other to this DOM document fragment.
The data of the copy is shared (shallow copy): modifying one node
will also change the other. If you want to make a deep copy, use
cloneNode().
*/
-QDomDocumentFragment& QDomDocumentFragment::operator= (const QDomDocumentFragment& x)
-{
- return (QDomDocumentFragment&) QDomNode::operator=(x);
-}
+QDomDocumentFragment &QDomDocumentFragment::operator=(const QDomDocumentFragment &other) = default;
/*!
\fn QDomNode::NodeType QDomDocumentFragment::nodeType() const
@@ -3383,7 +3336,7 @@ QDomCharacterDataPrivate::QDomCharacterDataPrivate(QDomDocumentPrivate* d, QDomN
: QDomNodePrivate(d, p)
{
value = data;
- name = QLatin1String("#character-data");
+ name = u"#character-data"_s;
}
QDomCharacterDataPrivate::QDomCharacterDataPrivate(QDomCharacterDataPrivate* n, bool deep)
@@ -3401,7 +3354,7 @@ QDomNodePrivate* QDomCharacterDataPrivate::cloneNode(bool deep)
int QDomCharacterDataPrivate::dataLength() const
{
- return value.length();
+ return value.size();
}
QString QDomCharacterDataPrivate::substringData(unsigned long offset, unsigned long n) const
@@ -3435,7 +3388,7 @@ void QDomCharacterDataPrivate::appendData(const QString& arg)
*
**************************************************************/
-#define IMPL ((QDomCharacterDataPrivate*)impl)
+#define IMPL static_cast<QDomCharacterDataPrivate *>(impl)
/*!
\class QDomCharacterData
@@ -3470,14 +3423,14 @@ QDomCharacterData::QDomCharacterData()
}
/*!
- Constructs a copy of \a x.
+ Constructs a copy of \a characterData.
The data of the copy is shared (shallow copy): modifying one node
will also change the other. If you want to make a deep copy, use
cloneNode().
*/
-QDomCharacterData::QDomCharacterData(const QDomCharacterData& x)
- : QDomNode(x)
+QDomCharacterData::QDomCharacterData(const QDomCharacterData &characterData)
+ : QDomNode(characterData)
{
}
@@ -3487,16 +3440,13 @@ QDomCharacterData::QDomCharacterData(QDomCharacterDataPrivate* n)
}
/*!
- Assigns \a x to this character data.
+ Assigns \a other to this character data.
The data of the copy is shared (shallow copy): modifying one node
will also change the other. If you want to make a deep copy, use
cloneNode().
*/
-QDomCharacterData& QDomCharacterData::operator= (const QDomCharacterData& x)
-{
- return (QDomCharacterData&) QDomNode::operator=(x);
-}
+QDomCharacterData &QDomCharacterData::operator=(const QDomCharacterData &other) = default;
/*!
Returns the string stored in this object.
@@ -3512,12 +3462,12 @@ QString QDomCharacterData::data() const
}
/*!
- Sets this object's string to \a v.
+ Sets this object's string to \a data.
*/
-void QDomCharacterData::setData(const QString& v)
+void QDomCharacterData::setData(const QString &data)
{
if (impl)
- impl->setNodeValue(v);
+ impl->setNodeValue(data);
}
/*!
@@ -3627,7 +3577,7 @@ void QDomAttrPrivate::setNodeValue(const QString& v)
t->ref.deref();
if (first) {
auto removed = removeChild(first);
- if (removed && !removed->ref)
+ if (removed && !removed->ref.loadRelaxed()) // removeChild() already deref()ed
delete removed;
}
appendChild(t);
@@ -3662,38 +3612,38 @@ static QString encodeText(const QString &str,
const bool encodeEOLs = false)
{
QString retval(str);
- int len = retval.length();
+ int len = retval.size();
int i = 0;
while (i < len) {
const QChar ati(retval.at(i));
- if (ati == QLatin1Char('<')) {
- retval.replace(i, 1, QLatin1String("&lt;"));
+ if (ati == u'<') {
+ retval.replace(i, 1, "&lt;"_L1);
len += 3;
i += 4;
- } else if (encodeQuotes && (ati == QLatin1Char('"'))) {
- retval.replace(i, 1, QLatin1String("&quot;"));
+ } else if (encodeQuotes && (ati == u'"')) {
+ retval.replace(i, 1, "&quot;"_L1);
len += 5;
i += 6;
- } else if (ati == QLatin1Char('&')) {
- retval.replace(i, 1, QLatin1String("&amp;"));
+ } else if (ati == u'&') {
+ retval.replace(i, 1, "&amp;"_L1);
len += 4;
i += 5;
- } else if (ati == QLatin1Char('>') && i >= 2 && retval[i - 1] == QLatin1Char(']') && retval[i - 2] == QLatin1Char(']')) {
- retval.replace(i, 1, QLatin1String("&gt;"));
+ } else if (ati == u'>' && i >= 2 && retval[i - 1] == u']' && retval[i - 2] == u']') {
+ retval.replace(i, 1, "&gt;"_L1);
len += 3;
i += 4;
} else if (performAVN &&
(ati == QChar(0xA) ||
ati == QChar(0xD) ||
ati == QChar(0x9))) {
- const QString replacement(QLatin1String("&#x") + QString::number(ati.unicode(), 16) + QLatin1Char(';'));
+ const QString replacement(u"&#x"_s + QString::number(ati.unicode(), 16) + u';');
retval.replace(i, 1, replacement);
- i += replacement.length();
- len += replacement.length() - 1;
+ i += replacement.size();
+ len += replacement.size() - 1;
} else if (encodeEOLs && ati == QChar(0xD)) {
- retval.replace(i, 1, QLatin1String("&#xd;")); // Replace a single 0xD with a ref for 0xD
+ retval.replace(i, 1, "&#xd;"_L1); // Replace a single 0xD with a ref for 0xD
len += 4;
i += 5;
} else {
@@ -3734,7 +3684,7 @@ void QDomAttrPrivate::save(QTextStream& s, int, int) const
*
**************************************************************/
-#define IMPL ((QDomAttrPrivate*)impl)
+#define IMPL static_cast<QDomAttrPrivate *>(impl)
/*!
\class QDomAttr
@@ -3779,14 +3729,14 @@ QDomAttr::QDomAttr()
}
/*!
- Constructs a copy of \a x.
+ Constructs a copy of \a attr.
The data of the copy is shared (shallow copy): modifying one node
will also change the other. If you want to make a deep copy, use
cloneNode().
*/
-QDomAttr::QDomAttr(const QDomAttr& x)
- : QDomNode(x)
+QDomAttr::QDomAttr(const QDomAttr &attr)
+ : QDomNode(attr)
{
}
@@ -3796,16 +3746,13 @@ QDomAttr::QDomAttr(QDomAttrPrivate* n)
}
/*!
- Assigns \a x to this DOM attribute.
+ Assigns \a other to this DOM attribute.
The data of the copy is shared (shallow copy): modifying one node
will also change the other. If you want to make a deep copy, use
cloneNode().
*/
-QDomAttr& QDomAttr::operator= (const QDomAttr& x)
-{
- return (QDomAttr&) QDomNode::operator=(x);
-}
+QDomAttr &QDomAttr::operator=(const QDomAttr &other) = default;
/*!
Returns the attribute's name.
@@ -3840,7 +3787,7 @@ QDomElement QDomAttr::ownerElement() const
Q_ASSERT(impl->parent());
if (!impl->parent()->isElement())
return QDomElement();
- return QDomElement((QDomElementPrivate*)(impl->parent()));
+ return QDomElement(static_cast<QDomElementPrivate *>(impl->parent()));
}
/*!
@@ -3857,15 +3804,15 @@ QString QDomAttr::value() const
}
/*!
- Sets the attribute's value to \a v.
+ Sets the attribute's value to \a value.
\sa value()
*/
-void QDomAttr::setValue(const QString& v)
+void QDomAttr::setValue(const QString &value)
{
if (!impl)
return;
- impl->setNodeValue(v);
+ impl->setNodeValue(value);
IMPL->m_specified = true;
}
@@ -3985,12 +3932,12 @@ void QDomElementPrivate::removeAttribute(const QString& aname)
QDomAttrPrivate* QDomElementPrivate::attributeNode(const QString& aname)
{
- return (QDomAttrPrivate*)m_attr->namedItem(aname);
+ return static_cast<QDomAttrPrivate *>(m_attr->namedItem(aname));
}
QDomAttrPrivate* QDomElementPrivate::attributeNodeNS(const QString& nsURI, const QString& localName)
{
- return (QDomAttrPrivate*)m_attr->namedItemNS(nsURI, localName);
+ return static_cast<QDomAttrPrivate *>(m_attr->namedItemNS(nsURI, localName));
}
QDomAttrPrivate* QDomElementPrivate::setAttributeNode(QDomAttrPrivate* newAttr)
@@ -4002,7 +3949,7 @@ QDomAttrPrivate* QDomElementPrivate::setAttributeNode(QDomAttrPrivate* newAttr)
newAttr->setParent(this);
- return (QDomAttrPrivate*)n;
+ return static_cast<QDomAttrPrivate *>(n);
}
QDomAttrPrivate* QDomElementPrivate::setAttributeNodeNS(QDomAttrPrivate* newAttr)
@@ -4014,12 +3961,12 @@ QDomAttrPrivate* QDomElementPrivate::setAttributeNodeNS(QDomAttrPrivate* newAttr
// Referencing is done by the maps
m_attr->setNamedItem(newAttr);
- return (QDomAttrPrivate*)n;
+ return static_cast<QDomAttrPrivate *>(n);
}
QDomAttrPrivate* QDomElementPrivate::removeAttributeNode(QDomAttrPrivate* oldAttr)
{
- return (QDomAttrPrivate*)m_attr->removeNamedItem(oldAttr->nodeName());
+ return static_cast<QDomAttrPrivate *>(m_attr->removeNamedItem(oldAttr->nodeName()));
}
bool QDomElementPrivate::hasAttribute(const QString& aname)
@@ -4034,14 +3981,14 @@ bool QDomElementPrivate::hasAttributeNS(const QString& nsURI, const QString& loc
QString QDomElementPrivate::text()
{
- QString t(QLatin1String(""));
+ QString t(u""_s);
QDomNodePrivate* p = first;
while (p) {
if (p->isText() || p->isCDATASection())
t += p->nodeValue();
else if (p->isElement())
- t += ((QDomElementPrivate*)p)->text();
+ t += static_cast<QDomElementPrivate *>(p)->text();
p = p->next;
}
@@ -4051,10 +3998,10 @@ QString QDomElementPrivate::text()
void QDomElementPrivate::save(QTextStream& s, int depth, int indent) const
{
if (!(prev && prev->isText()))
- s << QString(indent < 1 ? 0 : depth * indent, QLatin1Char(' '));
+ s << QString(indent < 1 ? 0 : depth * indent, u' ');
QString qName(name);
- QString nsDecl(QLatin1String(""));
+ QString nsDecl(u""_s);
if (!namespaceURI.isNull()) {
/** ###
*
@@ -4067,44 +4014,95 @@ void QDomElementPrivate::save(QTextStream& s, int depth, int indent) const
* hence possibly behavioral changes.
*/
if (prefix.isEmpty()) {
- nsDecl = QLatin1String(" xmlns");
+ nsDecl = u" xmlns"_s;
} else {
- qName = prefix + QLatin1Char(':') + name;
- nsDecl = QLatin1String(" xmlns:") + prefix;
+ qName = prefix + u':' + name;
+ nsDecl = u" xmlns:"_s + prefix;
}
- nsDecl += QLatin1String("=\"") + encodeText(namespaceURI) + QLatin1Char('\"');
+ nsDecl += u"=\""_s + encodeText(namespaceURI) + u'\"';
}
s << '<' << qName << nsDecl;
/* Write out attributes. */
if (!m_attr->map.isEmpty()) {
+ /*
+ * To ensure that we always output attributes in a consistent
+ * order, sort the attributes before writing them into the
+ * stream. (Note that the order may be different than the one
+ * that e.g. we've read from a file, or the program order in
+ * which these attributes have been populated. We just want to
+ * guarantee reproducibile outputs.)
+ */
+ struct SavedAttribute {
+ QString prefix;
+ QString name;
+ QString encodedValue;
+ };
+
+ /* Gather all the attributes to save. */
+ QVarLengthArray<SavedAttribute, 8> attributesToSave;
+ attributesToSave.reserve(m_attr->map.size());
+
QDuplicateTracker<QString> outputtedPrefixes;
- auto it = m_attr->map.constBegin();
- for (; it != m_attr->map.constEnd(); ++it) {
- s << ' ';
- if (it.value()->namespaceURI.isNull()) {
- s << it.value()->name << "=\"" << encodeText(it.value()->value, true, true) << '\"';
- } else {
- s << it.value()->prefix << ':' << it.value()->name << "=\"" << encodeText(it.value()->value, true, true) << '\"';
- /* This is a fix for 138243, as good as it gets.
- *
- * QDomElementPrivate::save() output a namespace declaration if
- * the element is in a namespace, no matter what. This function do as well, meaning
- * that we get two identical namespace declaration if we don't have the if-
- * statement below.
- *
- * This doesn't work when the parent element has the same prefix as us but
- * a different namespace. However, this can only occur by the user modifying the element,
- * and we don't do fixups by that anyway, and hence it's the user responsibility to not
- * arrive in those situations. */
- if ((!it.value()->ownerNode ||
- it.value()->ownerNode->prefix != it.value()->prefix) &&
- !outputtedPrefixes.hasSeen(it.value()->prefix)) {
- s << " xmlns:" << it.value()->prefix << "=\"" << encodeText(it.value()->namespaceURI, true, true) << '\"';
- }
+ for (const auto &[key, value] : std::as_const(m_attr->map).asKeyValueRange()) {
+ Q_UNUSED(key); /* We extract the attribute name from the value. */
+ bool mayNeedXmlNS = false;
+
+ SavedAttribute attr;
+ attr.name = value->name;
+ attr.encodedValue = encodeText(value->value, true, true);
+ if (!value->namespaceURI.isNull()) {
+ attr.prefix = value->prefix;
+ mayNeedXmlNS = true;
+ }
+
+ attributesToSave.push_back(std::move(attr));
+
+ /*
+ * This is a fix for 138243, as good as it gets.
+ *
+ * QDomElementPrivate::save() output a namespace
+ * declaration if the element is in a namespace, no matter
+ * what. This function do as well, meaning that we get two
+ * identical namespace declaration if we don't have the if-
+ * statement below.
+ *
+ * This doesn't work when the parent element has the same
+ * prefix as us but a different namespace. However, this
+ * can only occur by the user modifying the element, and we
+ * don't do fixups by that anyway, and hence it's the user
+ * responsibility to avoid those situations.
+ */
+
+ if (mayNeedXmlNS
+ && ((!value->ownerNode || value->ownerNode->prefix != value->prefix)
+ && !outputtedPrefixes.hasSeen(value->prefix)))
+ {
+ SavedAttribute nsAttr;
+ nsAttr.prefix = QStringLiteral("xmlns");
+ nsAttr.name = value->prefix;
+ nsAttr.encodedValue = encodeText(value->namespaceURI, true, true);
+ attributesToSave.push_back(std::move(nsAttr));
}
}
+
+ /* Sort the attributes by prefix and name. */
+ const auto savedAttributeComparator = [](const SavedAttribute &lhs, const SavedAttribute &rhs)
+ {
+ const int cmp = QString::compare(lhs.prefix, rhs.prefix);
+ return (cmp < 0) || ((cmp == 0) && (lhs.name < rhs.name));
+ };
+
+ std::sort(attributesToSave.begin(), attributesToSave.end(), savedAttributeComparator);
+
+ /* Actually stream the sorted attributes. */
+ for (const auto &attr : attributesToSave) {
+ s << ' ';
+ if (!attr.prefix.isEmpty())
+ s << attr.prefix << ':';
+ s << attr.name << "=\"" << attr.encodedValue << '\"';
+ }
}
if (last) {
@@ -4119,7 +4117,7 @@ void QDomElementPrivate::save(QTextStream& s, int depth, int indent) const
s << Qt::endl;
}
QDomNodePrivate::save(s, depth + 1, indent); if (!last->isText())
- s << QString(indent < 1 ? 0 : depth * indent, QLatin1Char(' '));
+ s << QString(indent < 1 ? 0 : depth * indent, u' ');
s << "</" << qName << '>';
} else {
@@ -4138,7 +4136,7 @@ void QDomElementPrivate::save(QTextStream& s, int depth, int indent) const
*
**************************************************************/
-#define IMPL ((QDomElementPrivate*)impl)
+#define IMPL static_cast<QDomElementPrivate *>(impl)
/*!
\class QDomElement
@@ -4175,7 +4173,7 @@ void QDomElementPrivate::save(QTextStream& s, int depth, int indent) const
n.toText().data() directly on the node, because the node may not
be a text element.
- You can get a list of all the decendents of an element which have
+ You can get a list of all the descendents of an element which have
a specified tag name with elementsByTagName() or
elementsByTagNameNS().
@@ -4202,14 +4200,14 @@ QDomElement::QDomElement()
}
/*!
- Constructs a copy of \a x.
+ Constructs a copy of \a element.
The data of the copy is shared (shallow copy): modifying one node
will also change the other. If you want to make a deep copy, use
cloneNode().
*/
-QDomElement::QDomElement(const QDomElement& x)
- : QDomNode(x)
+QDomElement::QDomElement(const QDomElement &element)
+ : QDomNode(element)
{
}
@@ -4219,16 +4217,13 @@ QDomElement::QDomElement(QDomElementPrivate* n)
}
/*!
- Assigns \a x to this DOM element.
+ Assigns \a other to this DOM element.
The data of the copy is shared (shallow copy): modifying one node
will also change the other. If you want to make a deep copy, use
cloneNode().
*/
-QDomElement& QDomElement::operator= (const QDomElement& x)
-{
- return (QDomElement&) QDomNode::operator=(x);
-}
+QDomElement &QDomElement::operator=(const QDomElement &other) = default;
/*!
\fn QDomNode::NodeType QDomElement::nodeType() const
@@ -4413,7 +4408,7 @@ QDomAttr QDomElement::setAttributeNode(const QDomAttr& newAttr)
{
if (!impl)
return QDomAttr();
- return QDomAttr(IMPL->setAttributeNode(((QDomAttrPrivate*)newAttr.impl)));
+ return QDomAttr(IMPL->setAttributeNode(static_cast<QDomAttrPrivate *>(newAttr.impl)));
}
/*!
@@ -4425,7 +4420,7 @@ QDomAttr QDomElement::removeAttributeNode(const QDomAttr& oldAttr)
{
if (!impl)
return QDomAttr(); // ### should this return oldAttr?
- return QDomAttr(IMPL->removeAttributeNode(((QDomAttrPrivate*)oldAttr.impl)));
+ return QDomAttr(IMPL->removeAttributeNode(static_cast<QDomAttrPrivate *>(oldAttr.impl)));
}
/*!
@@ -4479,7 +4474,7 @@ QString QDomElement::attributeNS(const QString& nsURI, const QString& localName,
Adds an attribute with the qualified name \a qName and the
namespace URI \a nsURI with the value \a value. If an attribute
with the same local name and namespace URI exists, its prefix is
- replaced by the prefix of \a qName and its value is repaced by \a
+ replaced by the prefix of \a qName and its value is replaced by \a
value.
Although \a qName is the qualified name, the local name is used to
@@ -4587,7 +4582,7 @@ QDomAttr QDomElement::setAttributeNodeNS(const QDomAttr& newAttr)
{
if (!impl)
return QDomAttr();
- return QDomAttr(IMPL->setAttributeNodeNS(((QDomAttrPrivate*)newAttr.impl)));
+ return QDomAttr(IMPL->setAttributeNodeNS(static_cast<QDomAttrPrivate *>(newAttr.impl)));
}
/*!
@@ -4648,7 +4643,7 @@ QString QDomElement::text() const
QDomTextPrivate::QDomTextPrivate(QDomDocumentPrivate* d, QDomNodePrivate* parent, const QString& val)
: QDomCharacterDataPrivate(d, parent, val)
{
- name = QLatin1String("#text");
+ name = u"#text"_s;
}
QDomTextPrivate::QDomTextPrivate(QDomTextPrivate* n, bool deep)
@@ -4675,6 +4670,10 @@ QDomTextPrivate* QDomTextPrivate::splitText(int offset)
value.truncate(offset);
parent()->insertAfter(t, this);
+ Q_ASSERT(t->ref.loadRelaxed() == 2);
+
+ // We are not interested in this node
+ t->ref.deref();
return t;
}
@@ -4691,7 +4690,7 @@ void QDomTextPrivate::save(QTextStream& s, int, int) const
*
**************************************************************/
-#define IMPL ((QDomTextPrivate*)impl)
+#define IMPL static_cast<QDomTextPrivate *>(impl)
/*!
\class QDomText
@@ -4702,7 +4701,7 @@ void QDomTextPrivate::save(QTextStream& s, int, int) const
\ingroup xml-tools
You can split the text in a QDomText object over two QDomText
- objecs with splitText().
+ objects with splitText().
For further information about the Document Object Model see
\l{http://www.w3.org/TR/REC-DOM-Level-1/}{Level 1} and
@@ -4722,14 +4721,14 @@ QDomText::QDomText()
}
/*!
- Constructs a copy of \a x.
+ Constructs a copy of \a text.
The data of the copy is shared (shallow copy): modifying one node
will also change the other. If you want to make a deep copy, use
cloneNode().
*/
-QDomText::QDomText(const QDomText& x)
- : QDomCharacterData(x)
+QDomText::QDomText(const QDomText &text)
+ : QDomCharacterData(text)
{
}
@@ -4739,16 +4738,13 @@ QDomText::QDomText(QDomTextPrivate* n)
}
/*!
- Assigns \a x to this DOM text.
+ Assigns \a other to this DOM text.
The data of the copy is shared (shallow copy): modifying one node
will also change the other. If you want to make a deep copy, use
cloneNode().
*/
-QDomText& QDomText::operator= (const QDomText& x)
-{
- return (QDomText&) QDomNode::operator=(x);
-}
+QDomText &QDomText::operator=(const QDomText &other) = default;
/*!
\fn QDomNode::NodeType QDomText::nodeType() const
@@ -4784,7 +4780,7 @@ QDomText QDomText::splitText(int offset)
QDomCommentPrivate::QDomCommentPrivate(QDomDocumentPrivate* d, QDomNodePrivate* parent, const QString& val)
: QDomCharacterDataPrivate(d, parent, val)
{
- name = QLatin1String("#comment");
+ name = u"#comment"_s;
}
QDomCommentPrivate::QDomCommentPrivate(QDomCommentPrivate* n, bool deep)
@@ -4805,10 +4801,10 @@ void QDomCommentPrivate::save(QTextStream& s, int depth, int indent) const
{
/* We don't output whitespace if we would pollute a text node. */
if (!(prev && prev->isText()))
- s << QString(indent < 1 ? 0 : depth * indent, QLatin1Char(' '));
+ s << QString(indent < 1 ? 0 : depth * indent, u' ');
s << "<!--" << value;
- if (value.endsWith(QLatin1Char('-')))
+ if (value.endsWith(u'-'))
s << ' '; // Ensures that XML comment doesn't end with --->
s << "-->";
@@ -4853,14 +4849,14 @@ QDomComment::QDomComment()
}
/*!
- Constructs a copy of \a x.
+ Constructs a copy of \a comment.
The data of the copy is shared (shallow copy): modifying one node
will also change the other. If you want to make a deep copy, use
cloneNode().
*/
-QDomComment::QDomComment(const QDomComment& x)
- : QDomCharacterData(x)
+QDomComment::QDomComment(const QDomComment &comment)
+ : QDomCharacterData(comment)
{
}
@@ -4870,16 +4866,13 @@ QDomComment::QDomComment(QDomCommentPrivate* n)
}
/*!
- Assigns \a x to this DOM comment.
+ Assigns \a other to this DOM comment.
The data of the copy is shared (shallow copy): modifying one node
will also change the other. If you want to make a deep copy, use
cloneNode().
*/
-QDomComment& QDomComment::operator= (const QDomComment& x)
-{
- return (QDomComment&) QDomNode::operator=(x);
-}
+QDomComment &QDomComment::operator=(const QDomComment &other) = default;
/*!
\fn QDomNode::NodeType QDomComment::nodeType() const
@@ -4897,7 +4890,7 @@ QDomCDATASectionPrivate::QDomCDATASectionPrivate(QDomDocumentPrivate* d, QDomNod
const QString& val)
: QDomTextPrivate(d, parent, val)
{
- name = QLatin1String("#cdata-section");
+ name = u"#cdata-section"_s;
}
QDomCDATASectionPrivate::QDomCDATASectionPrivate(QDomCDATASectionPrivate* n, bool deep)
@@ -4961,14 +4954,14 @@ QDomCDATASection::QDomCDATASection()
}
/*!
- Constructs a copy of \a x.
+ Constructs a copy of \a cdataSection.
The data of the copy is shared (shallow copy): modifying one node
will also change the other. If you want to make a deep copy, use
cloneNode().
*/
-QDomCDATASection::QDomCDATASection(const QDomCDATASection& x)
- : QDomText(x)
+QDomCDATASection::QDomCDATASection(const QDomCDATASection &cdataSection)
+ : QDomText(cdataSection)
{
}
@@ -4978,16 +4971,13 @@ QDomCDATASection::QDomCDATASection(QDomCDATASectionPrivate* n)
}
/*!
- Assigns \a x to this CDATA section.
+ Assigns \a other to this CDATA section.
The data of the copy is shared (shallow copy): modifying one node
will also change the other. If you want to make a deep copy, use
cloneNode().
*/
-QDomCDATASection& QDomCDATASection::operator= (const QDomCDATASection& x)
-{
- return (QDomCDATASection&) QDomNode::operator=(x);
-}
+QDomCDATASection &QDomCDATASection::operator=(const QDomCDATASection &other) = default;
/*!
\fn QDomNode::NodeType QDomCDATASection::nodeType() const
@@ -5045,7 +5035,7 @@ void QDomNotationPrivate::save(QTextStream& s, int, int) const
*
**************************************************************/
-#define IMPL ((QDomNotationPrivate*)impl)
+#define IMPL static_cast<QDomNotationPrivate *>(impl)
/*!
\class QDomNotation
@@ -5085,14 +5075,14 @@ QDomNotation::QDomNotation()
}
/*!
- Constructs a copy of \a x.
+ Constructs a copy of \a notation.
The data of the copy is shared (shallow copy): modifying one node
will also change the other. If you want to make a deep copy, use
cloneNode().
*/
-QDomNotation::QDomNotation(const QDomNotation& x)
- : QDomNode(x)
+QDomNotation::QDomNotation(const QDomNotation &notation)
+ : QDomNode(notation)
{
}
@@ -5102,16 +5092,13 @@ QDomNotation::QDomNotation(QDomNotationPrivate* n)
}
/*!
- Assigns \a x to this DOM notation.
+ Assigns \a other to this DOM notation.
The data of the copy is shared (shallow copy): modifying one node
will also change the other. If you want to make a deep copy, use
cloneNode().
*/
-QDomNotation& QDomNotation::operator= (const QDomNotation& x)
-{
- return (QDomNotation&) QDomNode::operator=(x);
-}
+QDomNotation &QDomNotation::operator=(const QDomNotation &other) = default;
/*!
\fn QDomNode::NodeType QDomNotation::nodeType() const
@@ -5213,8 +5200,8 @@ static QByteArray encodeEntity(const QByteArray& str)
void QDomEntityPrivate::save(QTextStream& s, int, int) const
{
QString _name = name;
- if (_name.startsWith(QLatin1Char('%')))
- _name = QLatin1String("% ") + _name.mid(1);
+ if (_name.startsWith(u'%'))
+ _name = u"% "_s + _name.mid(1);
if (m_sys.isNull() && m_pub.isNull()) {
s << "<!ENTITY " << _name << " \"" << encodeEntity(value.toUtf8()) << "\">" << Qt::endl;
@@ -5238,7 +5225,7 @@ void QDomEntityPrivate::save(QTextStream& s, int, int) const
*
**************************************************************/
-#define IMPL ((QDomEntityPrivate*)impl)
+#define IMPL static_cast<QDomEntityPrivate *>(impl)
/*!
\class QDomEntity
@@ -5282,14 +5269,14 @@ QDomEntity::QDomEntity()
/*!
- Constructs a copy of \a x.
+ Constructs a copy of \a entity.
The data of the copy is shared (shallow copy): modifying one node
will also change the other. If you want to make a deep copy, use
cloneNode().
*/
-QDomEntity::QDomEntity(const QDomEntity& x)
- : QDomNode(x)
+QDomEntity::QDomEntity(const QDomEntity &entity)
+ : QDomNode(entity)
{
}
@@ -5299,16 +5286,13 @@ QDomEntity::QDomEntity(QDomEntityPrivate* n)
}
/*!
- Assigns \a x to this DOM entity.
+ Assigns \a other to this DOM entity.
The data of the copy is shared (shallow copy): modifying one node
will also change the other. If you want to make a deep copy, use
cloneNode().
*/
-QDomEntity& QDomEntity::operator= (const QDomEntity& x)
-{
- return (QDomEntity&) QDomNode::operator=(x);
-}
+QDomEntity &QDomEntity::operator=(const QDomEntity &other) = default;
/*!
\fn QDomNode::NodeType QDomEntity::nodeType() const
@@ -5434,14 +5418,14 @@ QDomEntityReference::QDomEntityReference()
}
/*!
- Constructs a copy of \a x.
+ Constructs a copy of \a entityReference.
The data of the copy is shared (shallow copy): modifying one node
will also change the other. If you want to make a deep copy, use
cloneNode().
*/
-QDomEntityReference::QDomEntityReference(const QDomEntityReference& x)
- : QDomNode(x)
+QDomEntityReference::QDomEntityReference(const QDomEntityReference &entityReference)
+ : QDomNode(entityReference)
{
}
@@ -5451,16 +5435,13 @@ QDomEntityReference::QDomEntityReference(QDomEntityReferencePrivate* n)
}
/*!
- Assigns \a x to this entity reference.
+ Assigns \a other to this entity reference.
The data of the copy is shared (shallow copy): modifying one node
will also change the other. If you want to make a deep copy, use
cloneNode().
*/
-QDomEntityReference& QDomEntityReference::operator= (const QDomEntityReference& x)
-{
- return (QDomEntityReference&) QDomNode::operator=(x);
-}
+QDomEntityReference &QDomEntityReference::operator=(const QDomEntityReference &other) = default;
/*!
\fn QDomNode::NodeType QDomEntityReference::nodeType() const
@@ -5551,14 +5532,14 @@ QDomProcessingInstruction::QDomProcessingInstruction()
}
/*!
- Constructs a copy of \a x.
+ Constructs a copy of \a processingInstruction.
The data of the copy is shared (shallow copy): modifying one node
will also change the other. If you want to make a deep copy, use
cloneNode().
*/
-QDomProcessingInstruction::QDomProcessingInstruction(const QDomProcessingInstruction& x)
- : QDomNode(x)
+QDomProcessingInstruction::QDomProcessingInstruction(const QDomProcessingInstruction &processingInstruction)
+ : QDomNode(processingInstruction)
{
}
@@ -5568,16 +5549,14 @@ QDomProcessingInstruction::QDomProcessingInstruction(QDomProcessingInstructionPr
}
/*!
- Assigns \a x to this processing instruction.
+ Assigns \a other to this processing instruction.
The data of the copy is shared (shallow copy): modifying one node
will also change the other. If you want to make a deep copy, use
cloneNode().
*/
-QDomProcessingInstruction& QDomProcessingInstruction::operator= (const QDomProcessingInstruction& x)
-{
- return (QDomProcessingInstruction&) QDomNode::operator=(x);
-}
+QDomProcessingInstruction &
+QDomProcessingInstruction::operator=(const QDomProcessingInstruction &other) = default;
/*!
\fn QDomNode::NodeType QDomProcessingInstruction::nodeType() const
@@ -5610,15 +5589,14 @@ QString QDomProcessingInstruction::data() const
}
/*!
- Sets the data contained in the processing instruction to \a d.
+ Sets the data contained in the processing instruction to \a data.
\sa data()
*/
-void QDomProcessingInstruction::setData(const QString& d)
+void QDomProcessingInstruction::setData(const QString &data)
{
- if (!impl)
- return;
- impl->setNodeValue(d);
+ if (impl)
+ impl->setNodeValue(data);
}
/**************************************************************
@@ -5635,7 +5613,7 @@ QDomDocumentPrivate::QDomDocumentPrivate()
type = new QDomDocumentTypePrivate(this, this);
type->ref.deref();
- name = QLatin1String("#document");
+ name = u"#document"_s;
}
QDomDocumentPrivate::QDomDocumentPrivate(const QString& aname)
@@ -5647,7 +5625,7 @@ QDomDocumentPrivate::QDomDocumentPrivate(const QString& aname)
type->ref.deref();
type->name = aname;
- name = QLatin1String("#document");
+ name = u"#document"_s;
}
QDomDocumentPrivate::QDomDocumentPrivate(QDomDocumentTypePrivate* dt)
@@ -5662,7 +5640,7 @@ QDomDocumentPrivate::QDomDocumentPrivate(QDomDocumentTypePrivate* dt)
type->ref.deref();
}
- name = QLatin1String("#document");
+ name = u"#document"_s;
}
QDomDocumentPrivate::QDomDocumentPrivate(QDomDocumentPrivate* n, bool deep)
@@ -5685,8 +5663,8 @@ void QDomDocumentPrivate::clear()
QDomNodePrivate::clear();
}
-bool QDomDocumentPrivate::setContent(QXmlStreamReader *reader, bool namespaceProcessing,
- QString *errorMsg, int *errorLine, int *errorColumn)
+QDomDocument::ParseResult QDomDocumentPrivate::setContent(QXmlStreamReader *reader,
+ QDomDocument::ParseOptions options)
{
clear();
impl = new QDomImplementationPrivate;
@@ -5694,23 +5672,16 @@ bool QDomDocumentPrivate::setContent(QXmlStreamReader *reader, bool namespacePro
type->ref.deref();
if (!reader) {
- qWarning("Failed to set content, XML reader is not initialized");
- return false;
+ const auto error = u"Failed to set content, XML reader is not initialized"_s;
+ qWarning("%s", qPrintable(error));
+ return { error };
}
- QDomParser domParser(this, reader, namespaceProcessing);
-
- if (!domParser.parse()) {
- if (errorMsg)
- *errorMsg = std::get<0>(domParser.errorInfo());
- if (errorLine)
- *errorLine = std::get<1>(domParser.errorInfo());
- if (errorColumn)
- *errorColumn = std::get<2>(domParser.errorInfo());
- return false;
- }
+ QDomParser domParser(this, reader, options);
- return true;
+ if (!domParser.parse())
+ return domParser.result();
+ return {};
}
QDomNodePrivate* QDomDocumentPrivate::cloneNode(bool deep)
@@ -5756,7 +5727,7 @@ QDomElementPrivate* QDomDocumentPrivate::createElementNS(const QString &nsURI, c
QDomDocumentFragmentPrivate* QDomDocumentPrivate::createDocumentFragment()
{
- QDomDocumentFragmentPrivate *f = new QDomDocumentFragmentPrivate(this, (QDomNodePrivate*)nullptr);
+ QDomDocumentFragmentPrivate *f = new QDomDocumentFragmentPrivate(this, nullptr);
f->ref.deref();
return f;
}
@@ -5854,34 +5825,38 @@ QDomNodePrivate* QDomDocumentPrivate::importNode(QDomNodePrivate *importedNode,
QDomNodePrivate *node = nullptr;
switch (importedNode->nodeType()) {
case QDomNode::AttributeNode:
- node = new QDomAttrPrivate((QDomAttrPrivate*)importedNode, true);
+ node = new QDomAttrPrivate(static_cast<QDomAttrPrivate *>(importedNode), true);
break;
case QDomNode::DocumentFragmentNode:
- node = new QDomDocumentFragmentPrivate((QDomDocumentFragmentPrivate*)importedNode, deep);
+ node = new QDomDocumentFragmentPrivate(
+ static_cast<QDomDocumentFragmentPrivate *>(importedNode), deep);
break;
case QDomNode::ElementNode:
- node = new QDomElementPrivate((QDomElementPrivate*)importedNode, deep);
+ node = new QDomElementPrivate(static_cast<QDomElementPrivate *>(importedNode), deep);
break;
case QDomNode::EntityNode:
- node = new QDomEntityPrivate((QDomEntityPrivate*)importedNode, deep);
+ node = new QDomEntityPrivate(static_cast<QDomEntityPrivate *>(importedNode), deep);
break;
case QDomNode::EntityReferenceNode:
- node = new QDomEntityReferencePrivate((QDomEntityReferencePrivate*)importedNode, false);
+ node = new QDomEntityReferencePrivate(
+ static_cast<QDomEntityReferencePrivate *>(importedNode), false);
break;
case QDomNode::NotationNode:
- node = new QDomNotationPrivate((QDomNotationPrivate*)importedNode, deep);
+ node = new QDomNotationPrivate(static_cast<QDomNotationPrivate *>(importedNode), deep);
break;
case QDomNode::ProcessingInstructionNode:
- node = new QDomProcessingInstructionPrivate((QDomProcessingInstructionPrivate*)importedNode, deep);
+ node = new QDomProcessingInstructionPrivate(
+ static_cast<QDomProcessingInstructionPrivate *>(importedNode), deep);
break;
case QDomNode::TextNode:
- node = new QDomTextPrivate((QDomTextPrivate*)importedNode, deep);
+ node = new QDomTextPrivate(static_cast<QDomTextPrivate *>(importedNode), deep);
break;
case QDomNode::CDATASectionNode:
- node = new QDomCDATASectionPrivate((QDomCDATASectionPrivate*)importedNode, deep);
+ node = new QDomCDATASectionPrivate(static_cast<QDomCDATASectionPrivate *>(importedNode),
+ deep);
break;
case QDomNode::CommentNode:
- node = new QDomCommentPrivate((QDomCommentPrivate*)importedNode, deep);
+ node = new QDomCommentPrivate(static_cast<QDomCommentPrivate *>(importedNode), deep);
break;
default:
break;
@@ -5903,7 +5878,7 @@ void QDomDocumentPrivate::saveDocument(QTextStream& s, const int indent, QDomNod
#if QT_CONFIG(regularexpression)
const QDomNodePrivate* n = first;
- if (n && n->isProcessingInstruction() && n->nodeName() == QLatin1String("xml")) {
+ if (n && n->isProcessingInstruction() && n->nodeName() == "xml"_L1) {
// we have an XML declaration
QString data = n->nodeValue();
QRegularExpression encoding(QString::fromLatin1("encoding\\s*=\\s*((\"([^\"]*)\")|('([^']*)'))"));
@@ -5923,7 +5898,7 @@ void QDomDocumentPrivate::saveDocument(QTextStream& s, const int indent, QDomNod
bool doc = false;
while (n) {
- if (!doc && !(n->isProcessingInstruction() && n->nodeName() == QLatin1String("xml"))) {
+ if (!doc && !(n->isProcessingInstruction() && n->nodeName() == "xml"_L1)) {
// save doctype after XML declaration
type->save(s, 0, indent);
doc = true;
@@ -5946,7 +5921,7 @@ void QDomDocumentPrivate::saveDocument(QTextStream& s, const int indent, QDomNod
// First, we try to find the PI and sets the startNode to the one appearing after it.
while (n) {
- if (n->isProcessingInstruction() && n->nodeName() == QLatin1String("xml")) {
+ if (n->isProcessingInstruction() && n->nodeName() == "xml"_L1) {
startNode = n->next;
break;
}
@@ -5968,7 +5943,7 @@ void QDomDocumentPrivate::saveDocument(QTextStream& s, const int indent, QDomNod
*
**************************************************************/
-#define IMPL ((QDomDocumentPrivate*)impl)
+#define IMPL static_cast<QDomDocumentPrivate *>(impl)
/*!
\class QDomDocument
@@ -6019,8 +5994,8 @@ void QDomDocumentPrivate::saveDocument(QTextStream& s, const int indent, QDomNod
representation of the document can be obtained using toString().
\note The DOM tree might end up reserving a lot of memory if the XML
- document is big. For such documents, the QXmlStreamReader or the
- QXmlQuery classes might be better solutions.
+ document is big. For such documents, the QXmlStreamReader class
+ might be a better solution.
It is possible to insert a node from another document into the
document using importNode().
@@ -6045,10 +6020,9 @@ void QDomDocumentPrivate::saveDocument(QTextStream& s, const int indent, QDomNod
\l{http://www.w3.org/TR/DOM-Level-2-Core/}{Level 2 Core}
Specifications.
- \sa {DOM Bookmarks Example}, {Simple DOM Model Example}
+ \sa {DOM Bookmarks Application}
*/
-
/*!
Constructs an empty document.
*/
@@ -6074,37 +6048,34 @@ QDomDocument::QDomDocument(const QString& name)
*/
QDomDocument::QDomDocument(const QDomDocumentType& doctype)
{
- impl = new QDomDocumentPrivate((QDomDocumentTypePrivate*)(doctype.impl));
+ impl = new QDomDocumentPrivate(static_cast<QDomDocumentTypePrivate *>(doctype.impl));
}
/*!
- Constructs a copy of \a x.
+ Constructs a copy of \a document.
The data of the copy is shared (shallow copy): modifying one node
will also change the other. If you want to make a deep copy, use
cloneNode().
*/
-QDomDocument::QDomDocument(const QDomDocument& x)
- : QDomNode(x)
+QDomDocument::QDomDocument(const QDomDocument &document)
+ : QDomNode(document)
{
}
-QDomDocument::QDomDocument(QDomDocumentPrivate* x)
- : QDomNode(x)
+QDomDocument::QDomDocument(QDomDocumentPrivate *pimpl)
+ : QDomNode(pimpl)
{
}
/*!
- Assigns \a x to this DOM document.
+ Assigns \a other to this DOM document.
The data of the copy is shared (shallow copy): modifying one node
will also change the other. If you want to make a deep copy, use
cloneNode().
*/
-QDomDocument& QDomDocument::operator= (const QDomDocument& x)
-{
- return (QDomDocument&) QDomNode::operator=(x);
-}
+QDomDocument &QDomDocument::operator=(const QDomDocument &other) = default;
/*!
Destroys the object and frees its resources.
@@ -6113,25 +6084,30 @@ QDomDocument::~QDomDocument()
{
}
+#if QT_DEPRECATED_SINCE(6, 8)
+QT_WARNING_PUSH
+QT_WARNING_DISABLE_DEPRECATED
/*!
\overload
+ \deprecated [6.8] Use the overloads taking ParseOptions instead.
This function reads the XML document from the string \a text, returning
true if the content was successfully parsed; otherwise returns \c false.
Since \a text is already a Unicode string, no encoding detection
is done.
*/
-bool QDomDocument::setContent(const QString& text, bool namespaceProcessing, QString *errorMsg, int *errorLine, int *errorColumn)
+bool QDomDocument::setContent(const QString& text, bool namespaceProcessing,
+ QString *errorMsg, int *errorLine, int *errorColumn)
{
- if (!impl)
- impl = new QDomDocumentPrivate();
-
- QXmlStreamReader streamReader(text);
- streamReader.setNamespaceProcessing(namespaceProcessing);
- return IMPL->setContent(&streamReader, namespaceProcessing, errorMsg, errorLine, errorColumn);
+ QXmlStreamReader reader(text);
+ reader.setNamespaceProcessing(namespaceProcessing);
+ return setContent(&reader, namespaceProcessing, errorMsg, errorLine, errorColumn);
}
/*!
+ \deprecated [6.8] Use the overload taking ParseOptions instead.
+ \overload
+
This function parses the XML document from the byte array \a
data and sets it as the content of the document. It tries to
detect the encoding of the document as required by the XML
@@ -6146,26 +6122,21 @@ bool QDomDocument::setContent(const QString& text, bool namespaceProcessing, QSt
If a parse error occurs, this function returns \c false and the error
message is placed in \c{*}\a{errorMsg}, the line number in
\c{*}\a{errorLine} and the column number in \c{*}\a{errorColumn}
- (unless the associated pointer is set to 0); otherwise this
- function returns \c true. The various error messages are described in
- the QXmlParseException class documentation. Note that, if you
- want to display these error messages to your application's users,
- they will be displayed in English unless they are explicitly
- translated.
+ (unless the associated pointer is set to \c nullptr); otherwise this
+ function returns \c true.
If \a namespaceProcessing is true, the function QDomNode::prefix()
returns a string for all elements and attributes. It returns an
empty string if the element or attribute has no prefix.
Text nodes consisting only of whitespace are stripped and won't
- appear in the QDomDocument. If this behavior is not desired,
- one can use the setContent() overload that allows a QXmlReader to be
- supplied.
+ appear in the QDomDocument.
If \a namespaceProcessing is false, the functions
QDomNode::prefix(), QDomNode::localName() and
QDomNode::namespaceURI() return an empty string.
+//! [entity-refs]
Entity references are handled as follows:
\list
\li References to internal general entities and character entities occurring in the
@@ -6180,38 +6151,61 @@ bool QDomDocument::setContent(const QString& text, bool namespaceProcessing, QSt
occurs outside of the content is replaced with an empty string.
\li Any unparsed entity reference is replaced with an empty string.
\endlist
+//! [entity-refs]
\sa QDomNode::namespaceURI(), QDomNode::localName(),
QDomNode::prefix(), QString::isNull(), QString::isEmpty()
*/
-bool QDomDocument::setContent(const QByteArray &data, bool namespaceProcessing, QString *errorMsg, int *errorLine, int *errorColumn)
+bool QDomDocument::setContent(const QByteArray &data, bool namespaceProcessing,
+ QString *errorMsg, int *errorLine, int *errorColumn)
{
- if (!impl)
- impl = new QDomDocumentPrivate();
+ QXmlStreamReader reader(data);
+ reader.setNamespaceProcessing(namespaceProcessing);
+ return setContent(&reader, namespaceProcessing, errorMsg, errorLine, errorColumn);
+}
+
+static inline QDomDocument::ParseOptions toParseOptions(bool namespaceProcessing)
+{
+ return namespaceProcessing ? QDomDocument::ParseOption::UseNamespaceProcessing
+ : QDomDocument::ParseOption::Default;
+}
- QXmlStreamReader streamReader(data);
- streamReader.setNamespaceProcessing(namespaceProcessing);
- return IMPL->setContent(&streamReader, namespaceProcessing, errorMsg, errorLine, errorColumn);
+static inline void unpackParseResult(const QDomDocument::ParseResult &parseResult,
+ QString *errorMsg, int *errorLine, int *errorColumn)
+{
+ if (!parseResult) {
+ if (errorMsg)
+ *errorMsg = parseResult.errorMessage;
+ if (errorLine)
+ *errorLine = static_cast<int>(parseResult.errorLine);
+ if (errorColumn)
+ *errorColumn = static_cast<int>(parseResult.errorColumn);
+ }
}
/*!
\overload
+ \deprecated [6.8] Use the overload taking ParseOptions instead.
This function reads the XML document from the IO device \a dev, returning
true if the content was successfully parsed; otherwise returns \c false.
+
+ \note This method will try to open \a dev in read-only mode if it is not
+ already open. In that case, the caller is responsible for calling close.
+ This will change in Qt 7, which will no longer open \a dev. Applications
+ should therefore open the device themselves before calling setContent.
*/
-bool QDomDocument::setContent(QIODevice* dev, bool namespaceProcessing, QString *errorMsg, int *errorLine, int *errorColumn)
+bool QDomDocument::setContent(QIODevice* dev, bool namespaceProcessing,
+ QString *errorMsg, int *errorLine, int *errorColumn)
{
- if (!impl)
- impl = new QDomDocumentPrivate();
-
- QXmlStreamReader streamReader(dev);
- streamReader.setNamespaceProcessing(namespaceProcessing);
- return IMPL->setContent(&streamReader, namespaceProcessing, errorMsg, errorLine, errorColumn);
+ ParseResult result = setContent(dev, toParseOptions(namespaceProcessing));
+ unpackParseResult(result, errorMsg, errorLine, errorColumn);
+ return bool(result);
}
/*!
\overload
+ \deprecated [6.8] Use the overload returning ParseResult instead.
This function reads the XML document from the string \a text, returning
true if the content was successfully parsed; otherwise returns \c false.
@@ -6227,6 +6221,7 @@ bool QDomDocument::setContent(const QString& text, QString *errorMsg, int *error
/*!
\overload
+ \deprecated [6.8] Use the overload returning ParseResult instead.
This function reads the XML document from the byte array \a buffer,
returning true if the content was successfully parsed; otherwise returns
@@ -6241,7 +6236,7 @@ bool QDomDocument::setContent(const QByteArray& buffer, QString *errorMsg, int *
/*!
\overload
- \obsolete
+ \deprecated [6.8] Use the overload returning ParseResult instead.
This function reads the XML document from the IO device \a dev, returning
true if the content was successfully parsed; otherwise returns \c false.
@@ -6256,6 +6251,7 @@ bool QDomDocument::setContent(QIODevice* dev, QString *errorMsg, int *errorLine,
/*!
\overload
\since 5.15
+ \deprecated [6.8] Use the overload taking ParseOptions instead.
This function reads the XML document from the QXmlStreamReader \a reader
and parses it. Returns \c true if the content was successfully parsed;
@@ -6268,16 +6264,169 @@ bool QDomDocument::setContent(QIODevice* dev, QString *errorMsg, int *errorLine,
If a parse error occurs, the error message is placed in \c{*}\a{errorMsg}, the line
number in \c{*}\a{errorLine} and the column number in \c{*}\a{errorColumn} (unless
- the associated pointer is set to 0).
+ the associated pointer is set to \c nullptr).
\sa QXmlStreamReader
*/
-bool QDomDocument::setContent(QXmlStreamReader *reader, bool namespaceProcessing, QString *errorMsg,
- int *errorLine, int *errorColumn)
+bool QDomDocument::setContent(QXmlStreamReader *reader, bool namespaceProcessing,
+ QString *errorMsg, int *errorLine, int *errorColumn)
+{
+ ParseResult result = setContent(reader, toParseOptions(namespaceProcessing));
+ unpackParseResult(result, errorMsg, errorLine, errorColumn);
+ return bool(result);
+}
+QT_WARNING_POP
+#endif // QT_DEPRECATED_SINCE(6, 8)
+
+/*!
+ \enum QDomDocument::ParseOption
+ \since 6.5
+
+ This enum describes the possible options that can be used when
+ parsing an XML document using the setContent() method.
+
+ \value Default No parse options are set.
+ \value UseNamespaceProcessing Namespace processing is enabled.
+ \value PreserveSpacingOnlyNodes Text nodes containing only spacing
+ characters are preserved.
+
+ \sa setContent()
+*/
+
+/*!
+ \struct QDomDocument::ParseResult
+ \since 6.5
+ \inmodule QtXml
+ \ingroup xml-tools
+ \brief The struct is used to store the result of QDomDocument::setContent().
+
+ The QDomDocument::ParseResult struct is used for storing the result of
+ QDomDocument::setContent(). If an error is found while parsing an XML
+ document, the message, line and column number of an error are stored in
+ \c ParseResult.
+
+ \sa QDomDocument::setContent()
+*/
+
+/*!
+ \variable QDomDocument::ParseResult::errorMessage
+
+ The field contains the text message of an error found by
+ QDomDocument::setContent() while parsing an XML document.
+
+ \sa QDomDocument::setContent()
+*/
+
+/*!
+ \variable QDomDocument::ParseResult::errorLine
+
+ The field contains the line number of an error found by
+ QDomDocument::setContent() while parsing an XML document.
+
+ \sa QDomDocument::setContent()
+*/
+
+/*!
+ \variable QDomDocument::ParseResult::errorColumn
+
+ The field contains the column number of an error found by
+ QDomDocument::setContent() while parsing an XML document.
+
+ \sa QDomDocument::setContent()
+*/
+
+/*!
+ \fn QDomDocument::ParseResult::operator bool() const
+
+ Returns \c false if any error is found by QDomDocument::setContent();
+ otherwise returns \c true.
+
+ \sa QDomDocument::setContent()
+*/
+
+/*!
+ \fn ParseResult QDomDocument::setContent(const QByteArray &data, ParseOptions options)
+ \fn ParseResult QDomDocument::setContent(QAnyStringView text, ParseOptions options)
+ \fn ParseResult QDomDocument::setContent(QIODevice *device, ParseOptions options)
+ \fn ParseResult QDomDocument::setContent(QXmlStreamReader *reader, ParseOptions options)
+
+ \since 6.5
+
+ This function parses the XML document from the byte array \a
+ data, string view \a text, IO \a device, or stream \a reader
+ and sets it as the content of the document. It tries to
+ detect the encoding of the document, in accordance with the
+ XML specification. Returns the result of parsing in ParseResult,
+ which explicitly converts to \c bool.
+
+ You can use the \a options parameter to specify different parsing
+ options, for example, to enable namespace processing, etc.
+
+ By default, namespace processing is disabled. If it's disabled, the
+ parser does no namespace processing when it reads the XML file. The
+ functions QDomNode::prefix(), QDomNode::localName() and
+ QDomNode::namespaceURI() return an empty string.
+
+ If namespace processing is enabled via the parse \a options, the parser
+ recognizes namespaces in the XML file and sets the prefix name, local
+ name and namespace URI to appropriate values. The functions
+ QDomNode::prefix(), QDomNode::localName() and QDomNode::namespaceURI()
+ return a string for all elements and attributes and return an empty
+ string if the element or attribute has no prefix.
+
+ Text nodes consisting only of whitespace are stripped and won't
+ appear in the QDomDocument. Since Qt 6.5, one can pass
+ QDomDocument::ParseOption::PreserveSpacingOnlyNodes as a parse
+ option, to specify that spacing-only text nodes must be preserved.
+
+ \include qdom.cpp entity-refs
+
+ \note The overload taking IO \a device will try to open it in read-only
+ mode if it is not already open. In that case, the caller is responsible
+ for calling close. This will change in Qt 7, which will no longer open
+ the IO \a device. Applications should therefore open the device themselves
+ before calling setContent().
+
+ \sa ParseResult, ParseOptions
+*/
+QDomDocument::ParseResult QDomDocument::setContentImpl(const QByteArray &data, ParseOptions options)
+{
+ QXmlStreamReader reader(data);
+ reader.setNamespaceProcessing(options.testFlag(ParseOption::UseNamespaceProcessing));
+ return setContent(&reader, options);
+}
+
+QDomDocument::ParseResult QDomDocument::setContent(QAnyStringView data, ParseOptions options)
+{
+ QXmlStreamReader reader(data);
+ reader.setNamespaceProcessing(options.testFlag(ParseOption::UseNamespaceProcessing));
+ return setContent(&reader, options);
+}
+
+QDomDocument::ParseResult QDomDocument::setContent(QIODevice *device, ParseOptions options)
+{
+#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
+ if (!device->isOpen()) {
+ qWarning("QDomDocument called with unopened QIODevice. "
+ "This will not be supported in future Qt versions.");
+ if (!device->open(QIODevice::ReadOnly)) {
+ const auto error = u"QDomDocument::setContent: Failed to open device."_s;
+ qWarning("%s", qPrintable(error));
+ return { error };
+ }
+ }
+#endif
+
+ QXmlStreamReader reader(device);
+ reader.setNamespaceProcessing(options.testFlag(ParseOption::UseNamespaceProcessing));
+ return setContent(&reader, options);
+}
+
+QDomDocument::ParseResult QDomDocument::setContent(QXmlStreamReader *reader, ParseOptions options)
{
if (!impl)
impl = new QDomDocumentPrivate();
- return IMPL->setContent(reader, namespaceProcessing, errorMsg, errorLine, errorColumn);
+ return IMPL->setContent(reader, options);
}
/*!
@@ -6656,7 +6805,7 @@ QDomElement QDomDocument::elementById(const QString& /*elementId*/)
QDomAttr QDomNode::toAttr() const
{
if (impl && impl->isAttr())
- return QDomAttr(((QDomAttrPrivate*)impl));
+ return QDomAttr(static_cast<QDomAttrPrivate *>(impl));
return QDomAttr();
}
@@ -6669,7 +6818,7 @@ QDomAttr QDomNode::toAttr() const
QDomCDATASection QDomNode::toCDATASection() const
{
if (impl && impl->isCDATASection())
- return QDomCDATASection(((QDomCDATASectionPrivate*)impl));
+ return QDomCDATASection(static_cast<QDomCDATASectionPrivate *>(impl));
return QDomCDATASection();
}
@@ -6682,7 +6831,7 @@ QDomCDATASection QDomNode::toCDATASection() const
QDomDocumentFragment QDomNode::toDocumentFragment() const
{
if (impl && impl->isDocumentFragment())
- return QDomDocumentFragment(((QDomDocumentFragmentPrivate*)impl));
+ return QDomDocumentFragment(static_cast<QDomDocumentFragmentPrivate *>(impl));
return QDomDocumentFragment();
}
@@ -6695,7 +6844,7 @@ QDomDocumentFragment QDomNode::toDocumentFragment() const
QDomDocument QDomNode::toDocument() const
{
if (impl && impl->isDocument())
- return QDomDocument(((QDomDocumentPrivate*)impl));
+ return QDomDocument(static_cast<QDomDocumentPrivate *>(impl));
return QDomDocument();
}
@@ -6708,7 +6857,7 @@ QDomDocument QDomNode::toDocument() const
QDomDocumentType QDomNode::toDocumentType() const
{
if (impl && impl->isDocumentType())
- return QDomDocumentType(((QDomDocumentTypePrivate*)impl));
+ return QDomDocumentType(static_cast<QDomDocumentTypePrivate *>(impl));
return QDomDocumentType();
}
@@ -6721,7 +6870,7 @@ QDomDocumentType QDomNode::toDocumentType() const
QDomElement QDomNode::toElement() const
{
if (impl && impl->isElement())
- return QDomElement(((QDomElementPrivate*)impl));
+ return QDomElement(static_cast<QDomElementPrivate *>(impl));
return QDomElement();
}
@@ -6734,7 +6883,7 @@ QDomElement QDomNode::toElement() const
QDomEntityReference QDomNode::toEntityReference() const
{
if (impl && impl->isEntityReference())
- return QDomEntityReference(((QDomEntityReferencePrivate*)impl));
+ return QDomEntityReference(static_cast<QDomEntityReferencePrivate *>(impl));
return QDomEntityReference();
}
@@ -6747,7 +6896,7 @@ QDomEntityReference QDomNode::toEntityReference() const
QDomText QDomNode::toText() const
{
if (impl && impl->isText())
- return QDomText(((QDomTextPrivate*)impl));
+ return QDomText(static_cast<QDomTextPrivate *>(impl));
return QDomText();
}
@@ -6760,7 +6909,7 @@ QDomText QDomNode::toText() const
QDomEntity QDomNode::toEntity() const
{
if (impl && impl->isEntity())
- return QDomEntity(((QDomEntityPrivate*)impl));
+ return QDomEntity(static_cast<QDomEntityPrivate *>(impl));
return QDomEntity();
}
@@ -6773,7 +6922,7 @@ QDomEntity QDomNode::toEntity() const
QDomNotation QDomNode::toNotation() const
{
if (impl && impl->isNotation())
- return QDomNotation(((QDomNotationPrivate*)impl));
+ return QDomNotation(static_cast<QDomNotationPrivate *>(impl));
return QDomNotation();
}
@@ -6786,7 +6935,7 @@ QDomNotation QDomNode::toNotation() const
QDomProcessingInstruction QDomNode::toProcessingInstruction() const
{
if (impl && impl->isProcessingInstruction())
- return QDomProcessingInstruction(((QDomProcessingInstructionPrivate*)impl));
+ return QDomProcessingInstruction(static_cast<QDomProcessingInstructionPrivate *>(impl));
return QDomProcessingInstruction();
}
@@ -6799,7 +6948,7 @@ QDomProcessingInstruction QDomNode::toProcessingInstruction() const
QDomCharacterData QDomNode::toCharacterData() const
{
if (impl && impl->isCharacterData())
- return QDomCharacterData(((QDomCharacterDataPrivate*)impl));
+ return QDomCharacterData(static_cast<QDomCharacterDataPrivate *>(impl));
return QDomCharacterData();
}
@@ -6812,10 +6961,16 @@ QDomCharacterData QDomNode::toCharacterData() const
QDomComment QDomNode::toComment() const
{
if (impl && impl->isComment())
- return QDomComment(((QDomCommentPrivate*)impl));
+ return QDomComment(static_cast<QDomCommentPrivate *>(impl));
return QDomComment();
}
+/*!
+ \variable QDomNode::impl
+ \internal
+ Pointer to private data structure.
+*/
+
QT_END_NAMESPACE
#endif // QT_NO_DOM
diff --git a/src/xml/dom/qdom.h b/src/xml/dom/qdom.h
index 779e05805c..a3900609c4 100644
--- a/src/xml/dom/qdom.h
+++ b/src/xml/dom/qdom.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtXml module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QDOM_H
#define QDOM_H
@@ -43,6 +7,8 @@
#include <QtXml/qtxmlglobal.h>
#include <QtCore/qstring.h>
+class tst_QDom;
+
QT_BEGIN_NAMESPACE
@@ -51,9 +17,6 @@ QT_BEGIN_NAMESPACE
class QIODevice;
class QTextStream;
-class QXmlInputSource;
-class QXmlReader;
-
class QDomDocumentPrivate;
class QDomDocumentTypePrivate;
class QDomDocumentFragmentPrivate;
@@ -97,11 +60,11 @@ class Q_XML_EXPORT QDomImplementation
{
public:
QDomImplementation();
- QDomImplementation(const QDomImplementation&);
+ QDomImplementation(const QDomImplementation &implementation);
~QDomImplementation();
- QDomImplementation& operator= (const QDomImplementation&);
- bool operator== (const QDomImplementation&) const;
- bool operator!= (const QDomImplementation&) const;
+ QDomImplementation& operator=(const QDomImplementation &other);
+ bool operator==(const QDomImplementation &other) const;
+ bool operator!=(const QDomImplementation &other) const;
// functions
bool hasFeature(const QString& feature, const QString& version) const;
@@ -149,10 +112,10 @@ public:
};
QDomNode();
- QDomNode(const QDomNode&);
- QDomNode& operator= (const QDomNode&);
- bool operator== (const QDomNode&) const;
- bool operator!= (const QDomNode&) const;
+ QDomNode(const QDomNode &node);
+ QDomNode& operator=(const QDomNode &other);
+ bool operator==(const QDomNode &other) const;
+ bool operator!=(const QDomNode &other) const;
~QDomNode();
// DOM functions
@@ -183,7 +146,7 @@ public:
// DOM attributes
QString nodeValue() const;
- void setNodeValue(const QString&);
+ void setNodeValue(const QString &value);
QString prefix() const;
void setPrefix(const QString& pre);
@@ -240,6 +203,7 @@ protected:
QDomNode(QDomNodePrivate*);
private:
+ friend class ::tst_QDom;
friend class QDomDocument;
friend class QDomDocumentType;
friend class QDomNodeList;
@@ -250,10 +214,10 @@ class Q_XML_EXPORT QDomNodeList
{
public:
QDomNodeList();
- QDomNodeList(const QDomNodeList&);
- QDomNodeList& operator= (const QDomNodeList&);
- bool operator== (const QDomNodeList&) const;
- bool operator!= (const QDomNodeList&) const;
+ QDomNodeList(const QDomNodeList &nodeList);
+ QDomNodeList& operator=(const QDomNodeList &other);
+ bool operator==(const QDomNodeList &other) const;
+ bool operator!=(const QDomNodeList &other) const;
~QDomNodeList();
// DOM functions
@@ -279,8 +243,8 @@ class Q_XML_EXPORT QDomDocumentType : public QDomNode
{
public:
QDomDocumentType();
- QDomDocumentType(const QDomDocumentType& x);
- QDomDocumentType& operator= (const QDomDocumentType&);
+ QDomDocumentType(const QDomDocumentType &documentType);
+ QDomDocumentType& operator=(const QDomDocumentType &other);
// DOM read only attributes
QString name() const;
@@ -304,11 +268,27 @@ private:
class Q_XML_EXPORT QDomDocument : public QDomNode
{
public:
+ enum class ParseOption {
+ Default = 0x00,
+ UseNamespaceProcessing = 0x01,
+ PreserveSpacingOnlyNodes = 0x02,
+ };
+ Q_DECLARE_FLAGS(ParseOptions, ParseOption)
+
+ struct ParseResult
+ {
+ QString errorMessage;
+ qsizetype errorLine = 0;
+ qsizetype errorColumn = 0;
+
+ explicit operator bool() const noexcept { return errorMessage.isEmpty(); }
+ };
+
QDomDocument();
explicit QDomDocument(const QString& name);
explicit QDomDocument(const QDomDocumentType& doctype);
- QDomDocument(const QDomDocument& x);
- QDomDocument& operator= (const QDomDocument&);
+ QDomDocument(const QDomDocument &document);
+ QDomDocument& operator=(const QDomDocument &other);
~QDomDocument();
// DOM functions
@@ -336,20 +316,38 @@ public:
inline QDomNode::NodeType nodeType() const { return DocumentNode; }
// Qt extensions
- bool setContent(const QByteArray& text, bool namespaceProcessing, QString *errorMsg=nullptr, int *errorLine=nullptr, int *errorColumn=nullptr );
- bool setContent(const QString& text, bool namespaceProcessing, QString *errorMsg=nullptr, int *errorLine=nullptr, int *errorColumn=nullptr );
- bool setContent(QIODevice* dev, bool namespaceProcessing, QString *errorMsg=nullptr, int *errorLine=nullptr, int *errorColumn=nullptr );
- bool setContent(const QByteArray& text, QString *errorMsg=nullptr, int *errorLine=nullptr, int *errorColumn=nullptr );
- bool setContent(const QString& text, QString *errorMsg=nullptr, int *errorLine=nullptr, int *errorColumn=nullptr );
- bool setContent(QIODevice* dev, QString *errorMsg=nullptr, int *errorLine=nullptr, int *errorColumn=nullptr );
+#if QT_DEPRECATED_SINCE(6, 8)
+ QT_DEPRECATED_VERSION_X_6_8("Use the overload taking ParseOptions instead.")
+ bool setContent(const QByteArray &text, bool namespaceProcessing, QString *errorMsg = nullptr, int *errorLine = nullptr, int *errorColumn = nullptr);
+ QT_DEPRECATED_VERSION_X_6_8("Use the overload taking ParseOptions instead.")
+ bool setContent(const QString &text, bool namespaceProcessing, QString *errorMsg = nullptr, int *errorLine = nullptr, int *errorColumn = nullptr);
+ QT_DEPRECATED_VERSION_X_6_8("Use the overload taking ParseOptions instead.")
+ bool setContent(QIODevice *dev, bool namespaceProcessing, QString *errorMsg = nullptr, int *errorLine = nullptr, int *errorColumn = nullptr);
+ QT_DEPRECATED_VERSION_X_6_8("Use the overload returning ParseResult instead.")
+ bool setContent(const QByteArray &text, QString *errorMsg, int *errorLine = nullptr, int *errorColumn = nullptr);
+ QT_DEPRECATED_VERSION_X_6_8("Use the overload returning ParseResult instead.")
+ bool setContent(const QString &text, QString *errorMsg, int *errorLine = nullptr, int *errorColumn = nullptr);
+ QT_DEPRECATED_VERSION_X_6_8("Use the overload returning ParseResult instead.")
+ bool setContent(QIODevice *dev, QString *errorMsg, int *errorLine = nullptr, int *errorColumn = nullptr);
+ QT_DEPRECATED_VERSION_X_6_8("Use the overload taking ParseOptions instead.")
bool setContent(QXmlStreamReader *reader, bool namespaceProcessing, QString *errorMsg = nullptr,
int *errorLine = nullptr, int *errorColumn = nullptr);
+#endif // QT_DEPRECATED_SINCE(6, 8)
+
+ Q_WEAK_OVERLOAD
+ ParseResult setContent(const QByteArray &data, ParseOptions options = ParseOption::Default)
+ { return setContentImpl(data, options); }
+ ParseResult setContent(QAnyStringView data, ParseOptions options = ParseOption::Default);
+ ParseResult setContent(QIODevice *device, ParseOptions options = ParseOption::Default);
+ ParseResult setContent(QXmlStreamReader *reader, ParseOptions options = ParseOption::Default);
// Qt extensions
- QString toString(int = 1) const;
- QByteArray toByteArray(int = 1) const;
+ QString toString(int indent = 1) const;
+ QByteArray toByteArray(int indent = 1) const;
private:
+ ParseResult setContentImpl(const QByteArray &data, ParseOptions options);
+
QDomDocument(QDomDocumentPrivate*);
friend class QDomNode;
@@ -359,10 +357,10 @@ class Q_XML_EXPORT QDomNamedNodeMap
{
public:
QDomNamedNodeMap();
- QDomNamedNodeMap(const QDomNamedNodeMap&);
- QDomNamedNodeMap& operator= (const QDomNamedNodeMap&);
- bool operator== (const QDomNamedNodeMap&) const;
- bool operator!= (const QDomNamedNodeMap&) const;
+ QDomNamedNodeMap(const QDomNamedNodeMap &namedNodeMap);
+ QDomNamedNodeMap& operator=(const QDomNamedNodeMap &other);
+ bool operator==(const QDomNamedNodeMap &other) const;
+ bool operator!=(const QDomNamedNodeMap &other) const;
~QDomNamedNodeMap();
// DOM functions
@@ -396,8 +394,8 @@ class Q_XML_EXPORT QDomDocumentFragment : public QDomNode
{
public:
QDomDocumentFragment();
- QDomDocumentFragment(const QDomDocumentFragment& x);
- QDomDocumentFragment& operator= (const QDomDocumentFragment&);
+ QDomDocumentFragment(const QDomDocumentFragment &documentFragment);
+ QDomDocumentFragment& operator=(const QDomDocumentFragment &other);
// Overridden from QDomNode
inline QDomNode::NodeType nodeType() const { return DocumentFragmentNode; }
@@ -413,8 +411,8 @@ class Q_XML_EXPORT QDomCharacterData : public QDomNode
{
public:
QDomCharacterData();
- QDomCharacterData(const QDomCharacterData& x);
- QDomCharacterData& operator= (const QDomCharacterData&);
+ QDomCharacterData(const QDomCharacterData &characterData);
+ QDomCharacterData& operator=(const QDomCharacterData &other);
// DOM functions
QString substringData(unsigned long offset, unsigned long count);
@@ -428,7 +426,7 @@ public:
// DOM attributes
QString data() const;
- void setData(const QString&);
+ void setData(const QString &data);
// Overridden from QDomNode
QDomNode::NodeType nodeType() const;
@@ -446,8 +444,8 @@ class Q_XML_EXPORT QDomAttr : public QDomNode
{
public:
QDomAttr();
- QDomAttr(const QDomAttr& x);
- QDomAttr& operator= (const QDomAttr&);
+ QDomAttr(const QDomAttr &attr);
+ QDomAttr& operator=(const QDomAttr &other);
// DOM read only attributes
QString name() const;
@@ -456,7 +454,7 @@ public:
// DOM attributes
QString value() const;
- void setValue(const QString&);
+ void setValue(const QString &value);
// Overridden from QDomNode
inline QDomNode::NodeType nodeType() const { return AttributeNode; }
@@ -473,8 +471,8 @@ class Q_XML_EXPORT QDomElement : public QDomNode
{
public:
QDomElement();
- QDomElement(const QDomElement& x);
- QDomElement& operator= (const QDomElement&);
+ QDomElement(const QDomElement &element);
+ QDomElement& operator=(const QDomElement &other);
// DOM functions
QString attribute(const QString& name, const QString& defValue = QString() ) const;
@@ -531,8 +529,8 @@ class Q_XML_EXPORT QDomText : public QDomCharacterData
{
public:
QDomText();
- QDomText(const QDomText& x);
- QDomText& operator= (const QDomText&);
+ QDomText(const QDomText &text);
+ QDomText& operator=(const QDomText &other);
// DOM functions
QDomText splitText(int offset);
@@ -552,8 +550,8 @@ class Q_XML_EXPORT QDomComment : public QDomCharacterData
{
public:
QDomComment();
- QDomComment(const QDomComment& x);
- QDomComment& operator= (const QDomComment&);
+ QDomComment(const QDomComment &comment);
+ QDomComment& operator=(const QDomComment &other);
// Overridden from QDomCharacterData
inline QDomNode::NodeType nodeType() const { return CommentNode; }
@@ -569,8 +567,8 @@ class Q_XML_EXPORT QDomCDATASection : public QDomText
{
public:
QDomCDATASection();
- QDomCDATASection(const QDomCDATASection& x);
- QDomCDATASection& operator= (const QDomCDATASection&);
+ QDomCDATASection(const QDomCDATASection &cdataSection);
+ QDomCDATASection& operator=(const QDomCDATASection &other);
// Overridden from QDomText
inline QDomNode::NodeType nodeType() const { return CDATASectionNode; }
@@ -586,8 +584,8 @@ class Q_XML_EXPORT QDomNotation : public QDomNode
{
public:
QDomNotation();
- QDomNotation(const QDomNotation& x);
- QDomNotation& operator= (const QDomNotation&);
+ QDomNotation(const QDomNotation &notation);
+ QDomNotation& operator=(const QDomNotation &other);
// DOM read only attributes
QString publicId() const;
@@ -607,8 +605,8 @@ class Q_XML_EXPORT QDomEntity : public QDomNode
{
public:
QDomEntity();
- QDomEntity(const QDomEntity& x);
- QDomEntity& operator= (const QDomEntity&);
+ QDomEntity(const QDomEntity &entity);
+ QDomEntity& operator=(const QDomEntity &other);
// DOM read only attributes
QString publicId() const;
@@ -628,8 +626,8 @@ class Q_XML_EXPORT QDomEntityReference : public QDomNode
{
public:
QDomEntityReference();
- QDomEntityReference(const QDomEntityReference& x);
- QDomEntityReference& operator= (const QDomEntityReference&);
+ QDomEntityReference(const QDomEntityReference &entityReference);
+ QDomEntityReference& operator=(const QDomEntityReference &other);
// Overridden from QDomNode
inline QDomNode::NodeType nodeType() const { return EntityReferenceNode; }
@@ -645,15 +643,15 @@ class Q_XML_EXPORT QDomProcessingInstruction : public QDomNode
{
public:
QDomProcessingInstruction();
- QDomProcessingInstruction(const QDomProcessingInstruction& x);
- QDomProcessingInstruction& operator= (const QDomProcessingInstruction&);
+ QDomProcessingInstruction(const QDomProcessingInstruction &processingInstruction);
+ QDomProcessingInstruction& operator=(const QDomProcessingInstruction &other);
// DOM read only attributes
QString target() const;
// DOM attributes
QString data() const;
- void setData(const QString& d);
+ void setData(const QString &data);
// Overridden from QDomNode
inline QDomNode::NodeType nodeType() const { return ProcessingInstructionNode; }
@@ -666,7 +664,7 @@ private:
};
-Q_XML_EXPORT QTextStream& operator<<(QTextStream&, const QDomNode&);
+Q_XML_EXPORT QTextStream& operator<<(QTextStream& stream, const QDomNode& node);
#endif // QT_NO_DOM
diff --git a/src/xml/dom/qdom_p.h b/src/xml/dom/qdom_p.h
index 82c533b141..b2ecd534c8 100644
--- a/src/xml/dom/qdom_p.h
+++ b/src/xml/dom/qdom_p.h
@@ -1,47 +1,11 @@
-/****************************************************************************
-**
-** Copyright (C) 2019 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtXml module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2019 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QDOM_P_H
#define QDOM_P_H
#include "qdom.h"
-#include <qglobal.h>
+#include <private/qglobal_p.h>
#include <qhash.h>
#include <qstring.h>
#include <qlist.h>
@@ -62,7 +26,7 @@ QT_BEGIN_NAMESPACE
/**************************************************************
*
- * Private class declerations
+ * Private class declarations
*
**************************************************************/
@@ -178,7 +142,8 @@ public:
bool operator==(const QDomNodeListPrivate &) const;
bool operator!=(const QDomNodeListPrivate &) const;
- void createList();
+ void createList() const;
+ bool maybeCreateList() const;
QDomNodePrivate *item(int index);
int length() const;
@@ -189,8 +154,8 @@ public:
QDomNodePrivate *node_impl;
QString tagname;
QString nsURI;
- QList<QDomNodePrivate *> list;
- long timestamp;
+ mutable QList<QDomNodePrivate *> list;
+ mutable long timestamp;
};
class QDomNamedNodeMapPrivate
@@ -461,8 +426,8 @@ public:
QDomDocumentPrivate(QDomDocumentPrivate *n, bool deep);
~QDomDocumentPrivate();
- bool setContent(QXmlStreamReader *reader, bool namespaceProcessing, QString *errorMsg,
- int *errorLine, int *errorColumn);
+ QDomDocument::ParseResult setContent(QXmlStreamReader *reader,
+ QDomDocument::ParseOptions options);
// Attributes
QDomDocumentTypePrivate *doctype() { return type.data(); }
diff --git a/src/xml/dom/qdomhelpers.cpp b/src/xml/dom/qdomhelpers.cpp
index 75d4c2c2b7..0649e0c75d 100644
--- a/src/xml/dom/qdomhelpers.cpp
+++ b/src/xml/dom/qdomhelpers.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2019 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtXml module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2019 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include <QtXml/qtxmlglobal.h>
@@ -44,28 +8,14 @@
#include "qdomhelpers_p.h"
#include "qdom_p.h"
#include "qxmlstream.h"
+#include "private/qxmlstream_p.h"
+#include <memory>
#include <stack>
QT_BEGIN_NAMESPACE
-/**************************************************************
- *
- * QXmlDocumentLocators
- *
- **************************************************************/
-
-int QDomDocumentLocator::column() const
-{
- Q_ASSERT(reader);
- return static_cast<int>(reader->columnNumber());
-}
-
-int QDomDocumentLocator::line() const
-{
- Q_ASSERT(reader);
- return static_cast<int>(reader->lineNumber());
-}
+using namespace Qt::StringLiterals;
/**************************************************************
*
@@ -73,14 +23,12 @@ int QDomDocumentLocator::line() const
*
**************************************************************/
-QDomBuilder::QDomBuilder(QDomDocumentPrivate *d, QXmlDocumentLocator *l, bool namespaceProcessing)
- : errorLine(0),
- errorColumn(0),
- doc(d),
- node(d),
- locator(l),
- nsProcessing(namespaceProcessing)
+QDomBuilder::QDomBuilder(QDomDocumentPrivate *d, QXmlStreamReader *r,
+ QDomDocument::ParseOptions options)
+ : doc(d), node(d), reader(r), parseOptions(options)
{
+ Q_ASSERT(doc);
+ Q_ASSERT(reader);
}
QDomBuilder::~QDomBuilder() {}
@@ -101,15 +49,46 @@ bool QDomBuilder::startDTD(const QString &name, const QString &publicId, const Q
return true;
}
+QString QDomBuilder::dtdInternalSubset(const QString &dtd)
+{
+ // https://www.w3.org/TR/xml/#NT-intSubset
+ // doctypedecl: '<!DOCTYPE' S Name (S ExternalID)? S? ('[' intSubset ']' S?)? '>'
+ const QString &name = doc->doctype()->name;
+ QStringView tmp = QStringView(dtd).sliced(dtd.indexOf(name) + name.size());
+
+ const QString &publicId = doc->doctype()->publicId;
+ if (!publicId.isEmpty())
+ tmp = tmp.sliced(tmp.indexOf(publicId) + publicId.size());
+
+ const QString &systemId = doc->doctype()->systemId;
+ if (!systemId.isEmpty())
+ tmp = tmp.sliced(tmp.indexOf(systemId) + systemId.size());
+
+ const qsizetype obra = tmp.indexOf(u'[');
+ const qsizetype cbra = tmp.lastIndexOf(u']');
+ if (obra >= 0 && cbra >= 0)
+ return tmp.left(cbra).sliced(obra + 1).toString();
+
+ return QString();
+}
+
+bool QDomBuilder::parseDTD(const QString &dtd)
+{
+ doc->doctype()->internalSubset = dtdInternalSubset(dtd);
+ return true;
+}
+
bool QDomBuilder::startElement(const QString &nsURI, const QString &qName,
const QXmlStreamAttributes &atts)
{
+ const bool nsProcessing =
+ parseOptions.testFlag(QDomDocument::ParseOption::UseNamespaceProcessing);
QDomNodePrivate *n =
nsProcessing ? doc->createElementNS(nsURI, qName) : doc->createElement(qName);
if (!n)
return false;
- n->setLocation(locator->line(), locator->column());
+ n->setLocation(int(reader->lineNumber()), int(reader->columnNumber()));
node->appendChild(n);
node = n;
@@ -145,23 +124,23 @@ bool QDomBuilder::characters(const QString &characters, bool cdata)
if (node == doc)
return false;
- QScopedPointer<QDomNodePrivate> n;
+ std::unique_ptr<QDomNodePrivate> n;
if (cdata) {
n.reset(doc->createCDATASection(characters));
} else if (!entityName.isEmpty()) {
- QScopedPointer<QDomEntityPrivate> e(
- new QDomEntityPrivate(doc, nullptr, entityName, QString(), QString(), QString()));
+ auto e = std::make_unique<QDomEntityPrivate>(
+ doc, nullptr, entityName, QString(), QString(), QString());
e->value = characters;
e->ref.deref();
- doc->doctype()->appendChild(e.data());
- e.take();
+ doc->doctype()->appendChild(e.get());
+ Q_UNUSED(e.release());
n.reset(doc->createEntityReference(entityName));
} else {
n.reset(doc->createTextNode(characters));
}
- n->setLocation(locator->line(), locator->column());
- node->appendChild(n.data());
- n.take();
+ n->setLocation(int(reader->lineNumber()), int(reader->columnNumber()));
+ node->appendChild(n.get());
+ Q_UNUSED(n.release());
return true;
}
@@ -171,7 +150,7 @@ bool QDomBuilder::processingInstruction(const QString &target, const QString &da
QDomNodePrivate *n;
n = doc->createProcessingInstruction(target, data);
if (n) {
- n->setLocation(locator->line(), locator->column());
+ n->setLocation(int(reader->lineNumber()), int(reader->columnNumber()));
node->appendChild(n);
return true;
} else
@@ -181,21 +160,16 @@ bool QDomBuilder::processingInstruction(const QString &target, const QString &da
bool QDomBuilder::skippedEntity(const QString &name)
{
QDomNodePrivate *n = doc->createEntityReference(name);
- n->setLocation(locator->line(), locator->column());
+ n->setLocation(int(reader->lineNumber()), int(reader->columnNumber()));
node->appendChild(n);
return true;
}
void QDomBuilder::fatalError(const QString &message)
{
- errorMsg = message;
- errorLine = static_cast<int>(locator->line());
- errorColumn = static_cast<int>(locator->column());
-}
-
-QDomBuilder::ErrorInfo QDomBuilder::error() const
-{
- return ErrorInfo(errorMsg, errorLine, errorColumn);
+ parseResult.errorMessage = message;
+ parseResult.errorLine = reader->lineNumber();
+ parseResult.errorColumn = reader->columnNumber();
}
bool QDomBuilder::startEntity(const QString &name)
@@ -214,7 +188,7 @@ bool QDomBuilder::comment(const QString &characters)
{
QDomNodePrivate *n;
n = doc->createComment(characters);
- n->setLocation(locator->line(), locator->column());
+ n->setLocation(int(reader->lineNumber()), int(reader->columnNumber()));
node->appendChild(n);
return true;
}
@@ -252,8 +226,9 @@ bool QDomBuilder::notationDecl(const QString &name, const QString &publicId,
*
**************************************************************/
-QDomParser::QDomParser(QDomDocumentPrivate *d, QXmlStreamReader *r, bool namespaceProcessing)
- : reader(r), locator(r), domBuilder(d, &locator, namespaceProcessing)
+QDomParser::QDomParser(QDomDocumentPrivate *d, QXmlStreamReader *r,
+ QDomDocument::ParseOptions options)
+ : reader(r), domBuilder(d, r, options)
{
}
@@ -262,11 +237,6 @@ bool QDomParser::parse()
return parseProlog() && parseBody();
}
-QDomBuilder::ErrorInfo QDomParser::errorInfo() const
-{
- return domBuilder.error();
-}
-
bool QDomParser::parseProlog()
{
Q_ASSERT(reader);
@@ -284,23 +254,23 @@ bool QDomParser::parseProlog()
switch (reader->tokenType()) {
case QXmlStreamReader::StartDocument:
if (!reader->documentVersion().isEmpty()) {
- QString value(QLatin1String("version='"));
+ QString value(u"version='"_s);
value += reader->documentVersion();
- value += QLatin1Char('\'');
+ value += u'\'';
if (!reader->documentEncoding().isEmpty()) {
- value += QLatin1String(" encoding='");
+ value += u" encoding='"_s;
value += reader->documentEncoding();
- value += QLatin1Char('\'');
+ value += u'\'';
}
if (reader->isStandaloneDocument()) {
- value += QLatin1String(" standalone='yes'");
+ value += u" standalone='yes'"_s;
} else {
- // TODO: Add standalone='no', if 'standalone' is specified. With the current
- // QXmlStreamReader there is no way to figure out if it was specified or not.
- // QXmlStreamReader needs to be modified for handling that case correctly.
+ // Add the standalone attribute only if it was specified
+ if (reader->hasStandaloneDeclaration())
+ value += u" standalone='no'"_s;
}
- if (!domBuilder.processingInstruction(QLatin1String("xml"), value)) {
+ if (!domBuilder.processingInstruction(u"xml"_s, value)) {
domBuilder.fatalError(
QDomParser::tr("Error occurred while processing XML declaration"));
return false;
@@ -321,6 +291,8 @@ bool QDomParser::parseProlog()
QDomParser::tr("Error occurred while processing document type declaration"));
return false;
}
+ if (!domBuilder.parseDTD(reader->text().toString()))
+ return false;
if (!parseMarkupDecl())
return false;
break;
@@ -378,13 +350,14 @@ bool QDomParser::parseBody()
}
break;
case QXmlStreamReader::Characters:
- if (!reader->isWhitespace()) { // Skip the content consisting of only whitespaces
- if (!reader->text().toString().trimmed().isEmpty()) {
- if (!domBuilder.characters(reader->text().toString(), reader->isCDATA())) {
- domBuilder.fatalError(QDomParser::tr(
- "Error occurred while processing the element content"));
- return false;
- }
+ // Skip the content if it contains only spacing characters,
+ // unless it's CDATA or PreserveSpacingOnlyNodes was specified.
+ if (reader->isCDATA() || domBuilder.preserveSpacingOnlyNodes()
+ || !(reader->isWhitespace() || reader->text().trimmed().isEmpty())) {
+ if (!domBuilder.characters(reader->text().toString(), reader->isCDATA())) {
+ domBuilder.fatalError(
+ QDomParser::tr("Error occurred while processing the element content"));
+ return false;
}
}
break;
@@ -437,7 +410,7 @@ bool QDomParser::parseMarkupDecl()
const auto entities = reader->entityDeclarations();
for (const auto &entityDecl : entities) {
- // Entity declarations are created only for Extrenal Entities. Internal Entities
+ // Entity declarations are created only for External Entities. Internal Entities
// are parsed, and QXmlStreamReader handles the parsing itself and returns the
// parsed result. So we don't need to do anything for the Internal Entities.
if (!entityDecl.publicId().isEmpty() || !entityDecl.systemId().isEmpty()) {
diff --git a/src/xml/dom/qdomhelpers_p.h b/src/xml/dom/qdomhelpers_p.h
index f7264daf4b..5a4b2207f9 100644
--- a/src/xml/dom/qdomhelpers_p.h
+++ b/src/xml/dom/qdomhelpers_p.h
@@ -1,46 +1,11 @@
-/****************************************************************************
-**
-** Copyright (C) 2019 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtXml module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QDOMHELPERS_P_H
#define QDOMHELPERS_P_H
#include <qcoreapplication.h>
-#include <qglobal.h>
+#include <qdom.h>
+#include <private/qglobal_p.h>
QT_BEGIN_NAMESPACE
@@ -62,38 +27,6 @@ class QXmlStreamAttributes;
/**************************************************************
*
- * QXmlDocumentLocators
- *
- **************************************************************/
-
-/* TODO: QXmlDocumentLocator can be removed when the SAX-based
- * implementation is removed. Right now it is needed for QDomBuilder
- * to work with both QXmlStreamReader and QXmlInputSource (SAX)
- * based implementations.
- */
-class QXmlDocumentLocator
-{
-public:
- virtual ~QXmlDocumentLocator() = default;
- virtual int column() const = 0;
- virtual int line() const = 0;
-};
-
-class QDomDocumentLocator : public QXmlDocumentLocator
-{
-public:
- QDomDocumentLocator(QXmlStreamReader *r) : reader(r) {}
- ~QDomDocumentLocator() override = default;
-
- int column() const override;
- int line() const override;
-
-private:
- QXmlStreamReader *reader;
-};
-
-/**************************************************************
- *
* QDomBuilder
*
**************************************************************/
@@ -101,7 +34,7 @@ private:
class QDomBuilder
{
public:
- QDomBuilder(QDomDocumentPrivate *d, QXmlDocumentLocator *l, bool namespaceProcessing);
+ QDomBuilder(QDomDocumentPrivate *d, QXmlStreamReader *r, QDomDocument::ParseOptions options);
~QDomBuilder();
bool endDocument();
@@ -113,6 +46,7 @@ public:
bool startEntity(const QString &name);
bool endEntity();
bool startDTD(const QString &name, const QString &publicId, const QString &systemId);
+ bool parseDTD(const QString &dtd);
bool comment(const QString &characters);
bool externalEntityDecl(const QString &name, const QString &publicId, const QString &systemId);
bool notationDecl(const QString &name, const QString &publicId, const QString &systemId);
@@ -120,20 +54,20 @@ public:
const QString &notationName);
void fatalError(const QString &message);
+ QDomDocument::ParseResult result() const { return parseResult; }
- using ErrorInfo = std::tuple<QString, int, int>;
- ErrorInfo error() const;
-
- QString errorMsg;
- int errorLine;
- int errorColumn;
+ bool preserveSpacingOnlyNodes() const
+ { return parseOptions & QDomDocument::ParseOption::PreserveSpacingOnlyNodes; }
private:
+ QString dtdInternalSubset(const QString &dtd);
+
+ QDomDocument::ParseResult parseResult;
QDomDocumentPrivate *doc;
QDomNodePrivate *node;
- QXmlDocumentLocator *locator;
+ QXmlStreamReader *reader;
QString entityName;
- bool nsProcessing;
+ QDomDocument::ParseOptions parseOptions;
};
/**************************************************************
@@ -146,10 +80,10 @@ class QDomParser
{
Q_DECLARE_TR_FUNCTIONS(QDomParser)
public:
- QDomParser(QDomDocumentPrivate *d, QXmlStreamReader *r, bool namespaceProcessing);
+ QDomParser(QDomDocumentPrivate *d, QXmlStreamReader *r, QDomDocument::ParseOptions options);
bool parse();
- QDomBuilder::ErrorInfo errorInfo() const;
+ QDomDocument::ParseResult result() const { return domBuilder.result(); }
private:
bool parseProlog();
@@ -157,7 +91,6 @@ private:
bool parseMarkupDecl();
QXmlStreamReader *reader;
- QDomDocumentLocator locator;
QDomBuilder domBuilder;
};
diff --git a/src/xml/qtxmlglobal.h b/src/xml/qtxmlglobal.h
index 1ce3008f4a..ed7ea58860 100644
--- a/src/xml/qtxmlglobal.h
+++ b/src/xml/qtxmlglobal.h
@@ -1,62 +1,11 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Intel Corporation.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtXml module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Intel Corporation.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QTXMLGLOBAL_H
#define QTXMLGLOBAL_H
#include <QtCore/qglobal.h>
-#ifndef QT_BOOTSTRAPPED
-# include <QtXml/qtxml-config.h>
-#endif
-
-QT_BEGIN_NAMESPACE
-
-#ifndef QT_STATIC
-# if defined(QT_BUILD_XML_LIB)
-# define Q_XML_EXPORT Q_DECL_EXPORT
-# else
-# define Q_XML_EXPORT Q_DECL_IMPORT
-# endif
-#else
-# define Q_XML_EXPORT
-#endif
-
-QT_END_NAMESPACE
+#include <QtXml/qtxml-config.h>
+#include <QtXml/qtxmlexports.h>
#endif // QTXMLGLOBAL_H