saxon:schema

Returns information about the schema.

schema() ➔ function(*)?

There are no arguments

Result

function(*)?

schema($kind as xs:string, $name as xs:QName) ➔ function(*)?

Arguments

 

$kind

xs:string

The kind of component required

 

$name

xs:QName

The name of the component required

Result

function(*)?

Namespace

http://saxon.sf.net/

Saxon availability

Requires Saxon-EE. Implemented since Saxon 9.5.

Details

In a non-schema-aware configuration, both functions return the empty sequence.

In a schema-aware configuration, the first function returns the schema component representing the "schema as a whole", that is, the schema components from all the schema documents that have been loaded into the Configuration. The second function returns a specific named schema component, for example an element declaration.

With the two-argument function, the first argument must be one of "type definition", "attribute declaration", "element declaration", "attribute group definition", "model group definition", "notation declaration", or "identity-constraint definition"; the second argument is the QName identifying the component by its target namespace and local name properties.

The returned schema component is represented as a function. This function accepts a property name as a string argument, and returns the value of the property. The value of the property may be a simple value such as a boolean or a string, or it may be a sequence of such values. In some cases the value of a property is another schema component; this will be returned as a function item, which can be dynamically invoked to determine its properties, and so on. ('Property records' in the schema component model are represented in exactly the same way as schema components.)

The model is faithful to the specification of the schema component model as it appears in the XSD 1.1 specification from W3C. There are a few small variations:

  1. Saxon currently does not provide access to annotations (they are discarded at schema processing time)

  2. One or two other properties are not fully implemented, for example, {context} and {fundamental facets}

  3. The types available directly from the Schema do not include built-in types

  4. Saxon represents multiple patterns and assertions of a simple type as multiple facet objects rather than a single facet object

  5. There's one property that's hard to represent directly in the XDM data model: the value of the enumeration facet is a sequence of sequences. So Saxon is currently exposing the enumeration values as string values rather than typed values.

Every component has an additional property class which tells you what kind of schema component it is. This is particularly necessary for the components representing facets, where the class is the only way of telling, for example, whether you have a minInclusive or a maxExclusive facet.

Most components have an additional property implementation whose value is the wrapped Java object representing the component in Saxon's implementation. For example, for an element declaration the implementation property returns an object of Java type com.saxonica.ee.schema.ElementDecl whose methods can be used using the normal facilities for reflexive extension functions.

The complete list of properties is given in the tables below:

Assertion

Property name Type Value
class string "Assertion"
implementation java:com.saxonica.ee.schema.Assertion Java object
test XPath Property Record

Attribute declaration

