【问题标题】:etree schematron validation extends tagetree schematron 验证扩展标签
【发布时间】:2013-12-11 20:21:28
【问题描述】:

我正在尝试通过使用一组架构来验证 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 的正确方法是什么?

提前致谢。

【问题讨论】:

  • 我停下来尝试用 etree 做这件事,我通过使用带有 python 子进程的Probatron4j 解决了这个问题。

标签: python xml validation lxml schematron


【解决方案1】:

我认为问题要简单得多: 您似乎忘记了 &lt;assert&gt; 元素中的“sch:”XML 命名空间前缀。

【讨论】:

  • 谢谢。实际上,这些文件在主 schematron 上包含该名称空间前缀。("xmlns:sch="purl.oclc.org/dsdl/schematron" ) 而且我不认为问题出在 schematron,因为相同的 schematron 适用于 java probatron4.jar
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-12-30
  • 2020-06-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多