我正在尝试用lxml做一些Schematron验证.对于我正在使用的特定应用程序,重要的是报告任何未通过验证的测试.所述LXML文档提到的存在validation_report属性对象.我认为这应该包含我正在寻找的信息,但我无法弄清楚如何使用它.这是一些演示我的问题的示例代码(改编自http://lxml.de/validation.html#id2 ;使用Python 2.7.4测试):
import StringIO
from lxml import isoschematron
from lxml import etree
def main():
# Schema
f = StringIO.StringIO('''\
<schema xmlns="http://purl.oclc.org/dsdl/schematron" >
<pattern id="sum_equals_100_percent">
<title>Sum equals 100%.</title>
<rule context="Total">
<assert test="sum(//Percent)=100">Sum is not 100%.</assert>
</rule>
</pattern>
</schema>
''')
# Parse schema
sct_doc = etree.parse(f)
schematron = isoschematron.Schematron(sct_doc, store_report = True)
# XML to validate - validation will fail because sum of numbers
# not equal to 100
notValid = StringIO.StringIO('''\
<Total>
<Percent>30</Percent> …Run Code Online (Sandbox Code Playgroud)