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

Re: xsd:date and xsd:pattern together for custom data type

From: Jeni Tennison <jeni@jenitennison.com>
Date: Tue, 29 Oct 2002 15:27:29 +0000
Message-ID: <89251069078.20021029152729@jenitennison.com>
To: "Omprakash Bachu" <omprakash.bachu@mphasis.com>
CC: xmlschema-dev@w3.org, om@mphasis.com

Hi Om,

> I've declared in the below format, but the XMLSpy tool is giving an error
> the attribute tag is invalid child.
>         <xsd:element name="eosdate">
>                 <xsd:simpleType>
>                         <xsd:restriction base="xsd:string">
>                                 <xsd:pattern value="[0,1]{1}[0-9]{1}/[0-3]{1}[0-9]{1}/[0-9]{2}"/>
>                         </xsd:restriction>
>                 </xsd:simpleType>
>                 <xsd:attribute name="value" type="xsd:date"/>
>         </xsd:element>

Here, you have xsd:attribute as a direct child of xsd:element. You
can't do that. What you're trying to do here is say that the eosdate
element has simple *content* and an attribute. An element that has any
attributes is a *complex* type, so you need:

<xsd:element name="eosdate">

In order to say that the element's content is based on a restricted
version of a string with an attribute added, you need to have two
steps. First, create the simple type with the date format that you

<xsd:simpleType name="date">
  <xsd:restriction base="xsd:token">
    <xsd:pattern value="[0-1][0-9]/[0-3][0-9]/[0-9]{2}" />

then *extend* that simple type by adding an attribute:

<xsd:element name="eosdate">
      <xsd:extension base="date">
        <xsd:attribute name="value" type="xsd:date" />

This means that you can have things like:

  <eosdate value="2002-10-29">10/29/2002</eosdate>

Note that your current pattern doesn't restrict the content of eosdate
to valid dates, and there's nothing to guarantee that the date held in
the content of eosdate matches the date held in the value attribute of



Jeni Tennison
Received on Tuesday, 29 October 2002 10:27:31 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 14:55:58 UTC