Version: 1.1.110

libtaxii.validation Module

class libtaxii.validation.SchemaValidator(schema_file)[source]

A helper class for TAXII Schema Validation.

Example

See validate_etree(...) for an example how to use this class

validate_etree(etree_xml)[source]

Validate an LXML etree with the specified schema_file.

Parameters:
  • etree_xml (etree) – The XML to validate.
  • schema_file (str) – The schema file to validate against
Returns:

A SchemaValidationResult object

Raises:

lxml.etree.XMLSyntaxError – When the XML to be validated is not well formed

Example

from libtaxii import messages_11
from libtaxii.validation import SchemaValidator, TAXII_11_SCHEMA
from lxml.etree import XMLSyntaxError

sv = SchemaValidator(TAXII_11_SCHEMA)

try:
   result = sv.validate_etree(some_etree)
   # Note that validate_string() and validate_file() can also be used
except XMLSyntaxError:
    # Handle this exception, which occurs when
    # some_xml_string is not valid XML (e.g., 'foo')

if not result.valid:
    for error in result.error_log:
        print error
    sys.exit(1)

# At this point, the XML is schema valid
do_something(some_xml_string)
validate_file(file_location)[source]

A wrapper for validate_etree. Parses file_location, turns it into an etree, then calls validate_etree( ... )

validate_string(xml_string)[source]

A wrapper for validate_etree. Parses xml_string, turns it into an etree, then calls validate_etree( ... )

libtaxii.validation.TAXII_10_SCHEMA Use TAXII 1.0 schema for validation.

Automatically-calculated path to the bundled TAXII 1.0 schema.

libtaxii.validation.TAXII_11_SCHEMA Use TAXII 1.1 schema for validation.

Automatically-calculated path to the bundled TAXII 1.1 schema.

class libtaxii.validation.TAXII10Validator[source]

Bases: libtaxii.validation.SchemaValidator

A SchemaValidator that uses the TAXII 1.0 Schemas

class libtaxii.validation.TAXII11Validator[source]

Bases: libtaxii.validation.SchemaValidator

A SchemaValidator that uses the TAXII 1.1 Schemas