W3C home > Mailing lists > Public > www-xml-schema-comments@w3.org > January to March 2000

XML Schema Question: attributing an element with a datatype?

From: Roger Costello <costello@mitre.org>
Date: Sun, 30 Jan 2000 13:49:26 -0500
Message-ID: <389487B5.4AC9F4E2@mitre.org>
To: xml-dev@ic.ac.uk
CC: www-xml-schema-comments@w3c.org, jcs@mitre.org, costello@mitre.org
Hi Folks,

I have created an XML Schema document for juice machines. Part of the
description of each juice machine is its cost. One of the first things
that I did is create a money datatype:

    <datatype name="money" source="decimal">
        <scale value="2"/>
    </datatype>

Then, I declared the cost element to be of type money:

    <element name="cost" type="money"/>

Seems reasonable, right?  Well, the next thing that I wanted to do was
to add an attribute - currency - to the cost element.  This is where I
ran into problems.  Attributes are typically declared like this:

    <element name="cost">
        <type>
            <attribute name="currency" type="string" minOccurs="1"/> 
        <type>
    </element>

This declares currency to be a required attribute of cost.  However, in
adding this attribute, we have lost our nice typing of cost to money
(i.e., cost of datatype money).

Unless I am missing something obvious (which may well be the case),
there is no way to specify a datatype for an element as well as assign
attributes to it ...  I must not be thinking clearly.  Can someone tell
me how to assign cost the datatype money as well as giving it the
attribute currency?  To provide more context to my question, I have
included below the complete XML Schema which I am trying to enhance to
give cost the attribute currency.  /Roger

------------------------------------------------------------
                  juicers.xsd
------------------------------------------------------------
<?xml version="1.0"?>
<!DOCTYPE schema SYSTEM "xml-schema.dtd"[
<!ATTLIST schema xmlns:j CDATA #IMPLIED>
]>
<schema xmlns="http://www.w3.org/1999/XMLSchema"
               targetNamespace="http://www.juicers.org"
               xmlns:j="http://www.juicers.org">
    <element name="warranty" type="string"/>
    <element name="guarantee" equivClass="j:warranty" type="string"/>
    <type name="appliance">
        <element name="description" type="string"/>
        <element ref="j:warranty"/>
    </type>
    <type name="juiceAppliance" source="j:appliance"
derivedBy="extension">
        <element name="name" type="string"/>
        <element name="image" type="imageType"/>
        <element name="weight" type="integer"/>
        <element name="cost" type="money" maxOccurs="*"/>
        <element name="retailer" type="uri"/>
        <attribute name="id" type="ID" minOccurs="1"/>
        <attribute name="electric" type="boolean" minOccurs="1"/>
        <attribute name="type" minOccurs="1">
            <datatype source="string">
                <enumeration value="press"/>
                <enumeration value="gear"/>
                <enumeration value="centrifugal"/>
            </datatype>
        </attribute>
    </type>
    <element name="juicers">
        <type>
            <element name="juicer" type="j:juiceAppliance" 
                     minOccurs="0" maxOccurs="*"/>
        </type>
    </element>
    <datatype name="money" source="decimal">
        <scale value="2"/>
    </datatype>
    <datatype name="imageType" source="string">
        <pattern value="(.)*.gif"/>
        <pattern value="(.)*.jpeg"/>
        <pattern value="(.)*.jpg"/>
        <pattern value="(.)*.bmp"/>
    </datatype>
</schema>
Received on Sunday, 30 January 2000 13:47:30 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Sunday, 6 December 2009 18:12:46 GMT