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.XMLSchemainstead.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:schemalLocationattributes 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:schemaLocationattribute 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 isFalseor 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:includedirectives.
- 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¶ Trueif the validation was successful andFalseotherwise.
-
as_dict()[source]¶ A dictionary representation of the
XmlValidationResultsinstance.- Keys:
'result': The validation results (TrueorFalse)'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
XmlSchemaErrorvalidation errors.
-
is_valid Returns
Trueif the validation attempt was successful andFalseotherwise.
-
class
sdv.validators.xml_schema.XmlSchemaError(error)[source]¶ Represents an XML Schema validation error.
Parameters: error – An error returned from etreeXML 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.
-