Version: 2.3.0

sdv Module

sdv.validate_xml(doc, version=None, schemas=None, schemaloc=False, klass=None)[source]

Performs XML Schema validation against a STIX or CybOX document.

Parameters:
  • doc – A STIX/CybOX document to validate. This can be a filename, file-like object, etree._Element or etree._ElementTree object.
  • version – The version of the STIX/CybOX document being validated. If None an attempt will be made to extract the version from doc.
  • schemas – A string path to a directory of STIX/CybOX schemas. If None, the validation code will leverage its bundled STIX/CybOX schemas.
  • schemaloc – Use xsi:schemaLocation attribute on doc to perform validation.
  • klassInternal use only. The validator klass to use for validating doc.

Note

The first time running this for a given schemas (or no schemas) will take longer than following validation runs due to schema compilation time.

Returns:

An instance of XmlValidationResults.

Raises:
  • IOError – If doc is not a valid XML document or there is an issue processing schemas.
  • UnknownSTIXVersionError – If version is None and doc does not contain a @version attribute value.
  • UnknownCyboxVersionError – If version is None and doc does not contain CybOX version information.
  • InvalidSTIXVersionError – If version or the version attribute in doc contains an invalid STIX version number.
  • InvalidCyboxVersionError – if version or the version information on doc contain an invalid CybOX version number.
  • ValidationError – If the class was not initialized with a schema directory and schemaloc is False.
  • XMLSchemaImportError – If an error occurs while processing the schemas required for validation.
  • XMLSchemaIncludeError – If an error occurs while processing xs:include directives.
sdv.validate_best_practices(doc, version=None)[source]

Performs Best Practices validation against a STIX document.

Note

This should be used together with validate_xml() since this only checks best practices and not schema-conformance.

Parameters:
  • doc – A STIX document to validate. This can be a filename, file-like object, etree._Element or etree._ElementTree object.
  • version – The version of the STIX document being validated. If None an attempt will be made to extract the version from doc.
Returns:

An instance of BestPracticeValidationResults.

Raises:
  • IOError – If doc is not a valid XML document.
  • ValidationError – If doc is not a well-formed STIX document.
  • UnknownSTIXVersionError – If version is None and doc does not contain version information.
  • InvalidSTIXVersionError – If version or the @version attribute in doc contains an invalid STIX version number.
sdv.validate_profile(doc, profile)[source]

Performs STIX Profile validation against a STIX document.

Note

This should be used together with validate_xml() since this only checks profile-conformance and not schema-conformance.

Parameters:
  • doc – A STIX document to validate. This can be a filename, file-like object, etree._Element or etree._ElementTree object.
  • profile – A filename to a STIX Profile document.
Returns:

An instance of ProfileValidationResults.

Raises:
  • IOError – If doc is not a valid XML document.
  • ValidationError – If the input document is not a well-formed STIX document.
  • ProfileParseError – If an error occurred while attempting to parse the profile.
sdv.profile_to_schematron(profile)[source]

Converts the STIX Profile profile into a Schematron representation.

Parameters:profile – A filename to a STIX Profile document.
Returns:An etree._ElementTree Schematron representation of profile.
Raises:ProfileParseError – If an error occurred while attempting to parse the profile.
sdv.profile_to_xslt(profile)[source]

Converts the STIX Profile profile into an XSLT representation.

Parameters:profile – A filename to a STIX Profile document.
Returns:An etree._ElementTree XSLT representation of profile.
Raises:ProfileParseError – If an error occurred while attempting to parse the profile.