[Home] [By Thread] [By Date] [Recent Entries]
----- Original Message -----
From: "Iain W Fergusson" <fergusson_iain@j...>
To: <duane@x...>
Cc: <Pcj@I...>; <Tom.D.Conder@L...>; <xml-dev@l...>
Sent: Thursday, May 17, 2001 11:25 AM
Subject: Re: Attributes v Elements
<SNIP>
> >You would be better off to use a more definitive description of what the
> >monetary value is. "USDollar" is really the value for "Currency". Try
> >something like this:
> >
> ><Price currency="USD">10</Price>
> >
>
> In the above example <price> has to be described in XML Schema using a
> <complexType>, because of the presence of the currency attribute.
> There is then no way of constraining the contents of <price> to be a
number.
>
> If you need to validate that <price> is a number, it has to be a
<simpleType>,
> which cannot have attributes.
>
>
This is incorrect. There is no problem describing the Price element and
constraining the content to be a number. XML Schema provides facilities for
describing types with attributes and constrained text content. The type
definition would look like this;
<xs:complexType name='PriceType' >
<xs:simpleContent>
<xs:extension base='xs:decimal' >
<xs:attribute name='currency' type='xs:string' />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
a global element declaration could then be used to reference the PriceType;
<xs:element name='Price' type='PriceType' /> <!-- playing fast and loose
with namespaces for brevity -->
Regards
Martin Gudgin
DevelopMentor
|

Cart



