注意
该类在 Qt4.6 引入
PySide.QtXmlPatterns.QXmlSchema class provides loading and validation of a W3C XML Schema.
PySide.QtXmlPatterns.QXmlSchema class loads, compiles and validates W3C XML Schema files that can be used further for validation of XML instance documents via PySide.QtXmlPatterns.QXmlSchemaValidator .
The following example shows how to load a XML Schema file from the network and test whether it is a valid schema document:
url = QUrl("http://www.schema-example.org/myschema.xsd")
schema = QXmlSchema()
if schema.load(url):
qDebug("schema is valid")
else:
qDebug("schema is invalid")
This class is used to represent schemas that conform to the XML Schema 1.0 specification.
另请参阅
PySide.QtXmlPatterns.QXmlSchemaValidator XML 模式验证范例
| 参数: | other – PySide.QtXmlPatterns.QXmlSchema |
|---|
Constructs an invalid, empty schema that cannot be used until PySide.QtXmlPatterns.QXmlSchema.load() 被调用。
构造 PySide.QtXmlPatterns.QXmlSchema that is a copy of other . The new instance will share resources with the existing schema to the extent possible.
| 返回类型: | PySide.QtCore.QUrl |
|---|
Returns the document URI of the schema or an empty URI if no schema has been set.
| 返回类型: | PySide.QtCore.bool |
|---|
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.
| 参数: |
|
|---|---|
| 返回类型: |
PySide.QtCore.bool |
设置此 PySide.QtXmlPatterns.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,行为未定义。
若模式 is invalid , false 被返回且行为未定义。
范例:
file = QFile("myschema.xsd")
file.open(QIODevice.ReadOnly)
schema = QXmlSchema()
schema.load(file, QUrl.fromLocalFile(file.fileName()))
if schema.isValid():
qDebug("schema is valid")
else:
qDebug("schema is invalid")
| 参数: |
|
|---|---|
| 返回类型: |
PySide.QtCore.bool |
设置此 PySide.QtXmlPatterns.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,行为未定义。
若模式 is invalid , false 被返回且行为未定义。
范例:
data = QByteArray("<?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>" )
schema = QXmlSchema()
schema.load(data)
if schema.isValid():
qDebug("schema is valid")
else:
qDebug("schema is invalid")
| 参数: | source – PySide.QtCore.QUrl |
|---|---|
| 返回类型: | PySide.QtCore.bool |
设置此 PySide.QtXmlPatterns.QXmlSchema to a schema loaded from the source URI.
若模式 is invalid , false 被返回且行为未定义。
范例:
url = QUrl("http://www.schema-example.org/myschema.xsd")
schema = QXmlSchema()
if schema.load(url):
qDebug("schema is valid")
else:
qDebug("schema is invalid")
| 返回类型: | PySide.QtXmlPatterns.QAbstractMessageHandler |
|---|
Returns the message handler that handles compile and validation messages for this PySide.QtXmlPatterns.QXmlSchema .
| 返回类型: | PySide.QtXmlPatterns.QXmlNamePool |
|---|
Returns the name pool used by this PySide.QtXmlPatterns.QXmlSchema for constructing names . There is no setter for the name pool, because mixing name pools causes errors due to name confusion.
| 返回类型: | PySide.QtNetwork.QNetworkAccessManager |
|---|
Returns the network manager, or 0 if it has not been set.
| 参数: | handler – PySide.QtXmlPatterns.QAbstractMessageHandler |
|---|
改变 message handler for this PySide.QtXmlPatterns.QXmlSchema to handler . The schema sends all compile and validation messages to this message handler. PySide.QtXmlPatterns.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.
当 PySide.QtXmlPatterns.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 PySide.QtCore.QString & description | An XHTML document which is the actual message. It is translated into the current language. |
| const PySide.QtCore.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 PySide.QtXmlPatterns.QSourceLocation & sourceLocation | Identifies where the error occurred. |
| 参数: | networkmanager – PySide.QtNetwork.QNetworkAccessManager |
|---|
将网络管理器设为 manager . PySide.QtXmlPatterns.QXmlSchema 未拥有所有权对于 manager .
| 参数: | resolver – PySide.QtXmlPatterns.QAbstractUriResolver |
|---|
将 URI 解析器设为 resolver . PySide.QtXmlPatterns.QXmlSchema 未拥有所有权对于 resolver .
| 返回类型: | PySide.QtXmlPatterns.QAbstractUriResolver |
|---|
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.
当 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.