XML Schema Question: attributing an element with a datatype?

Roger Costello costello at mitre.org
Sun Jan 30 18:47:31 GMT 2000

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

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">
            <attribute name="currency" type="string" minOccurs="1"/> 

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

<?xml version="1.0"?>
<!DOCTYPE schema SYSTEM "xml-schema.dtd"[
<!ATTLIST schema xmlns:j CDATA #IMPLIED>
<schema xmlns="http://www.w3.org/1999/XMLSchema"
    <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 name="juiceAppliance" source="j:appliance"
        <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"/>
    <element name="juicers">
            <element name="juicer" type="j:juiceAppliance" 
                     minOccurs="0" maxOccurs="*"/>
    <datatype name="money" source="decimal">
        <scale value="2"/>
    <datatype name="imageType" source="string">
        <pattern value="(.)*.gif"/>
        <pattern value="(.)*.jpeg"/>
        <pattern value="(.)*.jpg"/>
        <pattern value="(.)*.bmp"/>

xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev at ic.ac.uk
Archived as: http://www.lists.ic.ac.uk/hypermail/xml-dev/ or CD-ROM/ISBN 981-02-3594-1
Please note: New list subscriptions and unsubscriptions
are  now ***CLOSED*** in preparation for list transfer to OASIS.

More information about the Xml-dev mailing list