Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python lxml的schematron报告问题_Python_Lxml_Schematron - Fatal编程技术网

python lxml的schematron报告问题

python lxml的schematron报告问题,python,lxml,schematron,Python,Lxml,Schematron,我正在使用lxml schematron模块验证xml文档。它工作得很好,但我无法显示验证报告,它被设置为属性。我找不到如何将其作为XML树进行处理 下面是我使用的代码片段: xdoc = etree.parse("mydoc.xml") # schematron code removed for clarity f = StringIO.StringIO('''<schema>...</schema>''') sdoc = etree.parse(f) schematr

我正在使用lxml schematron模块验证xml文档。它工作得很好,但我无法显示验证报告,它被设置为属性。我找不到如何将其作为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  
xdoc=etree.parse(“mydoc.xml”)
#为清晰起见,已删除schematron代码
f=StringIO.StringIO(“”…“”)
sdoc=etree.parse(f)
schematron=isoschematron.schematron(sdoc,store\u schematron=True,store\u xslt=True,store\u report=True)
如果schematron.validate(xdoc):
打印“确定”
其他:
tprint“ko”
报告=isoschematron.Schematron.validation\u报告
>>>类型(报告)
>>>处长(报告)
[''类''''''''''''''''''''''''''.'删除''.''.'文档'.''.'格式'.''.'获取'.''.',
“\uuuu getattribute”、“\uuuu hash”、“\uuuu init”、“\uuu new”、“\uuu reduce”、“\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu,
"报告","集合","设置属性","大小","str","子类钩子",,
'deleter'、'fdel'、'fget'、'fset'、'getter'、'setter']
>>>报告__
'ISO schematron验证结果报告(如果结果存储已关闭,则无)。\n

关于这一点,lxml文档并不清楚。有人能帮我获取xml报表树吗?

您需要将Schematron类“store\u report
\u init\u(…)
参数设置为True(默认值:False)

在这一点上,文档非常清楚,请参见。 或


到这里来的人可能也想看看下面的问题;第一个答案提供了一个非常清晰的示例,说明了如何使Schematron报告工作(发布这篇文章是因为我找不到任何工作示例,并且我发现lxml文档也有些混乱)。下面是:


嗯。。。我的样本就是这样,太好了。这就解决了问题。我用report=schematron.validation\u报告替换了report init,它就完成了。
>>> 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.