EXPath

DataType Conversion Module 1.0

EXPath Candidate Module 08 November 2012

Latest version:
http://expath.org/spec/datatype-conversion
Editor:
Claudius Teodorescu, XML Consultant

Abstract

This proposal defines a module for handling various datatypes. It has been designed to be compatible with XQuery 3.0 and XSLT 3.0, as well as any other standard based on XPath 3.0.

As this is a work in progress, more details about it can be found at Datatype Conversion Functions Comparison.

Table of Contents

1 Introduction
1.1 Namespace conventions
1.2 Error management
2 Datatype Systems
2.1 The datatypes:register-datatype-system function
2.2 The datatypes:deregister-datatype-system function
3 Conversions
3.1 xs:base64Binary to other datatypes
3.1.1 The datatypes:base64Binary-to-byte function
3.1.2 The datatypes:base64Binary-to-string function
3.2 xs:byte to other datatypes
3.2.1 The datatypes:byte-to-base64Binary function
3.2.2 The datatypes:byte-to-hexBinary function
3.3 xs:hexBinary to other datatypes
3.3.1 The datatypes:hexBinary-to-byte function
3.3.2 The datatypes:hexBinary-to-string function
3.4 xs:string to other datatypes
3.4.1 The datatypes:string-to-base64Binary function
3.4.2 The datatypes:string-to-hexBinary function
3.4.3 The datatypes:string-to-integer function
3.5 xs:integer to other datatypes
3.5.1 The datatypes:integer-to-string function
4 User defined datatypes
4.1 The datatypes:define function
5 Mappings
5.1 The datatypes:set-mapping function
5.2 The datatypes:get-mapping function
5.3 The datatypes:delete-mapping function
6 Characterizing Operations

Appendices

A References
B Summary of Error Conditions


1 Introduction

This module is designed for datatypes handling, providing conversions between datatypes that are not covered by casts mentioned in [XPath and XQuery Functions and Operators 3.0], as well as other functions related to datatypes.

1.1 Namespace conventions

The module defined by this document defines functions and elements in the namespace http://expath.org/ns/datatypes. In this document, the datatypes prefix, when used, is bound to this namespace URI.

Error codes are defined in the namespace http://expath.org/ns/error. In this document, the err prefix, when used, is bound to this namespace URI.

1.2 Error management

Error conditions are identified by a code (a QName). When such an error condition is reached during the execution of the function, a dynamic error is thrown, with the corresponding error code (as if the standard XPath function error had been called).

2 Datatype Systems

These are functions allowing operations on datatype systems. The implementations should register by default the XML datatype system ([W3C XML Schema Definition Language (XSD) 1.1 Part 1: Structures]). Other datatype systems are implementation dependent.

2.1 The datatypes:register-datatype-system function

This function registers a datatype system.

datatypes:register-datatype-system($uri as xs:anyURI) as empty()
  • $uri is the uri of the datatype system to be registered.

2.2 The datatypes:deregister-datatype-system function

This function deregisters a datatype system.

datatypes:deregister-datatype-system($uri as xs:anyURI) as empty()
  • $uri is the uri of the datatype system to be deregistered.

3 Conversions

These functions are for conversions between various datatypes.

3.1 xs:base64Binary to other datatypes

These functions provide conversion from xs:base64Binary datatype to other datatypes.

3.1.1 The datatypes:base64Binary-to-byte function

This function converts from xs:base64Binary to xs:byte.

datatypes:base64Binary-to-byte($data as xs:base64Binary?) as xs:byte*
  • $data is the data to be converted.

3.1.2 The datatypes:base64Binary-to-string function

This function converts from xs:base64Binary to xs:string.

datatypes:base64Binary-to-string($data as xs:base64Binary?) as xs:string?
datatypes:base64Binary-to-string($data as xs:base64Binary?,
		$encoding as xs:string) as xs:string?
  • $data is the data to be converted.

  • $encoding is the encoding used for conversion. The default value is UTF-8. If it is specified an unsupported encoding, this is an error [err:DT01].

3.2 xs:byte to other datatypes

These functions provide conversion from xs:byte datatype to other datatypes.

3.2.1 The datatypes:byte-to-base64Binary function

This function converts from xs:byte to xs:base64Binary.

datatypes:byte-to-base64Binary($data as xs:byte*) as xs:base64Binary?
  • $data is the data to be converted.

3.2.2 The datatypes:byte-to-hexBinary function

This function converts from xs:byte to xs:hexBinary.

	datatypes:byte-to-hexBinary($data as xs:byte*) as xs:hexBinary?
	
  • $data is the data to be converted.

3.3 xs:hexBinary to other datatypes

These functions provide conversion from xs:hexBinary datatype to other datatypes.

3.3.1 The datatypes:hexBinary-to-byte function

This function converts from xs:hexBinary to xs:byte.

	datatypes:hexBinary-to-byte($data as xs:hexBinary?) as xs:byte*
	
  • $data is the data to be converted.

3.3.2 The datatypes:hexBinary-to-string function

This function converts from xs:hexBinary to xs:string.

	datatypes:hexBinary-to-string($data as xs:hexBinary?) as xs:string?
	
	datatypes:hexBinary-to-string($data as xs:hexBinary?,
			$encoding as xs:string) as xs:string?
	
  • $data is the data to be converted.

  • $encoding is the encoding used for conversion. The default value is UTF-8. If it is specified an unsupported encoding, this is an error [err:DT01].

