XML technologies / XML Schema / XML Schema element reference / xs:element (global definition)

(Excerpt from “XML Schema” by Eric van der Vlist)

Global element definition that can be referenced within the same schema and by other schemas.

<xs:element
    abstract = xs:boolean : "false"
    block = ( "#all" | list of ( "extension" | "restriction" | "substitution" ) )
    default = xs:string
    final = ( "#all" | list of ( "extension" | "restriction" ) )
    fixed = xs:string
    id = xs:ID
    name = xs:NCName
    nillable = xs:boolean : "false"
    substitutionGroup = xs:QName
    type = xs:QName
    {beliebige Attribute mit einem Nicht-Schema-Namensraum}
    >
    Content: (xs:annotation?, (xs:simpleType | xs:complexType)?, (xs:unique | xs:key | xs:keyref)*)
</xs:element>

May occur within: xs:schema

Description

All elements defined at the top level of a schema, that is, with an xs:element immediately below the xs:schema document element, are considered globally defined.

Globally defined elements have global scope: they can be referenced by their qualified name anywhere in the schema and in any schema that imports or includes it. They can also be used as document elements in instance documents.

Elements are identified by their qualified name, but the attribute name expects the local name.

The type definition assigns a simple or complex data type to the element. This assignment can use the attribute type to reference a simple or complex data type by its qualified name, or be inline, embedding the definition of the simple type, element xs:simpleType, or complex-type definition, element xs:complexType, within element xs:element.

A default value can be defined using the attribute default. However, element defaults have different semantics from attribute defaults. An element is not created if absent from the instance document; the default is applied only when the element is present and empty.

Several control attributes can be specified in element definitions; see the attributes abstract, blocked, final, fixed and nillable.

Element definitions are also where substitution groups are defined using the attribute substitutionGroup, which references the substitution group’s head. Any global element that is not final can be chosen as a substitution group head. Any reference to that head can be replaced in instance documents by a member of the substitution group, provided these substitutions have not been blocked by the attribute block. The relationship is transitive: if the head of substitution group “A” is a member of substitution group “B”, members of “A” are also considered members of “B”.

Restrictions

There is no way to define global elements that cannot be used as document elements. If this is required, the workaround is to define all but one element locally. Simple and complex types or element groups can replace global elements to define reusable content models, and these types can be referenced from the single globally defined element.

Identifying global elements by their qualified name makes it impossible to define several global elements with the same qualified name. If a schema must include several element definitions with the same qualified name and different data types, all definitions except one must be declared locally. Here too, simple and complex types or element groups can replace global elements to define reusable content models.

All globally defined elements must be qualified if a target namespace is defined for the schema: they must all belong to it. Conversely, if no target namespace is defined, all globally or locally defined elements must be unqualified.

Default and fixed values are specified in attributes and therefore apply only to simple-type elements.

Elements cannot be redefined directly. To redefine an element, either place it in a group and redefine the group, or define it using a global complex type and then redefine that type.

Example

<xs:element name="name" type="xs:string"/>

Attributes

abstract
Controls whether the element may be used directly in instance documents. If the value is true, the element can still define content models but must be replaced in instance documents by a substitution group.

block
Controls whether type or substitution-group substitution may apply to an element. #all blocks all substitutions, substitution blocks substitution groups, and extension and restriction block substitution, through either xsi:type or substitution groups, by elements or types derived by extension or restriction from the element’s type. The default is set by attribute blockDefault of parent element xs:schema.

default
Default element value, necessarily simple content because specified in an attribute. Applies only to empty elements present in the document. Attributes fixed and default are mutually exclusive.

final
Controls whether the element can head a substitution group for elements whose types derive by extension or restriction from its type. The default value of this attribute is set by attribute finalDefault of parent element xs:schema.

fixed
Fixes a simple-content element’s value. Also used as the default, supplied to the application if the element is empty. Attributes fixed and default are mutually exclusive.

id
Element ID according to W3C XML Schema.

name
Local name of the element, without a namespace prefix.

nillable
If set to true, the element can be declared using attribute xsi:nil in instance documents as nil.

substitutionGroup
Qualified name of the head of the substitution group to which this element belongs.

type
Qualified name of a simple or complex type; must be omitted if a simple- or complex-type definition is embedded.

   

 

 

 

back to top