首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >etree schematron验证扩展了标记

etree schematron验证扩展了标记
EN

Stack Overflow用户
提问于 2013-11-26 23:32:43
回答 1查看 544关注 0票数 1

我正在尝试通过使用一组模式来验证xml,其中一个模式包含其他模式。

主要原理图:

代码语言:javascript
复制
    <?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:

代码语言:javascript
复制
    <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>

问题是,在主模式中,如果我直接放置一个断言标记,例如:

代码语言:javascript
复制
 <assert test="sum(//Percent)=100">Sum is not 100%.</assert>

在“规则”标签之间,就像这样:

代码语言:javascript
复制
<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。否则它会抛出如下错误:

代码语言:javascript
复制
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的

代码语言:javascript
复制
  <sch:extends /> 

标签。我的意思是,当schematron使用规则的外部断言时,就会出现错误。

使用python处理相关和联合模式的正确方法是什么?

提前谢谢。

EN

回答 1

Stack Overflow用户

发布于 2013-12-02 20:44:04

我认为问题要简单得多:您似乎忘记了<assert>元素中的"sch:“XML名称空间前缀。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20221349

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档