-
Notifications
You must be signed in to change notification settings - Fork 17
How to work with literal data types
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.
- xdi2.core.features.datatypes.DataTypes: A helper class to work with data types, i.e. get or set them.
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!
- 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.
- LiteralDatatypeRules on the OASIS XDI TC wiki
This work is licensed under a Creative Commons Attribution 4.0 International License.