Altova Mailing List Archives>Archive Index >xml-dev Archive Home >Recent entries >Thread Prev - >Thread Next - Re: [xml-dev] A bad idea to use the XML Schema list type? [xml-dev] A bad idea to use the XML Schema list type?To: "xml-dev@-----.---.---" <-------@-----.---.---> Date: 2/9/2009 3:11:00 PM Hi Folks,
Consider these two ways of expressing the numbers drawn in a lottery:
Approach #1: List of Values
<Lottery-Drawing>89 12 41 66 2 26</Lottery-Drawing>
Approach #2: List of Nodes
<Lottery-Drawing-List>
<li>89</li>
<li>12</li>
<li>41</li>
<li>66</li>
<li>2</li>
<li>26</li>
</Lottery-Drawing-List>
Here's how the two approaches may be expressed using XML Schemas:
Approach #1: Use the XML Schema List Type
Constrain the list to six values:
<xs:simpleType name="LotteryNumbers">
<xs:restriction base="NumbersList">
<xs:length value="6"/>
</xs:restriction>
</xs:simpleType>
Constrain the size of each value to 1 - 99:
<xs:simpleType name="OneToNinetyNine">
<xs:restriction base="xs:positiveInteger">
<xs:maxInclusive value="99"/>
</xsd:restriction>
</xs:simpleType>
<xs:simpleType name="NumbersList">
<xs:list itemType="OneToNinetyNine"/>
</xs:simpleType>
Declare the <Lottery-Drawing> element:
<xs:element name="Lottery-Drawing" type="LotteryNumbers" />
Approach #2: Declare Child Elements
Declare the <Lottery-Drawing-List> element to contain six <li> elements:
<xs:element name="Lottery-Drawing-List">
<xs:complexType>
<xs:sequence>
<xs:element name="li" type="OneToNinetyNine" minOccurs="6" maxOccurs="6"/>
</xs:sequence>
</xs:complexType>
</xs:element>
(The type OneToNinetyNine is shown above)
ANALYSIS OF THE TWO APPROACHES
Both approaches are relatively straighforward to express with XML Schemas.
There are, however, significant differences with regard to processing. For example, consider the task of summing all the values in the list. With appproach #2 it is easily accomplished using this XSLT:
sum(li)
With approach #1 it is not easily accomplished. With XSLT 1.0 it requires creating a named template that splits the string "89 12 41 66 2 26" and then sums the individual tokens. Not an easy task. XSLT 2.0 makes the job a bit easier, but it's still not as easy as with approach #2.
From reading Dimitre's paper [1] I see lots of benefits to using approach #2 in terms of enabling functional programming.
RECOMMENDATION
Don't use the XML Schema list type. Instead, create a list of elements.
Do you agree?
/Roger
[1] Higher-Order Functional Programming with XSLT 2.0 and FXSL by Dimitre Novatchev
http://www.idealliance.org/papers/extreme/proceedings/xslfo-pdf/2006/Novatchev01/EML2006Novatchev01.pdf
_______________________________________________________________________
XML-DEV is a publicly archived, unmoderated list hosted by OASIS
to support XML implementation and development. To minimize
spam in the archives, you must subscribe before posting.
[Un]Subscribe/change address: http://www.oasis-open.org/mlmanage/
Or unsubscribe: xml-dev-unsubscribe@l...
subscribe: xml-dev-subscribe@l...
List archive: http://lists.xml.org/archives/xml-dev/
List Guidelines: http://www.oasis-open.org/maillists/guidelines.php
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
