Qt 4.8
Public Functions | Properties | Friends | List of all members
QXmlSchema Class Reference

The QXmlSchema class provides loading and validation of a W3C XML Schema. More...

#include <qxmlschema.h>

Public Functions

QUrl documentUri () const
 Returns the document URI of the schema or an empty URI if no schema has been set. More...
 
bool isValid () const
 Returns true if this schema is valid. More...
 
bool load (const QUrl &source)
 Sets this QXmlSchema to a schema loaded from the source URI. More...
 
bool load (QIODevice *source, const QUrl &documentUri=QUrl())
 Sets this QXmlSchema to a schema read from the source device. More...
 
bool load (const QByteArray &data, const QUrl &documentUri=QUrl())
 Sets this QXmlSchema to a schema read from the data. More...
 
QAbstractMessageHandlermessageHandler () const
 Returns the message handler that handles compile and validation messages for this QXmlSchema. More...
 
QXmlNamePool namePool () const
 Returns the name pool used by this QXmlSchema for constructing QXmlName {names}. More...
 
QNetworkAccessManagernetworkAccessManager () const
 Returns the network manager, or 0 if it has not been set. More...
 
 QXmlSchema ()
 Constructs an invalid, empty schema that cannot be used until load() is called. More...
 
 QXmlSchema (const QXmlSchema &other)
 Constructs a QXmlSchema that is a copy of other. More...
 
void setMessageHandler (QAbstractMessageHandler *handler)
 Changes the QAbstractMessageHandler{message handler} for this QXmlSchema to handler. More...
 
void setNetworkAccessManager (QNetworkAccessManager *networkmanager)
 Sets the network manager to manager. More...
 
void setUriResolver (const QAbstractUriResolver *resolver)
 Sets the URI resolver to resolver. More...
 
const QAbstractUriResolveruriResolver () const
 Returns the schema's URI resolver. More...
 
 ~QXmlSchema ()
 Destroys this QXmlSchema. More...
 

Properties

QSharedDataPointer< QXmlSchemaPrivated
 

Friends

class QXmlSchemaValidatorPrivate
 

Detailed Description

The QXmlSchema class provides loading and validation of a W3C XML Schema.

Note
This class or function is reentrant.
Since
4.6

The QXmlSchema class loads, compiles and validates W3C XML Schema files that can be used further for validation of XML instance documents via QXmlSchemaValidator.

The following example shows how to load a XML Schema file from the network and test whether it is a valid schema document:

QUrl url("http://www.schema-example.org/myschema.xsd");
QXmlSchema schema;
if (schema.load(url) == true)
qDebug() << "schema is valid";
else
qDebug() << "schema is invalid";

XML Schema Version

This class is used to represent schemas that conform to the XML Schema 1.0 specification.

See also
QXmlSchemaValidator, {xmlpatterns/schema}{XML Schema Validation Example}

Definition at line 62 of file qxmlschema.h.

Constructors and Destructors

◆ QXmlSchema() [1/2]

QXmlSchema::QXmlSchema ( )

Constructs an invalid, empty schema that cannot be used until load() is called.

Definition at line 83 of file qxmlschema.cpp.

85 {
86 }
QSharedDataPointer< QXmlSchemaPrivate > d
Definition: qxmlschema.h:90
The QXmlNamePool class is a table of shared strings referenced by instances of QXmlName.
Definition: qxmlnamepool.h:69

◆ QXmlSchema() [2/2]

QXmlSchema::QXmlSchema ( const QXmlSchema other)

Constructs a QXmlSchema that is a copy of other.

The new instance will share resources with the existing schema to the extent possible.

Definition at line 93 of file qxmlschema.cpp.

94  : d(other.d)
95 {
96 }
QSharedDataPointer< QXmlSchemaPrivate > d
Definition: qxmlschema.h:90

◆ ~QXmlSchema()

QXmlSchema::~QXmlSchema ( )

Destroys this QXmlSchema.

Definition at line 101 of file qxmlschema.cpp.

102 {
103 }

Functions

◆ documentUri()

QUrl QXmlSchema::documentUri ( ) const

Returns the document URI of the schema or an empty URI if no schema has been set.

Definition at line 201 of file qxmlschema.cpp.

Referenced by QXmlSchemaValidatorPrivate::setSchema().

