Altova Mailing List Archives>Archive Index >xmlschema-dev Archive Home >Recent entries >Thread Prev - How to improve XSD for a list with differently typed items + multiplicity and uniqueness constraints [Thread Next] RE: How to improve XSD for a list with differently typed items + multiplicity and uniqueness constraintsTo: <gvt.junk@----.-->, <xmlschema-dev@--.---> Date: 4/23/2009 10:57:00 AM > > Here are the rules the schema shall enforce for the <LIST> element: > 1. The list allows a limited set of items; > (say: <ITEM_A>, <ITEM_B> and <ITEM_C>) 2. The list does > not allow duplicate items (same element name); > (items <ITEM_A>, <ITEM_B> and <ITEM_C> can only occur 0 or 1 time in the > list) > 3. Order of items in the list does not matter; 4. The list > must contain at least 1 item (among: <ITEM_A>, <ITEM_B> and > <ITEM_C>); 5. The content of item elements is typed and "data > type" is psecific to each item; > (e.g.: <ITEM_A> contains integer data, while <ITEM_B> > contains string and <ITEM_C> a complex type) > > Is there any chance to write an alternate XML schema that > enforce all these rules, but produce "better-looking" > compliant document that would look like the following one, > with reduced nesting levels? > Really, I'm not convinced it is possible with XML schema... > > <LIST> > <ITEM_B>100</ITEM_B> > <ITEM_A>0</ITEM_A> > <ITEM_C>aa-123</ITEM_C> > </LIST> > Using xs:all will allow this instance, and satisfy all your constraints except (4). Using xs:choice with a repetition (or equivalently, a substitution group) will allow this instance, and satisfy all your constraints except (2). I think that to enforce both (2) and (4) simultaneously you probably need XSD 1.1 assertions. You could then use xs:all with the additional assertion test="count(*) ge 1", or xs:choice with the additional assertion test="count(*) eq count(distinct-values(*/node-name()))". Michael Kay http://www.saxonica.com/ From gvt.junk@f... Thu Apr 23 17:43:33 2009 Received: from maggie.w3.org ([193.51.20 | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
