3.6. Derived Type properties
A Derived Type has the following properties:
$kind (JSON string): the kind of the Type. One of "atomic, "object", "array", "union".
$name (JSON string): a string containing the Qualified Name (as defined above) of this Type.
$baseType (JSON string): a string containing the Qualified Name of the Type which is the base type of this Type.
$about (JSON value): free content (documentation, comments, ...).
various facets properties. Which facets are available defines on the $kind of the Type.
There are the following constraints on these properties:
$name is optional and must live in the namespace of the Schema Document in which this Type is defined.
A prefix may not appear twice in the $imports.
Types defined directly in the top-level $types array must be named.
$baseType must refer to a known Type - builtin, in the same Schema Document or in an imported Schema Document. In particular, if a prefix is used, it must be bound to an imported namespace.
If $kind is "object", $baseType must be "object" if provided.
If $kind is "array", $baseType must be "array" if provided.
If $kind is "union", $baseType must be "item" if provided.
If $kind is "atomic", $baseType must be the Qualified Name of an existing Atomic Type.
Here is an example of an invalid Schema Document, because it does not fulfill many of the above constraints.
{
"$namespace" : "http://www.example.com/my-schema",
"$types" : [
{
"$kind" : "atomic",
"$name" : "type1",
"$baseType" : "unbound:type", (: prefix is not bound :)
"$maxInclusive" : 4
},
{
"$kind" : "atomic",
"$name" : "Q{http://www.example.com/other}type2", (: the namespace must match that of the Schema document :)
"$baseType" : "integer",
"$maxInclusive" : 4
},
{
"$kind" : "atomic",
"$name" : "Q{http://www.example.com/my-schema}type3",
"$baseType" : "object", (: base type MUST also be an atomic type :)
"$maxInclusive" : 4
},
{
"$kind" : "object",
"$name" : "object1",
"$baseType" : "type1" (: base type MUST be "object":)
"$content" : {}
},
{
"$kind" : "object",
"$name" : "object2",
"$baseType" : "object1" (: base type MUST be "object":)
}
]
}
There are two facets common to all types:
$enumeration (array of JSON values): Constrains a value space to a specified set of values.
$constraints (array of JSON strings): Constrains a value space to the values for which a set of JSONiq queries evaluates to true. In these JSONiq queries, the context item is bound to the Serialized Instance being validated, after parsing.
{
"$namespace" : "http://www.example.com/my-schema",
"$types" : [
{
"$kind" : "object"
(: "$baseType" : "object" is implicit :)
"$name" : "two-objects",
"$enumeration" : [ { "foo" : "bar" }, {} ] (: only these two objects :)
},
{
"$kind" : "array"
(: "$baseType" : "array" is implicit :)
"$name" : "uniform-array",
"$constraints" : [ "every $i in 1 to size($$) satisfies deep-equals($$($i), $$(1))" ] (: all members must be the same :)
},
]
}
The following JSON object is valid against Q{http://www.example.com/my-schema}two-objects.
{ "foo" : "bar" }
The following JSON array is valid against Q{http://www.example.com/my-schema}uniform-array.
[ 42, 42, 42 ]