OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
A bad idea to use the XML Schema list type?

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


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"/>

Constrain the size of each value to 1 - 99:

    <xs:simpleType name="OneToNinetyNine">
        <xs:restriction base="xs:positiveInteger">
            <xs:maxInclusive value="99"/>
    <xs:simpleType name="NumbersList">
        <xs:list itemType="OneToNinetyNine"/>

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:element name="li" type="OneToNinetyNine"  minOccurs="6" maxOccurs="6"/>

(The type OneToNinetyNine is shown above)


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:


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.


Don't use the XML Schema list type. Instead, create a list of elements.

Do you agree?


[1] Higher-Order Functional Programming with XSLT 2.0 and FXSL by Dimitre Novatchev

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS