Schematron release post with python lxml
I am checking xml docs with lxml schematron module. It works well, but I cannot display the validation report that is set as a property. I can't seem to find how to handle it as an XML tree.
Here is the piece of code I am using:
xdoc = etree.parse("mydoc.xml")
# schematron code removed for clarity
f = StringIO.StringIO('''<schema>...</schema>''')
sdoc = etree.parse(f)
schematron = isoschematron.Schematron(sdoc, store_schematron=True, store_xslt=True, store_report=True)
if schematron.validate(xdoc):
print "ok"
else:
tprint "ko"
report = isoschematron.Schematron.validation_report
>>> type(report)
<type 'property'>
>>> dir(report)
['__class__', '__delattr__', '__delete__', '__doc__', '__format__', '__get__',
'__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__',
'__repr__', '__set__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__',
'deleter', 'fdel', 'fget', 'fset', 'getter', 'setter']
>>> report.__doc__
'ISO-schematron validation result report (None if result-storing has\n been turned off).\n
The lxml documentation is unclear on this issue. Can anyone help me get the xml report tree?
You need to set the "store_report" parameter __init__(...)
of the Schematron class to True (default: False).
IMHO the documentation is pretty self-explanatory at this point, see for example http://lxml.de/api/lxml.isoschematron.Schematron-class.html or
>>> help(Schematron):
class Schematron(lxml.etree._Validator)
| An ISO Schematron validator.
|
| ...
| With ``store_report`` set to True (default: False), the resulting validation
| report document gets stored and can be accessed as the ``validation_report``
| property.
People who happen to be here may also want to take a look at the question below; the first answer gives a pretty clear example of how to make Schematron work (posting this because I couldn't find any working examples and I found the lxml documentation to be somewhat confusing as well). Here:
Schematron validation with lxml in Python: how to get validation errors?