Re: attribute validation

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:simpleType>
    <xs:restriction base="xs:token">
      <xs:pattern value=".+" />
    </xs:restriction>
  </xs:simpleType>

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:simpleType>
      <xs:restriction base="xs:token">
        <xs:pattern value=".+" />
      </xs:restriction>
    </xs:simpleType>
  </xs:attribute>

*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

---
Jeni Tennison
http://www.jenitennison.com/

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