Introduction to XMLSchema Part2 : Datatypes.

The W3C XML Schema Part 2: Datatypes recommendation states:

XML Schema: Datatypes is part 2 of the specification of the XML Schema language. It defines facilities for defining datatypes to be used in XML Schema s as well as other XML specifications. The datatype language, which is itself represented in XML 1.0, provides a superset of the capabilities found in XML 1.0 document type definitions (DTDs) for specifying datatypes on elements and attributes.”

The XML Schema datatypes definition language is, as it’s parental language XML, an extensible language. It is implemented in many xml languages or dialects as a way to distinct and validate values. Examples are RDF and Xforms. The following code example uses an XML Schema (xs) datatype to distinct a value used in RDF. The code is taken from the RDF recommendation

Example 1. RDF’s use of xs datatypes.

  1. <?xml version="1.0"?>
  2.   <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  3.          xmlns:ex="http://example.org/stuff/1.0/">
  4.         <rdf:Description rdf:about="http://example.org/item01">
  5.                 <ex:size
  6.                      rdf:datatype="http://www.w3.org/2001/XMLSchema#int">
  7.                 123</ex:size>
  8.         </rdf:Description>
  9.   </rdf:RDF>

Line 5 states that the datatype of the value given for the ex:size of http://example.org/item01 (123) is int

Example 2. XForms use of xs datatypes.

  1. <xforms:model>
  2.         <xforms:bind nodeset="/my:payment/my:number"
  3.                      relevant="/my:payment/@method = ‘cc’"
  4.                      required="true()"
  5.                      type="my:ccnumber"/>
  6.  
  7.         <xforms:bind nodeset="/my:payment/my:expiry"
  8.                      relevant="/my:payment/@method = ‘cc’"
  9.                      required="true()"
  10.                      type="xsd:gYearMonth"/>
  11.  
  12.         <xsd:schema>
  13.                 <xsd:simpleType name="ccnumber">
  14.                         <xsd:restriction base="xsd:string">
  15.                                 <xsd:pattern value="d{14,18}"/>
  16.                         </xsd:restriction>
  17.                 </xsd:simpleType>
  18.         </xsd:schema>
  19. </xforms:model>

This XForms model uses XML Schema datatypes twice: First while using the buil-in datatype gYearMonth to type the node /my:payment/my:expiry and then by deriving a new datatype called ccnumber from the buil-in string datatype. This example is taken from the XForms recommendation

Type System

A datatype is (in this recommendation) a 3-tuple consisting of value space, lexical space and a set of characterizing facets.

Figure 1. The 3-tuple : value space, lexical space and facets

The 3-tuple : value space, lexical space and facets

The value space holds the possible values and the lexical space holds the possible lexical representations of those values. If a datatype has more possible lexical representations - eg. like time or dates – the lexical space is referred to as ‘canonical’.

Facets define or restrict the value space of the datatype. The fundamental facets (equal, ordered, bounded, cardinality and numeric) semantically characterize while constraining facets (length, minLength, maxLength, pattern, enumeration, whiteSpace, maxInclusive, maxExclusive, minExclusive, minInclusive, totalDigits, fractionDigits) constrain the value space.

Datatypes can also be categorized by specific dimensions (Characterization dichotomies). The recommendation comes with a list of build-in datatypes, all other datatypes are user-derived (eg. written by you). Some build-in datatypes are primitive; They form the basis from which other datatypes are derived. Eg. A token is derived from normalizedString, which is derived from string. String is a primitive datatype.

Figure 2. Datatype Dichotomies

dichotomies

The most remarkable dichotomy is atomic versus list versus union. Datatypes can be either atomic (they hold only one indivisible value), lists (they hold a – possible empty - list of indivisible values) or unions (they combine the value and lexical space of one or several datatypes).



Figure 3. The build-in datatypes

buildintypes


The recommendation decribes all these datatypes into detail.


[1] XML Schema Part 2: Datatypes Second Edition [http://www.w3.org/TR/xmlschema-2/]

[2] RDF/XML Syntax Specification (Revised) [http://www.w3.org/TR/rdf-syntax-grammar/]

[3] XForms 1.0 (Second Edition) [http://www.w3.org/TR/xforms/]

1 comment to Introduction to XMLSchema Part2 : Datatypes.

  • [...] defined by the XML Schema Datatypes specification. And that’s something I ran into more often …Introduction to XMLSchema Part2 : Datatypes. | Polemian vzwThe W3C XML Schema Part 2: Datatypes recommendation states: XML Schema: Datatypes is part 2 of the [...]

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>