【问题标题】:xsd validation using schematron使用 schematron 进行 xsd 验证
【发布时间】:2011-03-10 02:15:44
【问题描述】:

我正在尝试将 schematron 验证添加到我的 xsd。 这是我的新 xsd:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    xmlns:sch="http://www.ascc.net/xml/schematron"    
    elementFormDefault="qualified" &gt;

 <xs:element name="books"> 
  <xs:complextype>
   <xs:sequence>   ;P 
    <xs:element name="book" type="bookType" maxoccurs="unbounded">
      <xs:annotation>
       <xs:appinfo>
        <sch:pattern id="onLoanTests" xmlns:sch="http://purl.oclc.org/dsdl/schematron">
          <sch:rule context="book">
           <sch:report test="@on-loan and not(@return-date)">
           Every book that is on loan must have a return date
           </sch:report>
          </sch:rule>
        </sch:pattern>
       </xs:appinfo>
      </xs:annotation>
    </xs:element>
   </xs:sequence> 
  </xs:complextype>
 </xs:element>

 <xs:complextype name="bookType">
  <xs:sequence>
   <xs:element name="title" type="xs:string" />
   <xs:element name="author" type="xs:string" />
   <xs:element name="publication-date" type="xs:string" />
  </xs:sequence>
  <xs:attribute name="publisher" type="xs:string" use="required" />
  <xs:attribute name="on-loan" type="xs:string" use="required" />
  <xs:attribute name="return-date" type="xs:string" use="optional" />
 </xs:complextype>

</xs:schema>

这是我的测试 xml:

<books>
<book publisher="ddd" on-loan="sdsd">
  <title>idan title</title> 
  <author>idan author</author> 
  <publication-date>idan date</publication-date> 
</book>
</books>

使用我提供的 xml 我没有收到验证错误。

我以为我会收到消息“每本借出的书都必须有归还日期”,并且该 xml 文件无效。关于为什么的建议?

更新 我确实设法通过在 oXygen xml 编辑器中使用 schematron 验证使其工作。 但是,我应该如何在我的代码中使用? 我需要安装一些特殊的东西吗?链接到另一个库?

更新2 显然here在“处理”部分中,所有需要的步骤都很详细。

【问题讨论】:

    标签: xml validation xsd schematron


    【解决方案1】:

    您的第二次更新可能是对该主题的最佳参考。 XSD 本身不允许您针对 schematron 以及模式本身进行验证的机制。 xsd:appinfo 元素确实允许您嵌入不同模式语言的验证信息,但它专门供应用程序使用(因此得名)。

    这意味着您需要做一些事情来启用它。您引用的论文给出了最好的方法,归结为:

    1. 使用 XSLT 提取 schematron XSD 中的规则
    2. 使用参考 XSLT 从实施 schematron.com 转换 架构到 XSLT
    3. 验证您的实例文档 反对 XSD
    4. 验证您的实例文档 通过处理来对抗schematron 在 2 中创建的 XSLT。

    根据您的环境,您可能需要考虑使用XProc 实现(calabashcalumet)来实现该管道。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-10
      • 1970-01-01
      • 2012-04-13
      • 1970-01-01
      • 2012-09-12
      • 2014-03-27
      • 2016-10-18
      相关资源
      最近更新 更多