[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?
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! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|