[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: how far should you go with XML schema?

  • From: Rick JELLIFFE <ricko@g...>
  • To: David Valera <dvalera@p...>
  • Date: Tue, 30 May 2000 17:05:55 +0800

combine xml xsd
David Valera wrote:
 
> <myroot>
>         <married>yes</married>
>         <dateofwedding>1973-10-12</dateofwedding>
> </myroot>
> 
> I would love to have the possibility of having something like this in XML
> schema: (look at the condition attributes in the dateofwedding element)
> 
> <xsd:element name="myroot">
>  <xsd:complexType content="elementOnly">
>   <xsd:element name="married">
>    <xsd:simpleType base="xsd:string">
>         <xsd:enumeration value="yes"/>
>         <xsd:enumeration value="no"/>
>    </xsd:simpleType>
>   </xsd:element>
>   <xsd:element name="dateofwedding"
>     type="xsd:date" condition="if married=yes" then="minOccurs="0""
> else="minOccurs="1"")/>
>  </xsd:complexType>
> </xsd:element>
> 
> "if married=yes" should of course be an xsl statement, but I hope you get
> the point.
> 
> Is this a desirable development in XML schema? Will something like this be
> implemented in future versions of XML schema? are there other XML drafts
> that combine XML schema and lets say XSL do this kind of condition checking
> during validation?

The current Last Call draft of XML Schemas is "feature-complete" (which
is not to
say it cannot be reorganized, or that features cannot be varied in
response to
the Last Call feedback--I think everyone recognizes that it is easier to
respond
to a 'final draft' than to a work-in-progress).  So I think it is highly
unlikely
that XML Schemas 1.x will support 'co-occurrence' constraints.

However, there is a solution now: you can embed a Schematron schema
inside
an <appinfo> element in the XML Schema. (That is what that element is
for.)

The appropriate XML Schema/Schematron schema would be something like
this:

<xsd:element name="myroot">
 <xsd:complexType content="elementOnly">
   <xsd:element name="married">
    <xsd:simpleType base="xsd:string">
         <xsd:enumeration value="yes"/>
         <xsd:enumeration value="no"/>
    </xsd:simpleType>
   </xsd:element>
   <xsd:element name="dateofwedding"
     type="xsd:date" minOccurs="0" />
  </xsd:complexType>
 </xsd:element>
 <annotation>
   <appinfo>
     <sch:schema xmlns:sch="http://www.ascc.net/xml/schematron/">
        <sch:pattern >
           <sch:rule context="myroot[married/text()='yes']">
              <sch:assert test="dateofwedding"
              >If married, should have a wedding date</sh:assert>
           </sxh:rule>
           <sch:rule context="myroot[dateofwedding]">
              <sch:assert test="married/text()=yes"
              >If has a wedding date, should be married</sh:assert>
           </sxh:rule>
        </sch:pattern>
      </sch:schema>
   </appinfo>
 </annotation>   


To use this, preprocess the XML Schema to extract the Schematron schema,
then run that as normal. Schematron site is 
http://www.ascc.net/xml/resource/schematron/schematron.html

If that is too much trouble, keep them as two separate schemas.
Schematron is not tied to XML Schemas, but can be used to augment the
validating power of any schema language, especially for "co-occurrence"
constraints.

As you suggest, Schematron compiles into XSL code.

Rick Jelliffe

(Not writing on behalf of Schema WG.)

***************************************************************************
This is xml-dev, the mailing list for XML developers.
To unsubscribe, mailto:majordomo@x...&BODY=unsubscribe%20xml-dev
List archives are available at http://xml.org/archives/xml-dev/
***************************************************************************

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.