![]() |
CopperSpice API
1.9.2
|
The QXmlSchema class provides loading and validation of a W3C XML Schema. More...
Public Methods | |
QXmlSchema () | |
QXmlSchema (const QXmlSchema &other) = default | |
~QXmlSchema () | |
QUrl | documentUri () const |
bool | isValid () const |
bool | load (const QByteArray &data, const QUrl &documentUri=QUrl ()) |
bool | load (const QUrl &source) |
bool | load (QIODevice *source, const QUrl &documentUri=QUrl ()) |
QAbstractMessageHandler * | messageHandler () const |
QXmlNamePool | namePool () const |
QNetworkAccessManager * | networkAccessManager () const |
void | setMessageHandler (QAbstractMessageHandler *handler) |
void | setNetworkAccessManager (QNetworkAccessManager *manager) |
void | setUriResolver (const QAbstractUriResolver *resolver) |
const QAbstractUriResolver * | uriResolver () const |
The QXmlSchema class provides loading and validation of a W3C XML Schema.
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:
This class is used to represent schemas that conform to the XML Schema 1.0 specification.
QXmlSchema::QXmlSchema | ( | ) |
Constructs an invalid, empty schema that can not be used until load() is called.
QXmlSchema::~QXmlSchema | ( | ) |
Destroys this QXmlSchema.
|
default |
Constructs a QXmlSchema that is a copy of other. The new instance will share resources with the existing schema to the extent possible.
QUrl QXmlSchema::documentUri | ( | ) | const |
Returns the document URI of the schema or an empty URI if no schema has been set.
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.
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.
If the schema is invalid, false
is returned and the behavior is undefined.
bool QXmlSchema::load | ( | const QUrl & | source | ) |
Sets this QXmlSchema to a schema loaded from the source URI. If the schema is invalid, false
is returned and the behavior is undefined.
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 is invalid, false
is returned and the behavior is undefined.
QAbstractMessageHandler * QXmlSchema::messageHandler | ( | ) | const |
Returns the message handler that handles compile and validation messages for this QXmlSchema.
QXmlNamePool QXmlSchema::namePool | ( | ) | const |
Returns the name pool used by this QXmlSchema for constructing names. There is no setter for the name pool, because mixing name pools causes errors due to name confusion.
QNetworkAccessManager * QXmlSchema::networkAccessManager | ( | ) | const |
Returns the network manager or a nullptr if it has not been set.
void QXmlSchema::setMessageHandler | ( | QAbstractMessageHandler * | handler | ) |
Changes the 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. |
void QXmlSchema::setNetworkAccessManager | ( | QNetworkAccessManager * | manager | ) |
Sets the network manager to manager. QXmlSchema does not take ownership of manager.
void QXmlSchema::setUriResolver | ( | const QAbstractUriResolver * | resolver | ) |
Sets the URI resolver to resolver. QXmlSchema does not take ownership of resolver.
const QAbstractUriResolver * QXmlSchema::uriResolver | ( | ) | const |
Returns the schema's URI resolver. If no URI resolver has been set, CsXmlPatterns 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 CsXmlPatterns 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.