Qt 4.8
|
The QXmlSchemaValidator class validates XML instance documents against a W3C XML Schema. More...
#include <qxmlschemavalidator.h>
Public Functions | |
QAbstractMessageHandler * | messageHandler () const |
Returns the message handler that handles parsing and validation messages for this QXmlSchemaValidator. More... | |
QXmlNamePool | namePool () const |
Returns the name pool used by this QXmlSchemaValidator for constructing QXmlName {names}. More... | |
QNetworkAccessManager * | networkAccessManager () const |
Returns the network manager, or 0 if it has not been set. More... | |
QXmlSchemaValidator () | |
Constructs a schema validator. More... | |
QXmlSchemaValidator (const QXmlSchema &schema) | |
Constructs a schema validator that will use schema for validation. More... | |
QXmlSchema | schema () const |
Returns the schema that is used for validation. More... | |
void | setMessageHandler (QAbstractMessageHandler *handler) |
Changes the QAbstractMessageHandler{message handler} for this QXmlSchemaValidator to handler. More... | |
void | setNetworkAccessManager (QNetworkAccessManager *networkmanager) |
Sets the network manager to manager. More... | |
void | setSchema (const QXmlSchema &schema) |
Sets the schema that shall be used for further validation. More... | |
void | setUriResolver (const QAbstractUriResolver *resolver) |
Sets the URI resolver to resolver. More... | |
const QAbstractUriResolver * | uriResolver () const |
Returns the schema's URI resolver. More... | |
bool | validate (const QUrl &source) const |
Validates the XML instance document read from source against the schema. More... | |
bool | validate (QIODevice *source, const QUrl &documentUri=QUrl()) const |
Validates the XML instance document read from source with the given documentUri against the schema. More... | |
bool | validate (const QByteArray &data, const QUrl &documentUri=QUrl()) const |
Validates the XML instance document read from data with the given documentUri against the schema. More... | |
~QXmlSchemaValidator () | |
Destroys this QXmlSchemaValidator. More... | |
Properties | |
QXmlSchemaValidatorPrivate *const | d |
The QXmlSchemaValidator class validates XML instance documents against a W3C XML Schema.
The QXmlSchemaValidator class loads, parses an XML instance document and validates it against a W3C XML Schema that has been compiled with QXmlSchema.
The following example shows how to load a XML Schema from a local file, check whether it is a valid schema document and use it for validation of an XML instance document:
This class implements schema validation according to the XML Schema 1.0 specification.
Definition at line 62 of file qxmlschemavalidator.h.
QXmlSchemaValidator::QXmlSchemaValidator | ( | ) |
Constructs a schema validator.
The schema used for validation must be referenced in the XML instance document via the xsi:schemaLocation
or xsi:noNamespaceSchemaLocation
attribute.
Definition at line 90 of file qxmlschemavalidator.cpp.
QXmlSchemaValidator::QXmlSchemaValidator | ( | const QXmlSchema & | schema | ) |
Constructs a schema validator that will use schema for validation.
If an empty QXmlSchema schema is passed to the validator, the schema used for validation must be referenced in the XML instance document via the xsi:schemaLocation
or xsi:noNamespaceSchemaLocation
attribute.
Definition at line 101 of file qxmlschemavalidator.cpp.
QXmlSchemaValidator::~QXmlSchemaValidator | ( | ) |
QAbstractMessageHandler * QXmlSchemaValidator::messageHandler | ( | ) | const |
Returns the message handler that handles parsing and validation messages for this QXmlSchemaValidator.
Definition at line 290 of file qxmlschemavalidator.cpp.
Referenced by validate().
QXmlNamePool QXmlSchemaValidator::namePool | ( | ) | const |
Returns the name pool used by this QXmlSchemaValidator 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 233 of file qxmlschemavalidator.cpp.
QNetworkAccessManager * QXmlSchemaValidator::networkAccessManager | ( | ) | const |
Returns the network manager, or 0 if it has not been set.
Definition at line 344 of file qxmlschemavalidator.cpp.
Referenced by validate().
QXmlSchema QXmlSchemaValidator::schema | ( | ) | const |
Returns the schema that is used for validation.
Definition at line 241 of file qxmlschemavalidator.cpp.
void QXmlSchemaValidator::setMessageHandler | ( | QAbstractMessageHandler * | handler | ) |
Changes the QAbstractMessageHandler{message handler} for this QXmlSchemaValidator to handler.
The schema validator sends all parsing and validation messages to this message handler. QXmlSchemaValidator 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 QXmlSchemaValidator 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 281 of file qxmlschemavalidator.cpp.
void QXmlSchemaValidator::setNetworkAccessManager | ( | QNetworkAccessManager * | manager | ) |
Sets the network manager to manager.
QXmlSchemaValidator does not take ownership of manager.
Definition at line 334 of file qxmlschemavalidator.cpp.
void QXmlSchemaValidator::setSchema | ( | const QXmlSchema & | schema | ) |
Sets the schema that shall be used for further validation.
If the schema is empty, the schema used for validation must be referenced in the XML instance document via the xsi:schemaLocation
or xsi:noNamespaceSchemaLocation
attribute.
Definition at line 120 of file qxmlschemavalidator.cpp.
void QXmlSchemaValidator::setUriResolver | ( | const QAbstractUriResolver * | resolver | ) |
Sets the URI resolver to resolver.
QXmlSchemaValidator does not take ownership of resolver.
Definition at line 304 of file qxmlschemavalidator.cpp.
const QAbstractUriResolver * QXmlSchemaValidator::uriResolver | ( | ) | const |
Returns the schema's URI resolver.
If no URI resolver has been set, QtXmlPatterns will use the URIs in instance documents 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.
Definition at line 323 of file qxmlschemavalidator.cpp.
Referenced by validate().
bool QXmlSchemaValidator::validate | ( | const QUrl & | source | ) | const |
Validates the XML instance document read from source against the schema.
Returns true
if the XML instance document is valid according to the schema, false
otherwise.
Example:
Definition at line 156 of file qxmlschemavalidator.cpp.
Referenced by validate().
Validates the XML instance document read from source with the given documentUri against the schema.
Returns true
if the XML instance document is valid according to the schema, false
otherwise.
Example:
Definition at line 181 of file qxmlschemavalidator.cpp.
bool QXmlSchemaValidator::validate | ( | const QByteArray & | data, |
const QUrl & | documentUri = QUrl() |
||
) | const |
Validates the XML instance document read from data with the given documentUri against the schema.
Returns true
if the XML instance document is valid according to the schema, false
otherwise.
Example:
Definition at line 136 of file qxmlschemavalidator.cpp.
|
private |
Definition at line 88 of file qxmlschemavalidator.h.
Referenced by messageHandler(), namePool(), networkAccessManager(), schema(), setMessageHandler(), setNetworkAccessManager(), setSchema(), setUriResolver(), uriResolver(), validate(), and ~QXmlSchemaValidator().