OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.


Help: OASIS Mailing Lists Help | MarkMail Help



   Re: [xml-dev] Best Practice - beyond schema

[ Lists Home | Date Index | Thread Index ]

Paul Spencer scripsit:

> [...] XML Schema cannot express the constraints required, for example,
> a section of a message that is required if the value of a previous
> element is "yes", but not if it is "no". 

RELAX NG can handle this very neatly:

locale = "GB"

start = element person {
	element commonName { text },
	element address { text },
	(element citizenship { locale } |
         (element citizenship { token - locale },
          (element residentAlien { "yes" } |
           (element residentAlien { "no"}, element visaExpires { xsd:date }))))

The choices provide that if the "citizenship" element has value "GB", then
neither "residentAlien" nor "visaExpires" elements may be present.
Otherwise, residentAlien must be present, and depending on its value,
visaExpires is likewise either required or forbidden.

This schema can be included in another schema and the "locale" rule
overridden, thus:

include "person.rnc" {
	locale = "US"

> The other situation, and the one that is a more immediate concern, is
> the situation where we need to localise a general purpose schema. 

The same mechanisms as above can be used.

U.S. elections are held in two phases, primary and general.  In a
primary election, which is held to decide the candidate of each party
for a seat, the voter's party affiliation must be recorded.  In
a general election, it must not be.  Thus:

element ballot {
	element votingTime { xsd:date },
	element pollSite { text}

affiliation = empty

defines the schema for a general election.  The following inclusion
gives us a primary election ballot schema instead:

include "ballot.rnc" {
	affiliation = element affiliation {
		"Republican" | "Democrat" |  "Green"

John Cowan <jcowan@reutershealth.com>     http://www.reutershealth.com
I amar prestar aen, han mathon ne nen,    http://www.ccil.org/~cowan
han mathon ne chae, a han noston ne 'wilith.  --Galadriel, _LOTR:FOTR_


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS