python lxml的schematron报告问题 [英] schematron report issue with python lxml

查看:77
本文介绍了python lxml的schematron报告问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用lxml schematron模块验证xml文档.它工作正常,但我无法显示设置为属性的验证报告.我找不到如何将其作为XML树进行处理.

I'm validating xml documents with the lxml schematron module. It works well but I can't display the validation report, which is set as a property. I can't find how to process it as an XML tree.

这是我使用的代码段:

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  

关于这点,lxml文档尚不清楚.有人可以帮助我获取xml报告树吗?

The lxml documentation is not clear on this point. Can somebody help me getting the xml report tree?

推荐答案

您需要将Schematron类的store_report __init__(...)参数设置为True(默认值:False).

You need to set the Schematron class' store_report __init__(...) parameter to True (default: False).

恕我直言,文档在这一点上非常清晰,例如 http://lxml.de/api/lxml.isoschematron.Schematron-class.html

IMHO the documentation is pretty clear on this point, see e.g. 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.

这篇关于python lxml的schematron报告问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