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

"Costello, Roger L." <[email protected]>
Newsgroups gmane.text.xml.schema.devel
Message-ID <[email protected]>
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.

Neat!

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:

1. TIGHT CONSTRAINTS

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


2. LOOSE CONSTRAINTS

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


3. MEDIUM CONSTRAINTS

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


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

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


Here's what an XML instance document looks like:

    <Family-name>__________</Family-name>


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?

/Roger
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.