XML Schema element
Element
Definition and Usage
The element
element defines an element.
Element Information
- Parent elements: schema, choice, all, sequence, group
Syntax
(? symbol declares that the element can appear zero or one time in the element
element, * symbol declares that the element can appear zero or more times.)
Attribute | Description |
---|---|
id | Optional. Specifies a unique ID for the element. |
name | Optional. Specifies the name of the element. This attribute is required if the parent element is a schema element. |
ref | Optional. A reference to another element. The ref attribute can include a namespace prefix. This attribute is not used if the parent element is a schema element. |
type | Optional. Specifies the name of a built-in data type, or the name of a simpleType or complexType element. |
substitutionGroup | Optional. Specifies the name of an element that can be used to replace this element. The element must have the same type or a type derived from the specified element type. This attribute cannot be used if the parent element is not a schema element. |
default | Optional. Specifies a default value for the element (only used if the element content is a simple type or textOnly). |
fixed | Optional. Specifies a fixed value for the element (only used if the element content is a simple type or textOnly). |
form | Optional. The form of the element. The default value is the value of the elementFormDefault attribute of the schema element that contains this attribute. The value must be one of the following strings: "qualified" or "unqualified". This attribute cannot be used if the parent element is a schema element. If the value is "unqualified", the element does not need to be qualified by a namespace prefix. If the value is "qualified", the element must be qualified by a namespace prefix. |
maxOccurs | Optional. Specifies the maximum number of times the element element can appear in the parent element. The value can be an integer greater than or equal to zero. To set no limit on the maximum number, use the string "unbounded". The default value is 1. This attribute cannot be used if the parent element is a schema element. |
minOccurs | Optional. Specifies the minimum number of times the element element can appear in the parent element. The value can be an integer greater than or equal to zero. The default value is 1. This attribute cannot be used if the parent element is a schema element. |
nillable | Optional. Indicates whether an explicit nil value can be assigned to the element. This applies to the element content and not the element's attributes. The default value is false. If nillable is true, it allows the element's instances to set the nil attribute to true. The nil attribute is defined as part of the XML Schema namespace for instances. |
abstract | Optional. Indicates whether the element can be used in instance documents. If the value is true, the element cannot appear in instance documents. Instead, other elements that contain this element's qualified name (QName) in their substitutionGroup attribute must appear in its place. Multiple elements can reference this element in their substitutionGroup attribute. The default value is false. |
block | Optional. Derived types. The block attribute prevents elements with the specified derivation type from being used to substitute this element. The value can contain #all or a subset list of extension, restriction, or substitution: extension - Prevents elements derived by extension from being used to substitute this element. restriction - Prevents elements derived by restriction from being used to substitute this element. substitution - Prevents elements derived by substitution from being used to substitute this element. #all - Prevents all derived elements from being used to substitute this element. |
final | Optional. Sets the default value for the final attribute on the element element. This attribute cannot be used if the parent element is not a schema element. The value can contain #all or a subset list of extension or restriction: extension - Prevents elements derived by extension from being used to substitute this element. restriction - Prevents elements derived by restriction from being used to substitute this element. #all - Prevents all derived elements from being used to substitute this element. |
any attributes | Optional. Specifies any other attributes with non-schema namespaces. |
Example 1
The following example is a schema with four simple elements: "fname", "lname", "age", and "dateborn", with types string, nonNegativeInteger, and date:
Example 2
The following example is a schema with a complex type "note" element. The "note" element contains four simple elements: "to", "from", "heading", and "body":
Example 3
This example is the same as Example 2, but in this case, we choose to use the ref attribute to reference the element names: