我正在尝试通过使用一组包含其他模式的模式来验证 xml。
主要架构师:
<?xml version="1.0" encoding="UTF-8"?>
<sch:schema xmlns="http://purl.oclc.org/dsdl/schematron"
xmlns:sch="http://purl.oclc.org/dsdl/schematron"
xmlns:sh="http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader"
xmlns:ef="http://www.efatura.gov.tr/envelope-namespace">
<sch:include href="UBL-TR_Codelist.sch#codes"/>
<sch:include href="UBL-TR_Common_Schematron.sch#abstracts"/>
<sch:ns prefix="sh" uri="http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader" />
<sch:ns prefix="ef" uri="http://www.efatura.gov.tr/package-namespace" />
<!-- .... -->
<sch:pattern id="document">
<sch:rule context="sh:StandardBusinessDocument">
<sch:extends rule="DocumentCheck"/>
</sch:rule>
</sch:pattern>
</sch:schema>
常见的schmatron:
<sch:schema xmlns="http://purl.oclc.org/dsdl/schematron"
xmlns:sch="http://purl.oclc.org/dsdl/schematron">
<sch:pattern name="AbstractRules" id="abstracts">
<sch:p>Pattern for storing abstract rules</sch:p>
<!-- Rule to validate StandardBusinessDocument -->
<sch:rule abstract="true" id="DocumentCheck">
<sch:assert test="sh:StandardBusinessDocumentHeader">sh:StandardBusinessDocumentHeader zorunlu bir elemandır.</sch:assert>
<sch:assert test="ef:Package">ef:Package zorunlu bir elemandır.</sch:assert>
</sch:rule>
</sch:pattern>
</sch:schema>
问题是,在主模式中,如果我直接放置一个断言标签,例如:
<assert test="sum(//Percent)=100">Sum is not 100%.</assert>
在“规则”标签之间,像这样:
<sch:pattern id="document">
<sch:rule context="sh:StandardBusinessDocument">
<assert test="sum(//Percent)=100">Sum is not 100%.</assert>
</sch:rule>
</sch:pattern>
比 etree 的 isoschematron.Schematron 类验证我的主要 schematron。否则它会抛出这样的错误:
Traceback (most recent call last):
File "C:\SUNUCU\validate\v.py", line 102, in <module>
schematron = etree.Schematron(s)
File "schematron.pxi", line 116, in lxml.etree.Schematron.__init__ (src\lxml\lxml.etree.c:156251)
SchematronParseError: Document is not a valid Schematron schema
我已经用 etree.Schematron 类进行了尝试,它也抛出了“SchematronParseError: invalid schematron schema:”。
我在想问题是关于schematron的
<sch:extends />
标签。我的意思是,当 schematron 使用外部规则断言时会出现错误。
使用 python 与相关和联合 schematron 一起工作的正确方法是什么?
提前致谢。