gws.lib.xmlx.validator

XML schema validator for tests.

Source code: gws.lib.xmlx.validator

Module Contents

exception gws.lib.xmlx.validator.Error(*args, **kwargs)

Bases: gws.Error

Validation or schema error, with message and lineno.

lineno
message
gws.lib.xmlx.validator.validate(xml: str | bytes) → bool

Validate a document against the schemas listed in its xsi:schemaLocation.

Remote schemas are downloaded and cached under gws.c.CACHE_DIR; URLs containing .loc or local are downloaded without caching.

Parameters:

xml – The document as a string or bytes.

Returns:

True if the document is valid.

Raises:

Error – If the document or a schema cannot be parsed, or the document is invalid.