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

limit string length

From: Frederik Elwert <felwert@uni-bremen.de>
Date: Sat, 22 Sep 2007 13:00:55 +0200
To: www-forms@w3.org
Message-Id: <1190458855.20361.48.camel@FredDesk>


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"/>

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

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"/>

but I guess this would be least compatible and probably (without having
investigated further) violate a couple of XForms and XML Schema spec

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?

Received on Monday, 24 September 2007 04:49:55 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 21:36:20 UTC