QXmlSchema

Note

This class was introduced in Qt 4.6

Synopsis

Functions

Detailed Description

The PySide.QtXmlPatterns.QXmlSchema class provides loading and validation of a W3C XML Schema.

The 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")

XML Schema Version

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

See also

PySide.QtXmlPatterns.QXmlSchemaValidator XML Schema Validation Example

class PySide.QtXmlPatterns.QXmlSchema
class PySide.QtXmlPatterns.QXmlSchema(other)
Parameters:otherPySide.QtXmlPatterns.QXmlSchema

Constructs an invalid, empty schema that cannot be used until PySide.QtXmlPatterns.QXmlSchema.load() is called.

Constructs a PySide.QtXmlPatterns.QXmlSchema that is a copy of other . The new instance will share resources with the existing schema to the extent possible.

PySide.QtXmlPatterns.QXmlSchema.documentUri()
Return type:PySide.QtCore.QUrl

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

PySide.QtXmlPatterns.QXmlSchema.isValid()
Return type: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.QtXmlPatterns.QXmlSchema.load(source[, documentUri=QUrl()])
Parameters:
Return type:

PySide.QtCore.bool

Sets this 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.

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.

Example:

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.QtXmlPatterns.QXmlSchema.load(data[, documentUri=QUrl()])
Parameters:
Return type:

PySide.QtCore.bool

Sets this 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.

If documentUri is not a valid URI, behavior is undefined.

If the schema is invalid , false is returned and the behavior is undefined.

Example:

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")
PySide.QtXmlPatterns.QXmlSchema.load(source)
Parameters:sourcePySide.QtCore.QUrl
Return type:PySide.QtCore.bool

Sets this PySide.QtXmlPatterns.QXmlSchema to a schema loaded from the source URI.

If the schema is invalid , false is returned and the behavior is undefined.

Example:

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.QXmlSchema.messageHandler()
Return type:PySide.QtXmlPatterns.QAbstractMessageHandler

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

PySide.QtXmlPatterns.QXmlSchema.namePool()
Return type: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.QtXmlPatterns.QXmlSchema.networkAccessManager()
Return type:PySide.QtNetwork.QNetworkAccessManager

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

PySide.QtXmlPatterns.QXmlSchema.setMessageHandler(handler)
Parameters:handlerPySide.QtXmlPatterns.QAbstractMessageHandler

Changes the message handler for this PySide.QtXmlPatterns.QXmlSchema to handler . The schema sends all compile and validation messages to this message handler. PySide.QtXmlPatterns.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 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.
PySide.QtXmlPatterns.QXmlSchema.setNetworkAccessManager(networkmanager)
Parameters:networkmanagerPySide.QtNetwork.QNetworkAccessManager

Sets the network manager to manager . PySide.QtXmlPatterns.QXmlSchema does not take ownership of manager .

PySide.QtXmlPatterns.QXmlSchema.setUriResolver(resolver)
Parameters:resolverPySide.QtXmlPatterns.QAbstractUriResolver

Sets the URI resolver to resolver . PySide.QtXmlPatterns.QXmlSchema does not take ownership of resolver .

PySide.QtXmlPatterns.QXmlSchema.uriResolver()
Return type: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.

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.