QXmlSchema Class Reference

[ QtXmlPatterns module]

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

方法


详细描述

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:

     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.


方法文档编制

QXmlSchema.__init__ ( self )

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

QUrl QXmlSchema.documentUri ( self )

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

bool QXmlSchema.isValid ( self )

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 ( self , 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 ( self , QIODevice   source , 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 ( self , QByteArray   data , 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 is not a valid URI, behavior is undefined.

若模式 是无效的 , false 被返回且行为未定义。

范例:

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

另请参阅 isValid () and isValid ().

QAbstractMessageHandler QXmlSchema.messageHandler ( self )

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

另请参阅 setMessageHandler ().

QXmlNamePool QXmlSchema.namePool ( self )

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 ( self )

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

另请参阅 setNetworkAccessManager ().

QXmlSchema.setMessageHandler ( self , QAbstractMessageHandler   handler )

改变 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 。默认 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 错误。
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 ().

QXmlSchema.setNetworkAccessManager ( self , QNetworkAccessManager   networkmanager )

将网络管理器设为 manager . QXmlSchema does not take ownership of manager .

另请参阅 networkAccessManager ().

QXmlSchema.setUriResolver ( self , QAbstractUriResolver   resolver )

将 URI 解析器设为 resolver . QXmlSchema does not take ownership of resolver .

另请参阅 uriResolver ().

QAbstractUriResolver QXmlSchema.uriResolver ( self )

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.

另请参阅 setUriResolver ().