Version: 2.5.0
sdv.validators.schematron
Module¶
-
class
sdv.validators.schematron.
SchematronValidator
(schematron, phase=None)[source]¶ Performs schematron validation against an XML instance document.
Parameters: schematron – A Schematron document. This can be a filename, file-like object, etree._Element
, oretree._ElementTree
instance.-
validate
(doc)[source]¶ Validates an XML instance document doc using Schematron rules.
Parameters: doc – An XML instance document. This can be a filename, file-like object, etree._Element
oretree._ElementTree
instance.Returns: An instance of SchematronValidationResults
.Raises: ValidationError
– If there are any issues parsing doc.
-
-
class
sdv.validators.schematron.
SchematronValidationResults
(is_valid, doc=None, svrl_report=None)[source]¶ Bases:
sdv.validators.base.ValidationResults
Used to hold results of a Schematron validation process.
Parameters: - is_valid – The boolean validation result.
- doc – The document which produced these validation results.
- svrl_report – The etree._ElementTree SVRL report produced during the validation run.
-
errors
¶ A list of
SchematronError
instances representing errors found in the svrl_report.
-
is_valid
¶ Returns
True
if the validation was successful andFalse
otherwise.
-
as_dict
()[source]¶ A dictionary representation of the
SchematronValidationResults
instance.- Keys:
'result'
: The validation results. Values can beTrue
orFalse
.'errors'
: A list of validation error dictionaries. The keys are'message'
and'line'
.
Returns: A dictionary representation of an instance of this class.
-
as_json
()¶ Returns a JSON representation of this class instance.
-
is_valid
Returns
True
if the validation attempt was successful andFalse
otherwise.
-
class
sdv.validators.schematron.
SchematronError
(doc, error)[source]¶ Bases:
sdv.validators.base.ValidationError
Represents an error found in a SVRL report.
Parameters: - doc – The instance document which was validated and produced this error.
- error – The
svrl:failed-assert
orsvrl:successful-report
etree._Element
instance.
-
message
¶ The 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 in the input document associated with this error.
This property is lazily evaluated, meaning the line number isn’t known until the first time this property is accessed. Each subsequent call will return the cached line number.