Skip to content

How to work with literal data types

peacekeeper edited this page Nov 18, 2014 · 5 revisions

Warning: This information is incomplete and/or outdated.

On the level of the XDI graph model, all literals are of type string, and XDI at this fundamental graph level does not distinguish between data types. It is however possible to associate data types (and other metadata) with literals by adding additional statements to a graph. This concept is closely related to XDI dictionary functionality.

Interfaces and Classes

Example

The following sample XDI graph contains a literal whose data type is xsd:int:

=markus$!(+age)/!/(data:,33)
=markus$!(+age)/$is+/+$xsd$int!

With XDI2, it is possible to get or set that data type using code like the following to get or set the data type on a literal:

Literal literal = graph.findLiteral(new XRI3Segment("=markus$!(+age)"));
	
System.out.println(DataTypes.getLiteralDataType(literal));  // +$xsd$int!
DataTypes.setLiteralDataType(literal, new XRI3Segment("+$xsd$string!"));

There are also helper methods for creating data types XRIs, e.g.:

XRI3Segment dataTypeXri = DataTypes.dataTypeXriFromXsdType("string");  // +$xsd$string!

Further work

  • The supported data types still have to be finalized.
  • Multiplicity has to be taken into account. For example, if an XDI collection has a certain data type, then that type is inherited by the members of the collection.
  • Certain serialization formats may have special support for certain data types, e.g. XDI/JSON.

See also

Clone this wiki locally