XML technologies / XML Schema / XML Schema element reference / xs:element (reference or local definition)
(Excerpt from “XML Schema” by Eric van der Vlist)
Reference to a global element declaration or local definition; local definitions cannot be referenced.
<xs:element
block = ( "#all" | list of ( "extension" | "restriction" | "substitution" ) )
default = xs:string
fixed = xs:string
form = ( "qualified" | "unqualified" )
id = xs:ID
maxOccurs = ( xs:nonNegativeInteger | "unbounded" ) : "1"
minOccurs = xs:nonNegativeInteger : "1"
name = xs:NCName
nillable = xs:boolean : "false"
ref = 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:choice (outside a group), xs:choice (within a group), xs:sequence (within a group), xs:sequence (outside a group)
Description
This element has two mutually exclusive purposes with distinct content models: reference to a global element or local element definition.
For an element reference, attribute ref must contain its qualified name, including namespace prefix.
A local definition assigns a simple or complex type, either by reference through attribute type, naming the type by qualified name, or inline by embedding a simple-type definition, element xs:simpleType, or complex-type definition, element xs:complexType, within element xs:element.
Occurrence count can always be restricted with attributes minOccurs and maxOccurs, defaulting to 1. Attribute maxOccurs can take value unbounded , unlimited, allowing as many occurrences as the author wants.
Restrictions
Default and fixed values are specified in attributes and therefore apply only to simple-type elements.
W3C XML Schema cannot express mutually exclusive combinations of attributes and elements of xs:element, summarized as follows:
ref-Attribut xor name-Attribut, type-Attribut xor xs:simpleType-Element xor xs:complexType-Element
This illustrates some limitations of the language.
Example
<xs:sequence>
<xs:element name="book" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element ref="isbn"/>
<xs:element ref="title"/>
<xs:element ref="author" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="character" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute ref="id"/>
<xs:attribute ref="available"/>
</xs:complexType>
</xs:element>
</xs:sequence>Attributes
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.
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.
form
Specifies whether the element is qualified, in the target namespace, or unqualified, in no namespace; local definitions only.
id
Element ID according to W3C XML Schema.
maxOccurs
Maximum occurrence count; “unbounded” means unlimited.
minOccurs
Minimum occurrence count.
name
Local name without namespace prefix; local definitions only.
nillable
If set to true, the element can use attribute xsi:nil to be marked nil in instance documents.
ref
Reference to a global element; references only.
type
Reference to a simple or complex type; local definitions only.
Copyright © 2003 O'Reilly Verlag GmbH & Co. KG
You may print the online version for your private use.
Otherwise, this chapter from “XML Schema” is subject to the same conditions as the bound edition. The work, including all its parts, is protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
O’Reilly Verlag GmbH & Co. KG, Balthasarstraße 81, 50670 Köln, kommentar(at)oreilly.de