Property name Type Value
class string "Attribute Declaration"
implementation java:com.saxonica.ee.schema.AttributeDecl
name string Local name of the attribute
target namespace string Namespace URI of the attribute
type definition Simple Type or Complex Type
scope A function with properties ("class":"Scope", "variety": "global" or "local", "parent": the containing Complex Type or Attribute Group)
value constraint If present, a function with properties ("class": "Value Constraint", "variety": "fixed" or "default", "value": atomic value, "lexical form": string
inheritable boolean

Attribute group declaration

Property name Type Value
class string "Attribute Group Definition"
implementation java:com.saxonica.ee.schema.AttributeGroupDecl
name string Local name of the attribute group
target namespace string Namespace URI of the attribute group
attribute uses Sequence of (Attribute Use)
attribute wildcard Optional Attribute Wildcard

Attribute use

Property name Type Value
class string "Attribute Use"
implementation java:com.saxonica.ee.schema.AttributeUse
required boolean true if the attribute is required, false if optional
value constraint See Attribute Declaration
inheritable boolean

Attribute wildcard

Property name Type Value
class string "Wildcard"
implementation java:com.saxonica.ee.schema.Wildcard
namespace constraint function with properties ("class": "Namespace Constraint", "variety": "any"|"enumeration"|"not", "namespaces": sequence of xs:anyURI, "disallowed names": list containing QNames and/or the strings "defined" and "definedSiblings"
process contents string ("strict"|"lax"|"skip")

Complex type

Property name Type Value
class string "Complex Type"
implementation java:com.saxonica.ee.schema.ComplexType (or a subtype such as UserComplexType)
name string Local name of the type (empty if anonymous)
target namespace string Namespace URI of the type (empty if anonymous)
base type definition Complex Type Definition
final Sequence of strings ("restriction"|"extension")
context Empty sequence (not implemented)
derivation method string ("restriction"|"extension")
abstract boolean
attribute uses Sequence of Attribute Use
attribute wildcard Optional Attribute Wildcard
content type function with properties: ("class":"Content Type", "variety":string ("element-only"|"empty"|"mixed"|"simple"), particle: optional Particle, "open content": function with properties ("class":"Open Content", "mode": string ("interleave"|"suffix"), "wildcard": Wildcard), "simple type definition": Simple Type)
prohibited substitutions Sequence of strings ("restriction"|"extension")
assertions Sequence of Assertion

Element declaration

Property name Type Value
class string "Complex Type"
implementation java:com.saxonica.ee.schema.ComplexType (or a subtype such as UserComplexType)
name string Local name of the type (empty if anonymous)
target namespace string Namespace URI of the type (empty if anonymous)
type definition Simple Type or Complex Type
type table function with properties ("class":"Type Table", "alternatives": sequence of Type Alternative, "default type definition": Simple Type or Complex Type)
scope function with properties ("class":"Scope", "variety": ("global"|"local"), "parent": optional Complex Type)
value constraint see Attribute Declaration
nillable boolean
identity-constraint definitions Sequence of Identity Constraint
substitution group affiliations Sequence of Element Declaration
substitution group exclusions Sequence of strings ("restriction"|"extension")
disallowed substitutions Sequence of strings ("restriction"|"extension"|"substitution")
abstract boolean

Element wildcard

Properties are the same as for Attribute Wildcard

Facet

Property name Type Value
class string The name of the facet, for example "minLength" or "enumeration"
implementation A subclass of java:com.saxonica.ee.schema.Facet
value depends on facet The value of the facet
fixed boolean
typed-value For the enumeration facet only, array(xs:anyAtomicType*) An array containing the enumeration values, each of which may in general be a sequence of atomic values. (Note: for the enumeration facet, the "value" property is a sequence of strings, regardless of the actual type)

Identity constraint

Property name Type Value
class string "Identity-Constraint Definition"
implementation java:com.saxonica.ee.schema.IdentityConstraint (or a subclass)
name string Local name of the constraint
target namespace string Namespace URI of the constraint
identity-constraint category string ("key"|"unique"|"keyRef")
selector XPath Property Record
fields Sequence of XPath Property Record
referenced key (For keyRef only): Identity Constraint The corresponding key constraint

Model group

Property name Type Value
class string "Model Group"
implementation java:com.saxonica.ee.schema.ModelGroup
compositor string ("sequence"|"choice"|"all")
particles Sequence of Particle

Model group definition

Property name Type Value
class string "Model Group Definition"
implementation java:com.saxonica.ee.schema.ModelGroupDefinition
name string Local name of the model group
target namespace string Namespace URI of the model group
model group Model Group

Notation

Property name Type Value
class string "Notation Declaration"
implementation java:com.saxonica.ee.schema.Notation
name string Local name of the notation
target namespace string Namespace URI of the notation
system identifier anyURI
public identifier string

Particle

Property name Type Value
class string "Particle"
implementation java:com.saxonica.ee.schema.Particle or a subtype
min occurs integer
max occurs integer, or string("unbounded")
term Element Declaration, Element Wildcard, or ModelGroup

Simple type

Property name Type Value
class string "Simple Type Definition"
implementation java:com.saxonica.ee.schema.SimpleType or a subclass
name string Local name of the type (empty if anonymous)
target namespace string Namespace URI of the type (empty if anonymous)
final Sequence of string("restriction"|"extension"|"list"|"union")
context containing component
base type definition Simple Type
facets Sequence of Facet
fundamental facets Empty sequence (not implemented)
variety string ("atomic"|"list"|"union")
primitive type definition Simple Type
item type definition (for list types only) Simple Type
member type definitions (for union types only) Sequence of Simple Type

Type alternative

Property name Type Value
class string "Type Alternative"
implementation java:com.saxonica.ee.schema.TypeAlternative
test XPath Property Record
type definition Simple Type or Complex Type

XPath property record

Property name Type Value
namespace bindings Sequence of functions with properties ("prefix": string, "namespace": anyURI)
default namespace anyURI
base URI anyURI The static base URI of the XPath expression
expression string The XPath expression as a string

Here's a simple example that tests whether a particular element has element-only content:

let $bookDecl := saxon:schema('element declaration', QName('', 'book')) return if ($bookDecl('type definition')('variety') = 'element-only') then ... else ...