Re: XML Schema Standard 1.0 - W3C - Regular Expressions - Patterns

(Excuse me for butting in, but I just happened to see your message).

> > I'm currently working on XML schemas to be used for a financial
> > application.

> > There is a specific requirement aiming to provide a data type where:
> >
> > 1) all strings must be length at least 1 and at most 35;
> > 2) the sequence "//" is not allowed within the first 16 characters
> >    of each string;
> > 3) the sequence "//"  is allowed within the substring [17..35] of
> >    each string.

> Thank you; this is an interesting problem in the construction of
> regular expressions.  The language you describe is clearly regular,
> but conventional regular expressions, including those of XML Schema,
> are a little awkward in handling it, and the regular expression is
> likely to be rather complex.

> It is, by contrast, easy to state with assertions of the kind
> supported by Schematron, or by XML Schema 1.1, and if simplicity of
> expression is your primary goal, you may wish to say

>    <assert test="not(contains(substring(.,1,16),'//'))"/>
>    <assert test="length(.) > 0"/>
>    <assert test="length(.) &lt; 36"/>

> and be done with it.

Can I also point out another W3C technology that allows you to do it:  
XForms. XForms is already widely used for financial applications.

You can say

	<bind nodeset="t"
             constraint="string-length(.) &gt; 0 and string-length(.) &lt;  
36
                        and not(contains(substring(.,1,16),'//'))" />

I've attached a complete file that tries this one case. It runs on Firefox  
with the XForms extension.

One thing I noticed while testing is that the rules miss out a case (since  
it states both valid and invalid states, it leaves a state undefined):  
what happens when substring(., 16, 17) = "//"?

Best wishes,

Steven Pemberton


 

Received on Monday, 12 February 2007 13:00:41 UTC