W3C home > Mailing lists > Public > xmlschema-dev@w3.org > February 2002

Re: How to handle Currency

From: Jeni Tennison <jeni@jenitennison.com>
Date: Sat, 23 Feb 2002 23:44:12 +0000
Message-ID: <10926483331.20020223234412@jenitennison.com>
To: "Pastor.Phil" <pastor@brulant.com>
CC: "'xmlschema-dev@w3.org'" <xmlschema-dev@w3.org>
Hi Phil,

> I have an XML document that stores currency amounts with all
> punctuation (eg. $1,234.00). A primitive data type will not work for
> this (other than string). Is there a way to validate an amount
> greater than $0.00 ? Should I use a pattern facet ?
Yes - I think that the closest type to what you're after here is a
xs:token that fulfils a pattern, which might be something like:

<xs:simpleType name="currency">
  <xs:restriction base="xs:token">
    <xs:pattern value="$[1-9][0-9]{0,2}(,[0-9]{3})*\.[0-9]{2}" />

The reason that I'd use xs:token as the base rather than xs:string is
that it means that you can include whitespace around the currency
without it messing up the validity. For example:


would be valid. This mirrors the other data types (aside from
xs:string and xs:normalizedString), so is more consistent and
therefore will be less prone to errors than basing the simple type on
xs:string (in my opinion).

You could use \d instead of the [0-9] but that would allow digits from
all sorts of languages, which you might not actually want. I'm sure
you're aware that other processors will not interpret these values as



Jeni Tennison
Received on Saturday, 23 February 2002 18:44:14 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 23:14:59 UTC