我正在用lxmlschematron模块验证xml文档。它工作得很好,但是我不能显示validation报告,它被设置为一个属性。我找不到如何将其作为XML树处理。在
下面是我使用的代码片段:
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报告吗?在
您需要将Schematron类的store\u report
__init__(...)
参数设置为True(默认值:False)。在IMHO文档在这一点上非常清楚,参见例如http://lxml.de/api/lxml.isoschematron.Schematron-class.html 或者
最后来到这里的人可能还想看看下面的问题;第一个答案提供了一个非常清楚的例子,说明了如何让Schematron报告工作(发布这个是因为我找不到任何有效的示例,而且我发现lxml文档也有点混乱)。接下来是:
Schematron validation with lxml in Python: how to retrieve validation errors?
相关问题 更多 >
编程相关推荐