class Schematron(_etree._Validator): (source)
An ISO Schematron validator. Pass a root Element or an ElementTree to turn it into a validator. Alternatively, pass a filename as keyword argument 'file' to parse from the file system. Schematron is a less well known, but very powerful schema language. The main idea is to use the capabilities of XPath to put restrictions on the structure and the content of XML documents. The standard behaviour is to fail on ``failed-assert`` findings only (``ASSERTS_ONLY``). To change this, you can either pass a report filter function to the ``error_finder`` parameter (e.g. ``ASSERTS_AND_REPORTS`` or a custom ``XPath`` object), or subclass isoschematron.Schematron for complete control of the validation process. Built on the Schematron language 'reference' skeleton pure-xslt implementation, the validator is created as an XSLT 1.0 stylesheet using these steps: 0) (Extract from XML Schema or RelaxNG schema) 1) Process inclusions 2) Process abstract patterns 3) Compile the schematron schema to XSLT The ``include`` and ``expand`` keyword arguments can be used to switch off steps 1) and 2). To set parameters for steps 1), 2) and 3) hand parameter dictionaries to the keyword arguments ``include_params``, ``expand_params`` or ``compile_params``. For convenience, the compile-step parameter ``phase`` is also exposed as a keyword argument ``phase``. This takes precedence if the parameter is also given in the parameter dictionary. If ``store_schematron`` is set to True, the (included-and-expanded) schematron document tree is stored and available through the ``schematron`` property. If ``store_xslt`` is set to True, the validation XSLT document tree will be stored and can be retrieved through the ``validator_xslt`` property. With ``store_report`` set to True (default: False), the resulting validation report document gets stored and can be accessed as the ``validation_report`` property. Here is a usage example:: >>> from lxml import etree >>> from lxml.isoschematron import Schematron >>> schematron = Schematron(etree.XML(''' ... <schema xmlns="http://purl.oclc.org/dsdl/schematron" > ... <pattern id="id_only_attribute"> ... <title>id is the only permitted attribute name</title> ... <rule context="*"> ... <report test="@*[not(name()='id')]">Attribute ... <name path="@*[not(name()='id')]"/> is forbidden<name/> ... </report> ... </rule> ... </pattern> ... </schema>'''), ... error_finder=Schematron.ASSERTS_AND_REPORTS) >>> xml = etree.XML(''' ... <AAA name="aaa"> ... <BBB id="bbb"/> ... <CCC color="ccc"/> ... </AAA> ... ''') >>> schematron.validate(xml) False >>> xml = etree.XML(''' ... <AAA id="aaa"> ... <BBB id="bbb"/> ... <CCC/> ... </AAA> ... ''') >>> schematron.validate(xml) True
Method | __call__ |
Validate doc using Schematron. |
Method | __init__ |
Undocumented |
Constant | ASSERTS |
Undocumented |
Property | schematron |
ISO-schematron schema document (None if object has been initialized with store_schematron=False). |
Property | validation |
ISO-schematron validation result report (None if result-storing has been turned off). |
Property | validator |
ISO-schematron skeleton implementation XSLT validator document (None if object has been initialized with store_xslt=False). |
Method | _extract |
Extract embedded schematron schema from non-schematron host schema. This method will only be called by __init__ if the given schema document is not a schematron schema by itself. Must return a schematron schema document tree or None. |
Instance Variable | _schematron |
Undocumented |
Instance Variable | _store |
Undocumented |
Instance Variable | _validation |
Undocumented |
Instance Variable | _validation |
Undocumented |
Instance Variable | _validator |
Undocumented |
Instance Variable | _validator |
Undocumented |
Undocumented
Undocumented
Value |
|
ISO-schematron skeleton implementation XSLT validator document (None if object has been initialized with store_xslt=False).