Version: 2.5.0
sdv.validators.xml_schema
Module¶
-
class
sdv.validators.xml_schema.
XmlSchemaValidator
(schema_dir=None)[source]¶ Validates XML instance documents.
Note
If validating against a single XML schema document, use
lxml.etree.XMLSchema
instead.Parameters: schema_dir – A directory of schema files used to validate XML instance documents. -
OVERRIDE_SCHEMALOC
¶ Overrides the schemalocation for a given namespace that may be discovered when walking schema_dir. This does not alter the schemalocation of namespaces declared by
xsi:schemalLocation
attributes if validating viaxsi:schemaLocation
.
-
validate
(doc, schemaloc=False)[source]¶ Validates an XML instance document.
Parameters: - doc – An XML instance document. This can be a filename, file-like
object,
etree._Element
, oretree._ElementTree
. - schemaloc – If
True
, the document will be validated using thexsi:schemaLocation
attribute found on the instance document root.
Returns: An instance of
XmlValidationResults
.Raises: ValidationError
– If the class was not initialized with a schema directory and schemaloc isFalse
or if there are any issues parsing doc.XMLSchemaIncludeError
– If an error occurs while processing the schemas required for validation.XMLSchemaIncludeError
– If an error occurs while processingxs:include
directives.
- doc – An XML instance document. This can be a filename, file-like
object,
-
-
class
sdv.validators.xml_schema.
XmlValidationResults
(is_valid, errors=None)[source]¶ Results of XML schema validation. Returned from
XmlSchemaValidator.validate()
.Parameters: - is_valid – The validation result.
- errors – A list of strings reported from the XML validation engine.
-
is_valid
¶ True
if the validation was successful andFalse
otherwise.
-
as_dict
()[source]¶ A dictionary representation of the
XmlValidationResults
instance.- Keys:
'result'
: The validation results (True
orFalse
)'errors'
: A list of validation errors.
Returns: A dictionary representation of an instance of this class.
-
as_json
()¶ Returns a JSON representation of this class instance.
-
errors
¶ “A list of
XmlSchemaError
validation errors.
-
is_valid
Returns
True
if the validation attempt was successful andFalse
otherwise.
-
class
sdv.validators.xml_schema.
XmlSchemaError
(error)[source]¶ Represents an XML Schema validation error.
Parameters: error – An error returned from etree
XML Schema validation error log.-
message
¶ The XML validation error message.
-
as_dict
()[source]¶ Returns a dictionary representation.
- Keys:
'message'
: The error message'line'
: The line number associated with the error
-
as_json
()¶ Returns a JSON representation of this class instance.
-
line
¶ Returns the line number associated with the error.
-