我嘗試使用Schematron驗證文檔。我使用schema for ISOSTS standard。SchematronParseError:無效schematron架構(對於ISOSTS架構)
from lxml import etree
from lxml.isoschematron import Schematron
def validate(self, filename: str):
file = open(filename)
schema_filename = join('/path/to/ISOSTS_validation.sch')
schema_file = open(schema_filename)
# fixme it works. But fails with ISOSTS scheme
# schema_file = 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>
# ''')
sct_doc = etree.parse(schema_file)
schematron = Schematron(sct_doc) ## <- FAIL !!!
doc = etree.parse(file)
result = schematron.validate(doc)
file.close()
schema_file.close()
return result
validate('/path/to/feature_doc.xml')
錯誤消息:
File "/var/www/.../venv/lib/python3.5/site-packages/lxml/isoschematron/__init__.py", line 279, in __init__
schematron_schema_valid.error_log)
lxml.etree.SchematronParseError: invalid schematron schema: <string>:553:0:ERROR:RELAXNGV:RELAXNG_ERR_EXTRACONTENT: Element function has extra content: param
<string>:560:0:ERROR:RELAXNGV:RELAXNG_ERR_ELEMNAME: Expecting element schema, got variable
<string>:0:0:ERROR:RELAXNGV:RELAXNG_ERR_INTEREXTRA: Extra element function in interleave
<string>:42:0:ERROR:RELAXNGV:RELAXNG_ERR_CONTENTVALID: Element schema failed to validate content
如何修復呢?