使用Schematron进行XSD验证 [英] XSD validation using Schematron

查看:132
本文介绍了使用Schematron进行XSD验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



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

Hi,

I''m trying to add schematron validation to my xsd.
This is my new 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:


This is my test 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无效.关于为什么的建议?


Using the xml I provided I don''t get validation error.
I assumed I will get the message "Every book that is on loan must have a return date" And that the xml won''t be valid. Suggestions as to why ?

推荐答案

本文应为您提供帮助.看看:
Schematron入门 [
This article should help you out. Have a look:
Getting Started with Schematron[^]


这篇关于使用Schematron进行XSD验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