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

How to improve XSD for a list with differently typed items + multiplicity and uniqueness constraints

From: <gvt.junk@free.fr>
Date: Tue, 21 Apr 2009 15:25:41 +0200
Message-ID: <1240320340.49edc95500026@imp.free.fr>
To: xmlschema-dev@w3.org
How to improve XSD for a list with differently typed items + multiplicity and uniqueness constraints
Hi Experts,

I was facing a problem to write a XML schema to define a <LIST> element that
obeys multiple rules (see below).

I finally reached a fully functional solution, but would like to know of an
alternate XML schema producing "better-looking" documents (with reduced nesting
levels).

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)

I succeed in writing an XML schema that enforce all these rules. A compliant
document look like this:
<LIST>
  <ITEM>
    <ITEM_B>100</ITEM_B>
  </ITEM>
  <ITEM>
    <ITEM_A>0</ITEM_A>
  </ITEM>
  <ITEM>
    <ITEM_C>aa-123</ITEM_C>
  </ITEM>
</LIST>

My question:
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>

I can provide the XML schema I produced to anyone interrested in this
chalenge... Just let me know: gvt {dOt} junk {a}{t} fREe {DOt} fr

Thanks and regards,
Grégoire Vatry
Received on Thursday, 23 April 2009 05:35:34 GMT

Subscribe to the Stylus Scoop newsletter for helpful XML tips and tutorials.
Email
First Name
Last Name
Company

Download Stylus Studio 6 XML Enterprise Edition

Subscribe in XML format
RSS 2.0
Atom 0.3
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-2007 All Rights Reserved.