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

Roger Costello <costello@mitre.org> writes:

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

    <element name="cost">
        <type source="money" derivedBy="extension">
            <attribute name="currency" type="string" minOccurs="1"/> 
        <type>
    </element>

is the solution you are looking for.

ht
-- 
  Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh
          W3C Fellow 1999--2001, part-time member of W3C Team
     2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440
	    Fax: (44) 131 650-4587, e-mail: ht@cogsci.ed.ac.uk
		     URL: http://www.ltg.ed.ac.uk/~ht/

Received on Thursday, 3 February 2000 19:15:10 UTC