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

A bad idea to use the XML Schema list type?

  • From: "Costello, Roger L." <costello@m...>
  • To: "xml-dev@l..." <xml-dev@l...>
  • Date: Mon, 9 Feb 2009 10:10:40 -0500

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

    <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 


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


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

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-2013 All Rights Reserved.