rest/datatypes: Difference between revisions
Line 73: | Line 73: | ||
== Proposals == | == Proposals == | ||
* | The proposal is to adopt [http://www.xmlrpc.com/spec/ XML-RPC] scalar values as the class names for typed microformats, with the following caveats: | ||
* the alias 'i4' for integer SHOULD not be used | |||
* the name 'long' MAY be used for 64-bit or longer integers | |||
* for 'dateTime' | |||
** the trailing '.iso8601' MUST be omitted, as '.' is not (always?) valid in CSS class names | |||
** date/time formats SHOULD follow the [http://www.w3.org/TR/NOTE-datetime W3C profile] of [http://en.wikipedia.org/wiki/ISO_8601 ISO 8601] | |||
* if no datatype is specified, an implementation MAY either attempt to infer a datatype from the syntax of the value, or simply assert that the value is a string. Thus, conforming implementations SHOULD always explicitly label strings. | |||
To indicate that a particular micforomat uses typed values, precede that microformat with the class name 'typed', as in: | |||
< div class="typed xoxo"> | |||
== References == | == References == |
Revision as of 23:50, 13 February 2006
Datatypes in HTML
One of the challenges of using HTML as a data transport is that everything, by default, is a string. This page explores ways to use microformats -- specifically, class names -- to encode data type information, e.g., for use with xoxo and rest/ahah, in order to allow lossless import/export from various languages. These could also be used with forms to provide rest/descriptions of the type of data expected.
Examples
These are the primary datatypes in a range of different languages and formats. Note that we are only concerned with "primitive" datatypes (loosely defined), as structured datatypes (list/array, hash/dictionary) are handled by xoxo.
Language/format | string | float | integer | boolean | data | date/time | null |
---|---|---|---|---|---|---|---|
XML Schema | string | float, double | decimal, integer, etc. | boolean | hexBinary, base64Binary | duration, dateTime, date, time | nil |
XML-RPC | string | double | i4, int | boolean | base64 | dateTime.iso8601 | nil |
Mac OS X plists | string | real | integer | true, false | data | date | nil |
JSON (JavaScript) | string | number | number | true, false | N/A | Date | nil |
YAML tags | str | int | float | bool | null (base 64) | N/A | null |
SQL (JDBC) | char,varchar | float, double, real | decimal, numeric | bit | binary | date, time, timestamp | ? |
C | char[] | float, double | int, long, short | bool, int | char[] | N/A | (void*)0 |
Java | char, String | float, double | int, long, short, byte | boolean | N/A | util.Date | null |
PHP | string | float (double) | integer | boolean | array | N/A | NULL |
Perl | array | scalar | scalar | scalar | array | N/A | |
Python | str | float, complex | int, long | bool | binascii, base64 | time,datetime | |
Ruby + lib | String | Float | Fixnum, Bignum | TrueClass,FalseClass | Hash | Date | NilClass |
REBOL | string! | decimal! | integer! | logic! | binary! | date!, time! | none! |
Analysis
The most common set of datatypes appears to be those represented by XML-RPC, which (perhaps fortunately) also has historical precedence on the web:
- string
- double
- int [i4] - 4-byte integer (32-bit)
- boolean (0,1)
- base64
- dateTime[.iso8601]
Whlle not perfect, these certainly cover the 80% case, and are reasonably well-defined. That said, there are a number of open questions about how to use them:
- should 'string' also be explicitly specified, or can it be assumed?
- does 'int' always mean 32-bits?
- If so, what should be used for 64-bit integers or cryptographic (256-bit+) numbers?
- Python's 'long' is simple, but ambiguous.
- Ruby's BigNum is clear but much less common.
- XML-Schema has so many types it is hard to say.
- SQL's "decimal", perhaps?
- If not, how should conforming implementations react to longer integers than they can handle?
- If so, what should be used for 64-bit integers or cryptographic (256-bit+) numbers?
- Is it worth deviating from the standard to allow "dateTime" as an alias? (the one case where XML Schema is actually simpler)
Proposals
The proposal is to adopt XML-RPC scalar values as the class names for typed microformats, with the following caveats:
- the alias 'i4' for integer SHOULD not be used
- the name 'long' MAY be used for 64-bit or longer integers
- for 'dateTime'
- the trailing '.iso8601' MUST be omitted, as '.' is not (always?) valid in CSS class names
- date/time formats SHOULD follow the W3C profile of ISO 8601
- if no datatype is specified, an implementation MAY either attempt to infer a datatype from the syntax of the value, or simply assert that the value is a string. Thus, conforming implementations SHOULD always explicitly label strings.
To indicate that a particular micforomat uses typed values, precede that microformat with the class name 'typed', as in:
< div class="typed xoxo">
References
- Datatypes in Wikipedia
- Origional datatype discussion
- Original plist datatype mapping proposal
- Revised xoxo datatype proposal