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

Re: Best Practice - beyond schema


xsd date locale
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 },
	affiliation,
	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@r...>     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_

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.