summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Koenig <tokoe@kde.org>2009-05-19 18:09:09 (GMT)
committerTobias Koenig <tokoe@kde.org>2009-05-19 18:09:09 (GMT)
commitf66a475a236649c94a47f668ba3461bdc325c308 (patch)
tree4734c2dccfc8e0adfe9474d8a0acc4e634970d5b
parent9519f3ee67c8ab2de8d1ab5e584f8d3adb8875bd (diff)
downloadQt-f66a475a236649c94a47f668ba3461bdc325c308.zip
Qt-f66a475a236649c94a47f668ba3461bdc325c308.tar.gz
Qt-f66a475a236649c94a47f668ba3461bdc325c308.tar.bz2
First version of documentation for schema example
-rw-r--r--doc/src/examples.qdoc1
-rw-r--r--doc/src/examples/schema.qdoc58
-rw-r--r--doc/src/images/schema-example.pngbin0 -> 84320 bytes
-rw-r--r--examples/xmlpatterns/schema/mainwindow.cpp19
-rw-r--r--examples/xmlpatterns/schema/schema.ui2
-rw-r--r--src/xmlpatterns/api/qxmlschema.cpp10
6 files changed, 81 insertions, 9 deletions
diff --git a/doc/src/examples.qdoc b/doc/src/examples.qdoc
index 29c6c0b..a0e9b23 100644
--- a/doc/src/examples.qdoc
+++ b/doc/src/examples.qdoc
@@ -398,6 +398,7 @@
\o \l{xmlpatterns/qobjectxmlmodel}{QObject XML Model Example}
\o \l{xmlpatterns/xquery/globalVariables}{C++ Source Code Analyzer Example}
\o \l{xmlpatterns/trafficinfo}{Traffic Info}\raisedaster
+ \o \l{xmlpatterns/schema}{XML Schema Validation}\raisedaster
\endlist
\section1 Inter-Process Communication
diff --git a/doc/src/examples/schema.qdoc b/doc/src/examples/schema.qdoc
new file mode 100644
index 0000000..2287796
--- /dev/null
+++ b/doc/src/examples/schema.qdoc
@@ -0,0 +1,58 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example xmlpatterns/schema
+ \title XML Schema Validation Example
+
+ This example shows how to use QtXmlPatterns to validate XML with
+ a W3C XML Schema.
+
+ \section1 Introduction
+
+ The example application shows different XML schema definitions and
+ for every definition two XML instance documents, one that is valid
+ according to the schema and one that is not.
+ The user can select the valid or invalid instance document, change
+ it and validate it again.
+
+ \image schema-example.png
+*/
diff --git a/doc/src/images/schema-example.png b/doc/src/images/schema-example.png
new file mode 100644
index 0000000..5e95bf5
--- /dev/null
+++ b/doc/src/images/schema-example.png
Binary files differ
diff --git a/examples/xmlpatterns/schema/mainwindow.cpp b/examples/xmlpatterns/schema/mainwindow.cpp
index 6b43d7b..98276a3 100644
--- a/examples/xmlpatterns/schema/mainwindow.cpp
+++ b/examples/xmlpatterns/schema/mainwindow.cpp
@@ -69,7 +69,8 @@ class MessageHandler : public QAbstractMessageHandler
}
protected:
- virtual void handleMessage(QtMsgType type, const QString &description, const QUrl &identifier, const QSourceLocation &sourceLocation)
+ virtual void handleMessage(QtMsgType type, const QString &description,
+ const QUrl &identifier, const QSourceLocation &sourceLocation)
{
Q_UNUSED(type);
Q_UNUSED(identifier);
@@ -127,7 +128,7 @@ void MainWindow::schemaSelected(int index)
QFile schemaFile(QString(":/schema_%1.xsd").arg(index));
schemaFile.open(QIODevice::ReadOnly);
- const QString schemaText(QString::fromLatin1(schemaFile.readAll()));
+ const QString schemaText(QString::fromUtf8(schemaFile.readAll()));
schemaView->setPlainText(schemaText);
validate();
@@ -137,7 +138,7 @@ void MainWindow::instanceSelected(int index)
{
QFile instanceFile(QString(":/instance_%1.xml").arg((2*schemaSelection->currentIndex()) + index));
instanceFile.open(QIODevice::ReadOnly);
- const QString instanceText(QString::fromLatin1(instanceFile.readAll()));
+ const QString instanceText(QString::fromUtf8(instanceFile.readAll()));
instanceEdit->setPlainText(instanceText);
validate();
@@ -145,22 +146,22 @@ void MainWindow::instanceSelected(int index)
void MainWindow::validate()
{
- const QByteArray schemaData = schemaView->toPlainText().toLatin1();
- const QByteArray instanceData = instanceEdit->toPlainText().toLatin1();
+ const QByteArray schemaData = schemaView->toPlainText().toUtf8();
+ const QByteArray instanceData = instanceEdit->toPlainText().toUtf8();
MessageHandler messageHandler;
QXmlSchema schema;
schema.setMessageHandler(&messageHandler);
- schema.load(schemaData, QUrl("http://dummySchemaUrl/"));
+ schema.load(schemaData);
bool errorOccurred = false;
if (!schema.isValid()) {
errorOccurred = true;
} else {
QXmlSchemaValidator validator(schema);
- if (!validator.validate(instanceData, QUrl("http://dummyInstanceUrl")))
+ if (!validator.validate(instanceData))
errorOccurred = true;
}
@@ -171,7 +172,9 @@ void MainWindow::validate()
validationStatus->setText(tr("validation successful"));
}
- QString styleSheet = QString("QLabel {background: %1; padding: 3px}").arg(errorOccurred ? QColor(Qt::red).lighter(160).name() : QColor(Qt::green).lighter(160).name());
+ const QString styleSheet = QString("QLabel {background: %1; padding: 3px}")
+ .arg(errorOccurred ? QColor(Qt::red).lighter(160).name() :
+ QColor(Qt::green).lighter(160).name());
validationStatus->setStyleSheet(styleSheet);
}
diff --git a/examples/xmlpatterns/schema/schema.ui b/examples/xmlpatterns/schema/schema.ui
index af7020a..b67f444 100644
--- a/examples/xmlpatterns/schema/schema.ui
+++ b/examples/xmlpatterns/schema/schema.ui
@@ -11,7 +11,7 @@
</rect>
</property>
<property name="windowTitle">
- <string>MainWindow</string>
+ <string>XML Schema Validation</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QGridLayout" name="gridLayout">
diff --git a/src/xmlpatterns/api/qxmlschema.cpp b/src/xmlpatterns/api/qxmlschema.cpp
index aa5b77c..8e14f3f 100644
--- a/src/xmlpatterns/api/qxmlschema.cpp
+++ b/src/xmlpatterns/api/qxmlschema.cpp
@@ -88,6 +88,9 @@ QXmlSchema::~QXmlSchema()
/*!
Sets this QXmlSchema to a schema loaded from the \a source
URI.
+
+ If the schema \l {isValid()} {is invalid}, \c{false} is returned
+ and the behavior is undefined.
*/
bool QXmlSchema::load(const QUrl &source)
{
@@ -107,6 +110,10 @@ bool QXmlSchema::load(const QUrl &source)
If \a source is \c null or not readable, or if \a documentUri is not
a valid URI, behavior is undefined.
+
+ If the schema \l {isValid()} {is invalid}, \c{false} is returned
+ and the behavior is undefined.
+
\sa isValid()
*/
bool QXmlSchema::load(QIODevice *source, const QUrl &documentUri)
@@ -125,6 +132,9 @@ bool QXmlSchema::load(QIODevice *source, const QUrl &documentUri)
If \a documentUri is not a valid URI, behavior is undefined.
\sa isValid()
+
+ If the schema \l {isValid()} {is invalid}, \c{false} is returned
+ and the behavior is undefined.
*/
bool QXmlSchema::load(const QByteArray &data, const QUrl &documentUri)
{