QXmlSchemaValidator¶
The
QXmlSchemaValidatorclass validates XML instance documents against a W3C XML Schema. More…

New in version 4.6.
Synopsis¶
Functions¶
def
messageHandler()def
namePool()def
networkAccessManager()def
schema()def
setMessageHandler(handler)def
setNetworkAccessManager(networkmanager)def
setSchema(schema)def
setUriResolver(resolver)def
uriResolver()def
validate(data[, documentUri=QUrl()])def
validate(source)def
validate(source[, documentUri=QUrl()])
Detailed Description¶
The
QXmlSchemaValidatorclass loads, parses an XML instance document and validates it against a W3C XML Schema that has been compiled withQXmlSchema.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:
schemaUrl = QUrl("file:///home/user/schema.xsd") schema = QXmlSchema() schema.load(schemaUrl) if schema.isValid(): file = QFile("test.xml") file.open(QIODevice.ReadOnly) validator = QXmlSchemaValidator(schema) if validator.validate(file, QUrl.fromLocalFile(file.fileName())): print "instance document is valid" else: print "instance document is invalid" }
XML Schema Version¶
This class implements schema validation according to the XML Schema 1.0 specification.
See also
-
class
QXmlSchemaValidator¶ QXmlSchemaValidator(schema)
- param schema
Constructs a schema validator. The schema used for validation must be referenced in the XML instance document via the
xsi:schemaLocationorxsi:noNamespaceSchemaLocationattribute.
-
PySide2.QtXmlPatterns.QXmlSchemaValidator.messageHandler()¶ - Return type
Returns the message handler that handles parsing and validation messages for this
QXmlSchemaValidator.See also
-
PySide2.QtXmlPatterns.QXmlSchemaValidator.namePool()¶ - Return type
Returns the name pool used by this
QXmlSchemaValidatorfor constructingnames. There is no setter for the name pool, because mixing name pools causes errors due to name confusion.
-
PySide2.QtXmlPatterns.QXmlSchemaValidator.networkAccessManager()¶ - Return type
QNetworkAccessManager
Returns the network manager, or 0 if it has not been set.
See also
-
PySide2.QtXmlPatterns.QXmlSchemaValidator.schema()¶ - Return type
QXmlSchema*
Returns the schema that is used for validation.
See also
-
PySide2.QtXmlPatterns.QXmlSchemaValidator.setMessageHandler(handler)¶ - Parameters
handler –
QAbstractMessageHandler
Changes the
message handlerfor thisQXmlSchemaValidatortohandler. The schema validator sends all parsing and validation messages to this message handler.QXmlSchemaValidatordoes not take ownership ofhandler.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
QXmlSchemaValidatorcallsmessage(), the arguments are as follows:message() argument
Semantics
QtMsgTypetypeOnly
QtWarningMsgandQtFatalMsgare used. The former identifies a warning, while the latter identifies an error.const
QString& descriptionAn XHTML document which is the actual message. It is translated into the current language.
const
QUrl&identifierIdentifies the error with a URI, where the fragment is the error code, and the rest of the URI is the error namespace.
const
QSourceLocation& sourceLocationIdentifies where the error occurred.
See also
-
PySide2.QtXmlPatterns.QXmlSchemaValidator.setNetworkAccessManager(networkmanager)¶ - Parameters
networkmanager –
QNetworkAccessManager
Sets the network manager to
manager.QXmlSchemaValidatordoes not take ownership ofmanager.See also
-
PySide2.QtXmlPatterns.QXmlSchemaValidator.setSchema(schema)¶ - Parameters
schema –
QXmlSchema
Sets the
schemathat 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 thexsi:schemaLocationorxsi:noNamespaceSchemaLocationattribute.See also
-
PySide2.QtXmlPatterns.QXmlSchemaValidator.setUriResolver(resolver)¶ - Parameters
resolver –
QAbstractUriResolver
Sets the URI resolver to
resolver.QXmlSchemaValidatordoes not take ownership ofresolver.See also
-
PySide2.QtXmlPatterns.QXmlSchemaValidator.uriResolver()¶ - Return type
Returns the schema’s URI resolver. If no URI resolver has been set, Qt XML Patterns 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 Qt XML Patterns calls
resolve()the absolute URI is the URI mandated by the schema specification, and the relative URI is the URI specified by the user.See also
-
PySide2.QtXmlPatterns.QXmlSchemaValidator.validate(source[, documentUri=QUrl()])¶ - Parameters
source –
QIODevicedocumentUri –
QUrl
- Return type
bool
-
PySide2.QtXmlPatterns.QXmlSchemaValidator.validate(data[, documentUri=QUrl()]) - Parameters
data –
QByteArraydocumentUri –
QUrl
- Return type
bool
-
PySide2.QtXmlPatterns.QXmlSchemaValidator.validate(source) - Parameters
source –
QUrl- Return type
bool
Validates the XML instance document read from
sourceagainst the schema.Returns
trueif the XML instance document is valid according to the schema,falseotherwise.Example:
schema = getSchema() url = QUrl("http://www.schema-example.org/test.xml") validator = QXmlSchemaValidator(schema) if validator.validate(url): print "instance document is valid" else: print "instance document is invalid"
© 2018 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.