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

Re: XML Schema Question: attributing an element with a datatype?

  • From: "Roger L. Costello" <costello@m...>
  • To: xml-dev@i..., www-xml-schema-comments@w..., jcs@m..., costello@m...
  • Date: Mon, 31 Jan 2000 06:51:44 -0500

xml schema money
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@i...
> 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@i...
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.



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.