202 {
203  return d->documentUri();
204 }
QSharedDataPointer< QXmlSchemaPrivate > d
Definition: qxmlschema.h:90
QUrl documentUri() const

◆ isValid()

bool QXmlSchema::isValid ( ) const

Returns true if this schema is valid.

Examples of invalid schemas are ones that contain syntax errors or that do not conform the W3C XML Schema specification.

Definition at line 183 of file qxmlschema.cpp.

184 {
185  return d->isValid();
186 }
QSharedDataPointer< QXmlSchemaPrivate > d
Definition: qxmlschema.h:90
bool isValid() const

◆ load() [1/3]

bool QXmlSchema::load ( const QUrl source)

Sets this QXmlSchema to a schema loaded from the source URI.

If the schema isValid() {is invalid}, false is returned and the behavior is undefined.

Example:

QUrl url("http://www.schema-example.org/myschema.xsd");
QXmlSchema schema;
if (schema.load(url) == true)
qDebug() << "schema is valid";
else
qDebug() << "schema is invalid";
See also
isValid()

Definition at line 118 of file qxmlschema.cpp.

119 {
120  d->load(source, QString());
121  return d->isValid();
122 }
QSharedDataPointer< QXmlSchemaPrivate > d
Definition: qxmlschema.h:90
The QString class provides a Unicode character string.
Definition: qstring.h:83
void load(const QUrl &source, const QString &targetNamespace)
bool isValid() const

◆ load() [2/3]

bool QXmlSchema::load ( QIODevice source,
const QUrl documentUri = QUrl() 
)

Sets this QXmlSchema to a schema read from the source device.

The device must have been opened with at least QIODevice::ReadOnly.

documentUri represents the schema obtained from the source device. It is the base URI of the schema, that is used internally to resolve relative URIs that appear in the schema, and for message reporting.

If source is null or not readable, or if documentUri is not a valid URI, behavior is undefined.

If the schema isValid() {is invalid}, false is returned and the behavior is undefined.

Example:

QFile file("myschema.xsd");
file.open(QIODevice::ReadOnly);
QXmlSchema schema;
schema.load(&file, QUrl::fromLocalFile(file.fileName()));
if (schema.isValid())
qDebug() << "schema is valid";
else
qDebug() << "schema is invalid";
See also
isValid()

Definition at line 146 of file qxmlschema.cpp.

147 {
148  d->load(source, documentUri, QString());
149  return d->isValid();
150 }
QSharedDataPointer< QXmlSchemaPrivate > d
Definition: qxmlschema.h:90
The QString class provides a Unicode character string.
Definition: qstring.h:83
void load(const QUrl &source, const QString &targetNamespace)
bool isValid() const

◆ load() [3/3]

bool QXmlSchema::load ( const QByteArray data,
const QUrl documentUri = QUrl() 
)

Sets this QXmlSchema to a schema read from the data.

documentUri represents the schema obtained from the data. It is the base URI of the schema, that is used internally to resolve relative URIs that appear in the schema, and for message reporting.

If documentUri is not a valid URI, behavior is undefined.

See also
isValid()

If the schema isValid() {is invalid}, false is returned and the behavior is undefined.

Example:

QByteArray data( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"<xsd:schema"
" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\""
" xmlns=\"http://qt.nokia.com/xmlschematest\""
" targetNamespace=\"http://qt.nokia.com/xmlschematest\""
" version=\"1.0\""
" elementFormDefault=\"qualified\">"
"</xsd:schema>" );
QXmlSchema schema;
schema.load(data);
if (schema.isValid())
qDebug() << "schema is valid";
else
qDebug() << "schema is invalid";
See also
isValid()

Definition at line 172 of file qxmlschema.cpp.

173 {
174  d->load(data, documentUri, QString());
175  return d->isValid();
176 }
QSharedDataPointer< QXmlSchemaPrivate > d
Definition: qxmlschema.h:90
The QString class provides a Unicode character string.
Definition: qstring.h:83
void load(const QUrl &source, const QString &targetNamespace)
bool isValid() const

◆ messageHandler()

QAbstractMessageHandler * QXmlSchema::messageHandler ( ) const

Returns the message handler that handles compile and validation messages for this QXmlSchema.

Definition at line 250 of file qxmlschema.cpp.

251 {
252  return d->messageHandler();
253 }
QSharedDataPointer< QXmlSchemaPrivate > d
Definition: qxmlschema.h:90
QAbstractMessageHandler * messageHandler() const

