2013-11-26 33 views
1

我想通过使用包含其他模式的模式组来验证xml。etree schematron验证扩展标记

主要的Schematron:

<?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:无效Schematron模式:”太。

我想这个问题是有关的Schematron的

<sch:extends /> 

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

通过使用python与相关联合schematrons的正确方式是什么?

在此先感谢。

+0

我停下来试着用etree来做,我用python subproces [Probatron4j](https://code.google.com/p/probatron4j/)解决了这个问题。 –

回答

0

我认为这个问题简单得多: 好像你忘记了<assert>元素中的“sch:”XML命名空间前缀。

+0

谢谢。实际上,这些文件在主要schematron上包含该命名空间前缀(“xmlns:sch =”http://purl.oclc.org/dsdl/schematron“) 我不认为问题出现在schematron中,因为相同的schematron工作用java [probatron4.jar](https://code.google.com/p/probatron4j/) –