W3C home > Mailing lists > Public > www-forms@w3.org > September 2007

Re: limit string length

From: Mark Birbeck <mark.birbeck@formsPlayer.com>
Date: Mon, 24 Sep 2007 07:25:54 +0100
Message-ID: <a707f8300709232325g1b2ab160q5a4e123219b9d533@mail.gmail.com>
To: "Frederik Elwert" <felwert@uni-bremen.de>
Cc: www-forms@w3.org

Hi Frederik,

I think the @constraint way is the best one.

Regards,

Mark

On 22/09/2007, Frederik Elwert <felwert@uni-bremen.de> wrote:
>
> Hello!
>
> Currently, I am writing an online survey tool that uses an XForms based
> file format for survey definition. There are some topics that I'm not
> really sure how to solve them best in XForms.
>
> One is the ability to limit the allowed length of string variables. In
> XHTML, this would be pretty straight forward:
>
> Question label: <html:input type="text" name="v1" maxlength="20"/>
>
> Now, in XForms I have a control like
>
> <xf:input ref="v1"><xf:label>Question label:</xf:label></xf:input>
>
> and a binding:
>
> <xf:bind nodeset="v1" type="xsd:string"/>
>
> Now, to limit the allowed input size, I could define a new datatype:
>
> <xsd:schema targetNamespace="http://my-namespace/">
>     <xsd:simpleType name="stringMax20">
>         <xsd:restriction base="xsd:string">
>             <xsd:maxLength value="20"/>
>         </xsd:restriction>
>     </xsd:simpleType>
> </xsd:schema>
>
> and use this in my binding:
>
> <xf:bind nodeset="v1" type="my:stringMax20"/>
>
> But this would mean that for every variable that uses a different
> maxlength, I would have to define a whole new datatype. I think that
> this implies quite much overhead (add a five-line datatype definition
> instead of changing one value from, e.g., 20 to 21) and I somewhat feel
> that this would "abuse" the concept of datatypes.
>
> Another possibility would be to use the constraint property:
>
> <xf:bind nodeset="v1" type="xsd:string" constraint="string-length() &lt;= 20"/>
>
> This is quite flexible, but also semantically less clear and harder to
> parse.
>
> For the purpose of my application, I could also take the shortest step
> and use the XHTML property:
>
> <xf:bind nodeset="v1" type="xsd:string" html:maxlength="20"/>
>
> But this is not really compatible and also quite limited, since it's not
> possible to implement restrictions that don't have an XHTML equivalent.
>
> Personally, I'd prefer something like
>
> <xf:bind nodeset="v1" type="xsd:string">
>     <xsd:maxLength value="20"/>
> </xf:bind>
>
> but I guess this would be least compatible and probably (without having
> investigated further) violate a couple of XForms and XML Schema spec
> details.
>
> Primarily, the format has to serve the purpose of my application, so I
> don't have to stick too tight to the "XForms way". But my intention is
> to follow the XForms spec where possible and allow other XForms capable
> application to display the survey without big incompatibilities. I.e.,
> no string length constraints in other applications would be tolerable,
> but the format should be valid XML and not violate the XForms spec where
> XForms is used.
>
> So what would you suggest to be the best way to go?
>
> Thanks,
> Frederik
>
>
>
>


-- 
  Mark Birbeck, formsPlayer

  mark.birbeck@formsPlayer.com | +44 (0) 20 7689 9232
  http://www.formsPlayer.com | http://internet-apps.blogspot.com

  standards. innovation.
Received on Monday, 24 September 2007 06:26:05 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Saturday, 10 March 2012 06:22:10 GMT