W3C home > Mailing lists > Public > xmlschema-dev@w3.org > January 2011

RE: Express length constraints in a regex or use maxLength and minLength?

From: Costello, Roger L. <costello@mitre.org>
Date: Sun, 9 Jan 2011 18:20:09 -0500
To: "xmlschema-dev@w3.org" <xmlschema-dev@w3.org>
Message-ID: <9E51F88D5247B648908850C35A3BBB50052DE55F8C@IMCMBX3.MITRE.ORG>
Michael Sperberg-McQueen wrote:

> It may be worth pointing out that XSD union types are designed
> to make this kind of thing relatively easy:  you can define several
> simple types, for example one for the simplest most regular values,
> another for values which are less likely (and thus more likely to 
> require special handling), and at the bottom one which is (as
> Roger Costello has suggested) essentially a renamed version
> of xsd:string (or xsd:string itself).
> The application can then (if the XSD validator provides access to
> the appropriate information in the PSVI) dispatch the value for further 
> processing to an appropriate routine or workflow suitable for a
> particular class of input.


I think that I know how to do this, but let me reconfirm. Suppose that I create three versions of the English-language-family-name simpleType:


<simpleType name="English-language-family-name_v1">
     <restriction base="string">
            <minLength value="1" />
            <maxLength value="100" />
            <pattern value="[a-zA-Z' \.-]+" />


<simpleType name="English-language-family-name_v2">
     <restriction base="string" />


<simpleType name="English-language-family-name_v3">
     <restriction base="string">
            <minLength value="1" />
            <maxLength value="500" />

Next, I declare Family-name to be a union of the three versions:

<element name="Family-name">
        <union memberTypes="fn:English-language-family-name_v1

Here's what an XML instance document looks like:


Suppose that at data entry I want the data validated against tight constraints, i.e., English-language-family-name_v1.

How do I instruct an XML Schema validator to use that version of the simpleType? 

I think that this is how to do it: 

    <Family-name xsi:type="fn:English-language-family-name_v1">__________</Family-name>

Is that correct?


Received on Sunday, 9 January 2011 23:20:45 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 14:56:18 UTC