◆ namePool()

QXmlNamePool QXmlSchema::namePool ( ) const

Returns the name pool used by this QXmlSchema for constructing QXmlName {names}.

There is no setter for the name pool, because mixing name pools causes errors due to name confusion.

Definition at line 192 of file qxmlschema.cpp.

Referenced by QXmlSchemaValidatorPrivate::setSchema().

193 {
194  return d->namePool();
195 }
QSharedDataPointer< QXmlSchemaPrivate > d
Definition: qxmlschema.h:90
QXmlNamePool namePool() const

◆ networkAccessManager()

QNetworkAccessManager * QXmlSchema::networkAccessManager ( ) const

Returns the network manager, or 0 if it has not been set.

See also
setNetworkAccessManager()

Definition at line 301 of file qxmlschema.cpp.

302 {
303  return d->networkAccessManager();
304 }
QSharedDataPointer< QXmlSchemaPrivate > d
Definition: qxmlschema.h:90
QNetworkAccessManager * networkAccessManager() const

◆ setMessageHandler()

void QXmlSchema::setMessageHandler ( QAbstractMessageHandler handler)

Changes the QAbstractMessageHandler{message handler} for this QXmlSchema to handler.

The schema sends all compile and validation messages to this message handler. QXmlSchema does not take ownership of handler.

Normally, the default message handler is sufficient. It writes compile and validation messages to stderr. The default message handler includes color codes if stderr can render colors.

When QXmlSchema calls QAbstractMessageHandler::message(), the arguments are as follows:

message() argument Semantics
QtMsgType type Only QtWarningMsg and QtFatalMsg are used. The former identifies a warning, while the latter identifies an error.
const QString & description An XHTML document which is the actual message. It is translated into the current language.
const QUrl &identifier Identifies the error with a URI, where the fragment is the error code, and the rest of the URI is the error namespace.
const QSourceLocation & sourceLocation Identifies where the error occurred.

Definition at line 241 of file qxmlschema.cpp.

242 {
243  d->setMessageHandler(handler);
244 }
QSharedDataPointer< QXmlSchemaPrivate > d
Definition: qxmlschema.h:90
void setMessageHandler(QAbstractMessageHandler *handler)

◆ setNetworkAccessManager()

void QXmlSchema::setNetworkAccessManager ( QNetworkAccessManager manager)

Sets the network manager to manager.

QXmlSchema does not take ownership of manager.

See also
networkAccessManager()

Definition at line 291 of file qxmlschema.cpp.

292 {
293  d->setNetworkAccessManager(manager);
294 }
QSharedDataPointer< QXmlSchemaPrivate > d
Definition: qxmlschema.h:90
void setNetworkAccessManager(QNetworkAccessManager *networkmanager)

◆ setUriResolver()

void QXmlSchema::setUriResolver ( const QAbstractUriResolver resolver)

Sets the URI resolver to resolver.

QXmlSchema does not take ownership of resolver.

See also
uriResolver()

Definition at line 261 of file qxmlschema.cpp.

262 {
263  d->setUriResolver(resolver);
264 }
QSharedDataPointer< QXmlSchemaPrivate > d
Definition: qxmlschema.h:90
void setUriResolver(const QAbstractUriResolver *resolver)

◆ uriResolver()

const QAbstractUriResolver * QXmlSchema::uriResolver ( ) const

Returns the schema's URI resolver.

If no URI resolver has been set, QtXmlPatterns will use the URIs in schemas as they are.

The URI resolver provides a level of abstraction, or polymorphic URIs. A resolver can rewrite logical URIs to physical ones, or it can translate obsolete or invalid URIs to valid ones.

When QtXmlPatterns calls QAbstractUriResolver::resolve() the absolute URI is the URI mandated by the schema specification, and the relative URI is the URI specified by the user.

See also
setUriResolver()

Definition at line 280 of file qxmlschema.cpp.

281 {
282  return d->uriResolver();
283 }
QSharedDataPointer< QXmlSchemaPrivate > d
Definition: qxmlschema.h:90
const QAbstractUriResolver * uriResolver() const

Friends and Related Functions

◆ QXmlSchemaValidatorPrivate

Definition at line 64 of file qxmlschema.h.

Properties

◆ d

QSharedDataPointer<QXmlSchemaPrivate> QXmlSchema::d
private

The documentation for this class was generated from the following files: