QXmlSchema 類

QXmlSchema 類提供對 W3C XML 模式的加載和驗證。 更多...

頭: #include <QXmlSchema>
qmake: QT += xmlpatterns
Since: Qt 4.6

該類在 Qt 4.6 引入。

注意: 此類的所有函數 可重入 .

公共函數

QXmlSchema (const QXmlSchema & other )
QXmlSchema ()
QXmlSchema & operator= (const QXmlSchema & other )
~QXmlSchema ()
QUrl documentUri () const
bool isValid () const
bool load (const QUrl & source )
bool load (QIODevice * source , const QUrl & documentUri = QUrl())
bool load (const QByteArray & data , 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 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 模式版本

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

另請參閱 QXmlSchemaValidator and XML 模式驗證範例 .

成員函數文檔編製

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.

QXmlSchema:: QXmlSchema ()

Constructs an invalid, empty schema that cannot be used until load () 被調用。

QXmlSchema &QXmlSchema:: operator= (const QXmlSchema & other )

Copies the resources of other into this instance, sharing them to the extent possible.

該函數在 Qt 5.4 引入。

QXmlSchema:: ~QXmlSchema ()

銷毀此 QXmlSchema .

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 QUrl & source )

設置此 QXmlSchema to a schema loaded from the source URI.

若模式 是無效的 , false 被返迴且行為未定義。

範例:

    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";
					

另請參閱 isValid ().

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

設置此 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.

source is null 或不可讀,或者若 documentUri 不是有效 URI,行為未定義。

若模式 是無效的 , false 被返迴且行為未定義。

範例:

    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";
					

另請參閱 isValid ().

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

設置此 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.

documentUri 不是有效 URI,行為未定義。

若模式 是無效的 , false 被返迴且行為未定義。

範例:

    QByteArray data( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
                     "<xsd:schema"
                     "        xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\""
                     "        xmlns=\"http://www.qt-project.org/xmlschematest\""
                     "        targetNamespace=\"http://www.qt-project.org/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";
					

另請參閱 isValid () 和 isValid ().

QAbstractMessageHandler *QXmlSchema:: messageHandler () const

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

另請參閱 setMessageHandler ().

QXmlNamePool QXmlSchema:: namePool () const

Returns the name pool used by this QXmlSchema for constructing 名稱 . 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 0 if it has not been set.

另請參閱 setNetworkAccessManager ().

void QXmlSchema:: setMessageHandler ( QAbstractMessageHandler * handler )

改變 message handler 為此 QXmlSchema to handler . The schema sends all compile and validation messages to this message handler. QXmlSchema 未擁有所有權對於 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.

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

message() argument Semantics
QtMsgType type 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.

另請參閱 messageHandler ().

void QXmlSchema:: setNetworkAccessManager ( QNetworkAccessManager * manager )

將網絡管理器設為 manager . QXmlSchema 未擁有所有權對於 manager .

另請參閱 networkAccessManager ().

void QXmlSchema:: setUriResolver (const QAbstractUriResolver * resolver )

將 URI (統一資源標識符) 解析器設為 resolver . QXmlSchema 未擁有所有權對於 resolver .

另請參閱 uriResolver ().

const QAbstractUriResolver *QXmlSchema:: uriResolver () const

Returns the schema's URI resolver. If no URI resolver has been set, Qt XML Patterns 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 Qt XML Patterns 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.

另請參閱 setUriResolver ().