4.2 Useful Datatypes

The following useful datatypes are either part of the XForms specification, or included from XML Schema. For each datatype, this section describes where it is defined, what conformance level of XForms it applies to, how the datatype is useful, caveats, and one or more examples.

xs:string

Defined in: XML Schema part 2

As the least-restricted datatype, xs:string is the default datatype that XForms will use, unless the author specifies otherwise.

Caveats

xs:string punts on all whitespace processing, so all tab characters and newline characters pass through unchanged. If this is undesired, it is better to use a more restricted datatype such as xs:normalizedString or xforms:listItem.

Example

  • Hello, World

xs:normalizedString

Defined in: XML Schema part 2

The only difference between this datatype and xs:string is that all whitespace characters are converted into space (0x20) characters.

Caveats

Whitespace is normalized, but not collapsed. Thus, it is still possible for multiple consecutive whitespace characters to exist.

Example

  • Hello, World

xs:language

Defined in: XML Schema part 2

If a form collects the name of a human language, this is the datatype to use.

Caveats

The actual values that represent languages are subject to change over time.

Examples

  • en

  • en-US

  • x-sindarin

xs:boolean

Defined in: XML Schema part 2

Simple on/off controls, such as a single checkbox, are naturally represented by a boolean datatype.

Caveats

The lexical space allows multiple representations, so any script or XPath function that reads a value of this datatype should be prepared to see either a string ("true" or "false") or a number (1 or 0).

Examples

  • true

  • 1

  • false

  • 0

xs:decimal

Defined in: XML Schema part 2

Any decimal number can be exactly represented by this datatype.

Caveats

The definition of this datatype defines no restrictions whatsoever on the size of numbers permissible under this datatype. Unless your form processing is prepared to deal with a number thousands of digits long (or even longer), you should use a restriction on the allowed upper and lower limits, and number of digits past the decimal point, as shown here:

<xs:simpleType name="restrictedInteger">   <xs:restriction base="xs:decimal">     <xs:maxExclusive value="1000000"/>     <xs:minInclusive value="-1000000"/>     <xs:fractionDigits value='2'/>   </xs:restriction> </xs:simpleType>

Examples

  • 3.14

  • -12345678901234567890123456789012345

  • 0.318309886

xs:integer

Defined in: XML Schema part 2

This datatype is derived from xs:decimal, with the restriction that only whole numbers are permitted.

Caveats

As with xs:decimal, there is no inherent upper bound on the size of this datatype.

Examples

  • 0

  • 123456

  • -42

xs:nonPositiveInteger

Defined in: XML Schema part 2

This datatype is derived from xs:integer, with the restriction that positive values are not allowed.

Caveats

The same warnings about length of the lexical representation from xs:integer apply here.

Examples

  • 0

  • -1234

xs:negativeInteger

Defined in: XML Schema part 2

This datatype is derived from xs:integer, with the restriction that only negative values are allowed.

Caveats

The same warnings about length of the lexical representation from xs:integer apply here.

Examples

  • -1

  • -9078563412

xs:nonNegativeInteger

Defined in: XML Schema part 2

This datatype is derived from xs:integer, with the restriction that negative values are not allowed.

Caveats

The same warnings about length of the lexical representation from xs:integer apply here.

Examples

  • 0

  • 9078563412

xs:positiveInteger

Defined in: XML Schema part 2

This datatype is derived from xs:integer, with the restriction that only positive values are allowed.

Caveats

The same warnings about length of the lexical representation from xs:integer apply here.

Examples

  • 42

  • 9078563412

xs:double

Defined in: XML Schema part 2

This datatype maps directly to the XPath concept of number, and thus can be useful in situations where data flows back and forth between XPath and the XML instance data.

Caveats

Unlike the decimal datatypes, xs:double is based on an internal binary representation, so many operations (particularly comparisons) are only approximations. The lexical space of this datatype allows scientific notation, so you need to be careful not to assume that any particular representation will always be used. Also, special values of NaN (not a number), INF (infinity), -INF (negative infinity), as well as negative zero, are possible. NaN in particular behaves strangely in comparisons, being equal to itself and greater than all other numbers, even INF!

Examples

  • 3.14159

  • 3.14159E0

  • NaN

  • 0

  • -0

  • INF

  • -INF

xs:dateTime

Defined in: XML Schema part 2

This datatype identifies a specific moment in time.

Caveats

Having our planet divided into time zones complicates matters, since one xs:dateTime with a time zone can't always be reliably compared to another without time zone information.

Example

  • 2002-07-30T23:32:15.32-09:00

xs:time

Defined in: XML Schema part 2

This datatype identifies a recurring point in time each day.

Caveats

The same time zone warnings apply as with other date and time datatypes. Additionally, keep in mind that this format is not useful for representing a duration.

Example

  • 21:37:32-08:00

xs:date

Defined in: XML Schema part 2

This datatype identifies a particular period of time one day long.

Caveats

An optional time zone identifier on the end complicates matters, as is the case with xs:dateTime.

Example

  • 2002-07-30-09:00

xs:base64Binary

Defined in: XML Schema part 2

This datatype allows characters, including control characters, that otherwise aren't representable in XML.

Caveats

Base64 encoding increases the size of any encoded data.

Example

  • Q2VjaSBuJ2VzdCBwYXMgdW4gZW5jb2Rpbmc=

xs:anyURI

Defined in: XML Schema part 2

This datatype represents a URI, which includes web page addresses (commonly called URLs).

Caveats

The allowed characters in anyURI include spaces and other characters not usually found in URI syntax.

Examples

  • http://dubinko.info/writing/xforms/

  • file://localhost/My Documents/résumé

  • mailto:editors@xmlhack.com

xforms:yearMonthDuration

Defined in: XForms 1.0

This datatype represents a duration of a certain number of months (and therefore years also).

Caveats

It's not possible to combine smaller durations, such as days, with xforms:yearMonthDuration without introducing ambiguity. For instance, a month and a day could be anywhere between 29 and 32 days.

Examples

  • P1Y2M

  • P21M

xforms:dayTimeDuration

Defined in: XForms 1.0

This datatype represents a duration of a certain number of seconds (and from that, a number of days, hours, and minutes can be determined).

Caveats

It's not possible to combine larger durations, such as years, with xforms:dayTimeDuration without introducing ambiguity.

Examples

  • PT10000001S

  • P4DT3H2M1S

xforms:listItem

Defined in: XForms 1.0

This datatype represents only non-whitespace characters, and thus makes an excellent base type for a whitespace-separated list datatype (namely xforms:listItems).

Caveats

None

Examples

  • vanilla

  • noauto,owner,kudzu

xforms:listItemsDefined in: XForms 1.0

This datatype represents a space-separated list, and can be used directly with XForms list form controls.

Caveats

None.

Examples

  • Hello World

  • 0 1 0 1 1 1 null



XForms Essentials
Xforms Essentials
ISBN: 0596003692
EAN: 2147483647
Year: 2005
Pages: 117
Authors: Micah Dubinko

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net