Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

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

This is my test xml:
XML
<books>
<book publisher="ddd" on-loan="sdsd">
  <title>idan title</title> 
  <author>idan author</author> 
  <publication-date>idan date</publication-date> 
</book>
</books>

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 ?
Posted
Updated 30-Jun-10 4:32am
v2

1 solution

This article should help you out. Have a look:
Getting Started with Schematron[^]
 
Share this answer
 
Comments
PROG3 30-Jun-10 10:55am    
Do I need to install something to use Schematron ? I'm using oXygen.
In the example you gave me the auther is using XmlSpy but requires installing a special plugin.
Does it mean that if i'm using xds validation in my code I will have to use another library or install something ahead ?
Sandeep Mewara 30-Jun-10 10:57am    
I am not sure of that! Might be http://www.schematron.com/ website can help regarding pre-requisites.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900