3.4 xs:string to other datatypes

These functions provide conversion from xs:string datatype to other datatypes.

3.4.1 The datatypes:string-to-base64Binary function

This function converts from xs:string to xs:base64Binary.

	datatypes:string-to-base64Binary($data as xs:string?) as xs:base64Binary?
	
	datatypes:string-to-base64Binary($data as xs:string?,
			$encoding as xs:string) as xs:base64Binary?
	
  • $data is the data to be converted.

  • $encoding is the encoding used for conversion. The default value is UTF-8. If it is specified an unsupported encoding, this is an error [err:DT01].

3.4.2 The datatypes:string-to-hexBinary function

This function converts from xs:string to xs:hexBinary.

	datatypes:string-to-hexBinary($data as xs:string?) as xs:hexBinary?
	
	datatypes:string-to-hexBinary($data as xs:string?,
			$encoding as xs:string) as xs:hexBinary?
	
  • $data is the data to be converted.

  • $encoding is the encoding used for conversion. The default value is UTF-8. If it is specified an unsupported encoding, this is an error [err:DT01].

3.4.3 The datatypes:string-to-integer function

This function converts from xs:string to xs:integer.

	datatypes:string-to-integer($data as xs:string?,
			$radix as xs:integer) as xs:integer?
	
  • $data is the data to be converted.

  • $radix is the radix used to provide the conversion of $data ($data is considered being in radix $radix).

3.5 xs:integer to other datatypes

These functions provide conversion from xs:integer datatype to other datatypes.

3.5.1 The datatypes:integer-to-string function

This function converts from xs:integer to xs:string.

	datatypes:integer-to-string($data as xs:integer?,
			$radix as xs:integer) as xs:string?
	
  • $data is the data to be converted.

  • $radix is the radix used to provide the conversion of $data.

4 User defined datatypes

These are functions related to the user defined datatypes.

4.1 The datatypes:define function

This function defines a user defined datatype.

5 Mappings

These are functions related to mappings between various datatype systems.

5.1 The datatypes:set-mapping function

This function sets mappings between datatypes belonging to different datatype systems. One can map one or more source datatypes to one target datatype, or one source datatype to one or more target datatypes.

datatypes:set-mapping($source-datatype as xs:string+,
		$target-datatype as xs:string+) as empty()
  • $source-datatype is the source datatype to set the mapping for.

  • $target-datatype is the target datatype to set the mapping for.

5.2 The datatypes:get-mapping function

This function returns the mapping(s) between datatypes belonging to different datatype systems. If there are more target datatypes mapped, they are all returned.

datatypes:get-mapping($source-datatype as xs:string,
		$target-datatype-system as xs:anyURI) as xs:string*
  • $source-datatype is the datatype to get the mapping(s) of.

  • $target-datatype-system is the datatype system to get the mapping(s) from.

5.3 The datatypes:delete-mapping function

This function deletes the mapping between datatypes belonging to different datatype systems. If they are more source or target datatypes, each individual mapping between each one of them will be deleted.

datatypes:delete-mapping($source-datatype as xs:string+,
		$target-datatype as xs:string+) as empty()
  • $source-datatype is the source datatype to delete the mapping for.

  • $target-datatype is the target datatype to delete the mapping for.

6 Characterizing Operations

These are functions allowing operations on the registered datatypes. (https://w3.org/1999/05/06-xmlschema-2/#characterizing-operations)

A References

XPath 3.0
XML Path Language (XPath) 3.0. Jonathan Robie, Don Chamberlin, Michael Dyck, John Snelson, editors. W3C Working Draft, 13 December 2011.
XSLT 3.0
XSL Transformations (XSLT) Version 3.0. Michael Kay, editor. W3C Working Draft, 10 July 2012.
XQuery 3.0
XQuery 3.0: An XML Query Language. Jonathan Robie, Don Chamberlin, Michael Dyck, John Snelson, editors. W3C Working Draft, 13 December 2011.
XPath and XQuery Functions and Operators 3.0
XPath and XQuery Functions and Operators 3.0. Michael Kay, editor. W3C Working Draft, 13 December 2011.
XQuery and XPath Data Model 3.0
XQuery and XPath Data Model 3.0. Norman Walsh, Anders Berglund, John Snelson, editors. W3C Working Draft, 13 December 2011.
W3C XML Schema Definition Language (XSD) 1.1 Part 1: Structures
W3C XML Schema Definition Language (XSD) 1.1 Part 1: Structures. Henry S. Thompson, Noah Mendelsohn, David Beech, Murray Maloney, editors. W3C Recommendation, 5 April 2012.
W3C XML Schema Definition Language (XSD) 1.1 Part 2: Datatypes
W3C XML Schema Definition Language (XSD) 1.1 Part 2: Datatypes. David Peterson, Shudi (Sandy) Gao 高殊镝, Ashok Malhotra, C. M. Sperberg-McQueen, Henry S. Thompson, editors. W3C Recommendation, 5 April 2012.
RFC 2045 - Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet Message Bodies
Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet Message Bodies. N. Freed, N. Borenstein, editors. Network Working Group, November 1996.

B Summary of Error Conditions

err:DT01
The encoding is not supported.