W3C home > Mailing lists > Public > xmlschema-dev@w3.org > September 2003

Re: Validate list (XML Schema)

From: Jeni Tennison <jeni@jenitennison.com>
Date: Tue, 23 Sep 2003 10:04:38 +0100
Message-ID: <117309620791.20030923100438@jenitennison.com>
To: -saNetta- <san_netta@yahoo.com>
Cc: xmlschema-dev@w3.org

Hi San,

> I have problem in writing XML schema for the following xml code
>
> <list>Alan,Andrew,Santy<list>
>
> I have tried to write it in the following way
> <xsd:simpleType name="PatronsType">
>     <xsd:list itemType="xsd:string" />
> </xsd:simpleType>

In XML Schema, list values have to be separated by whitespace (rather
than commas, semi-colons or any other separator). So if you wanted to
use a list type here, your XML would have to look like:

  <list>Alan Andrew Santy</list>

Your other option is to specify a subtype of xs:string, using a
regular expression, specifying comma separators. For example:

<xs:simpleType name="PatronsType">
  <xs:restriction base="xs:string">
    <xs:pattern value="([A-Z][a-z]+(,[A-Z][a-z]+)*)?" />
  </xs:restriction>
</xs:simpleType>
  
By the way, the type xs:string actually allows whitespace inside it;
the value "Alan Andrew Santy" is a legal xs:string value. It's not
generally a good idea to create a list type whose item type allows
whitespace, because it means that it's ambiguous whether you want
"Alan Andrew Santy" to be the list ("Alan", "Andrew", "Santy") or
("Alan Andrew", "Santy") or ("Alan", "Andrew Santy") or ("Alan Andrew
Santy").

> the problem is "how to validate the value of list tag to not be able
> to have repeating value eg. <list>Alan,Andrew,Santy,Andrew<list>
>
> note:the above xml, the Andrew is repeated.

I don't think that's possible using XML Schema.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/
Received on Tuesday, 23 September 2003 05:25:45 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 11 January 2011 00:14:39 GMT