[
Lists Home |
Date Index |
Thread Index
]
- From: "Roger L. Costello" <costello@mitre.org>
- To: xml-dev@ic.ac.uk, www-xml-schema-comments@w3c.org, jcs@mitre.org, costello@mitre.org
- Date: Mon, 31 Jan 2000 06:51:44 -0500
I reckon that I will answer my own question. To give the cost element
an attribute currency, where the type of cost is the datatype money, you
declare it as follows:
<element name="cost">
<type source="money">
<attribute name="currency" minOccurs="1">
<datatype name="currencies" source="string">
<enumeration value="USD"/>
<enumeration value="CND"/>
</datatype>
</attribute>
</type>
</element>
The element "type" has an optional attribute "source" which I set to the
datatype "money".
"money" is defined as:
<datatype name="money" source="decimal">
<scale value="2"/>
</datatype>
/Roger
Roger Costello wrote:
>
> 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>
>
> xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev@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.
xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev@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.
|