A helper class for TAXII Schema Validation.
Example
See validate_etree(...) for an example how to use this class
Validate an LXML etree with the specified schema_file.
Parameters: |
|
---|---|
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)
A wrapper for validate_etree. Parses file_location, turns it into an etree, then calls validate_etree( ... )
A wrapper for validate_etree. Parses xml_string, turns it into an etree, then calls validate_etree( ... )
Automatically-calculated path to the bundled TAXII 1.0 schema.
Automatically-calculated path to the bundled TAXII 1.1 schema.
Bases: libtaxii.validation.SchemaValidator
A SchemaValidator that uses the TAXII 1.0 Schemas
Bases: libtaxii.validation.SchemaValidator
A SchemaValidator that uses the TAXII 1.1 Schemas