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

Re: attribute validation

From: Jeni Tennison <jeni@jenitennison.com>
Date: Tue, 23 Oct 2001 10:51:25 +0100
Message-ID: <6241976163.20011023105125@jenitennison.com>
To: "Rajendra" <rajendrabp@samyog.com>
CC: xmlschema-dev@w3.org
Hi Rajendra,

> the above example is definition of attribute element of an element
> called column.Since attribute name is required in every instance of
> column element it is defined as required.I want to know is it
> possible to validate this attribute value when it is assigned null
> value such as this
> <column name =""/>
> I do not want any null values to be enrtered over there....at least
> some text string should be there ...so how to do this
> validation??????

You need to restrict the simple type of the name attribute so that it
*must* contain a character. You can use the pattern facet to fix this,
with the regular expression:


You probably want to choose xs:token as a base type to prevent names
that just consist of white space, so need:

    <xs:restriction base="xs:token">
      <xs:pattern value=".+" />

You can assign this simple type to the attribute by nesting the
xs:simpleType element inside the xs:attribute element as follows:

  <xs:attribute name="name" use="required">
      <xs:restriction base="xs:token">
        <xs:pattern value=".+" />

*Alternatively*, you might want to choose an existing data type, for
example xs:NMTOKEN or xs:Name as the type of the name attribute. These
data types are specifically designed for values that are names - they
don't allow whitespace within the value, for example.
I hope that helps,


Jeni Tennison
Received on Tuesday, 23 October 2001 05:52:40 UTC

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