[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Best Practice - beyond schema
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! 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
|