Datatypes in XML
Datatypes in XML
Overview
Context: DSDL Part 5 What is data in XML? Why do we need to type data?
validation, documentation, authoring support, application support
DSDL
ISO-standardised schema language(s) W3C XML Schema is for the big boys
want to do data binding into databases or programming languages primarily data-oriented content database vendors, web service providers
people who jumped on the XML bandwagon, and are distorting it to satisfy their requirements
Data in XML
Data appears in:
attribute values content of text-only elements mixed-content elements, more rarely
Whitespace weirdness
line endings normalised to #xA whitespace in attributes replaced with spaces whitespace chars can be escaped using entities
Sep 24, 2004 Datatypes in XML 4
Data in XML
Uses in *real* XML
human-readable rather than machinereadable
for presentation rather than processing
Authoring support
enable applications to prompt user for values rather than using separate validation step
pop-ups for enumerated values calendars for dates sliders for numbers
Datatypes in XML
Survey of Data
Well-known markup languages
XML attributes DocBook XHTML SVG MathML Dublin Core XInclude XSLT XSL-FO XML Schema RELAX NG XForms
Designed by people who should know what they're doing, so bound to be good
or "designed by committee, so bound to be bad"
Numbers
integers (7) decimals (7.5) scientific format (7.5E3)
Booleans
Sep 24, 2004
Datatypes in XML
10
Enumerated Values
Listings of possible values
xml:space - "preserve" | "default" XInclude - "xml" | "text"
May be case-insensitive
XHTML LinkTypes
Lists
Lists of values
whitespace-separated
most common NMTOKENS, IDREFS
comma-separated
XHTML URI lists XHTML media-type lists (as in CSS2)
whitespace-or-comma-separated
SVG lists
semi-colon-separated
Dublin Core Separated Values
Sep 24, 2004 Datatypes in XML 12
many examples:
Sep 24, 2004
dates and times URI references colours in RGB notation SVG path data SVG transformations MathML group alignment XInclude accept, accept-language attributes XPath 2.0 sequence types XPath subsets (as in W3C XML Schema) P3P type names (as in XForms)
Datatypes in XML 14
Datatypes in XML
15
application context
lengths - ems and exs proportions - percentages and *s 'auto'/'inherit' in XSL-FO
Sep 24, 2004 Datatypes in XML 16
Datatypes in XML
17
Lists must be space separated, and items must be of the same type Can use regexes for lengths etc., but then comparisons are string comparisons
Sep 24, 2004 Datatypes in XML 19
Supports enumerated values Supports "except" and "choice" Datatype libraries can be used
test validity of value, and equality of values pass in parameter values and context information usually uses XML Schema datatype library
Sep 24, 2004 Datatypes in XML 20
RNG schema
validator
Datatypes in XML
21
XSLT stylesheet
Datatypes in XML
22
Lexical Datatyping
Values are sequences of characters Values have properties
accessible via API properties have different types aren't necessarily independent
3pc points: 36 units: pc PT2M seconds: 120 2003-12-19 year: 2003 month: 12 day: 19 isLeapYear: false
23
Datatypes in XML
Example
colourNames
collation: colourCollation params: lightest, darkest props: red, green, blue, hue, saturation, luminance
Datatype Definitions
Extensible set of tests on values
valid values must pass all the tests
Negative conditions
Sep 24, 2004 Datatypes in XML 26
Datatype Mapping
How value in one datatype maps to value (or properties) in another
unidirectional: every source value must be mappable to target
Supports casting
colourNames blue
RRGGBB #0000FF
Datatypes in XML
27
Supertyping
Ease definition of types
inherit properties and collation can just alter values of parameters
Example
byte 160 hexByte A0
colour
colourName blue
RRGGBB #0000FF
Datatypes in XML
29
Partial Ordering
Occurs with durations and date/times (due to timezones)
xs:duration('P1M') = xs:duration('P30D')
Context Information
Standard extension functions for Infoset information:
inf:ns-for-prefix($prefix) returns URI inf:prefix-declared($prefix) returns boolean inf:entity-declared($entity) returns boolean
Implementations can define additional extension functions for other context information
Sep 24, 2004 Datatypes in XML 36
Status
Draft spec available at: http://www.jenitennison.com/datatypes
schemas also available there comments, please!
No implementations yet
help, please!
That's it
questions, please!
Sep 24, 2004 Datatypes in XML 40