Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


[xml-dev] A bad idea to use the XML Schema list type?

From: "Costello, Roger L." <costello@-----.--->
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



transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent