Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

XML Schema element Element

XML Schema element Element


XML Schema Reference Manual Complete XML Schema Reference Manual


Definition and Usage

The element element defines an element.

Element Information

Syntax

id=ID

name=NCName

ref=QName

type=QName

substitutionGroup=QName

default=string

fixed=string

form=qualified|unqualified

maxOccurs=nonNegativeInteger|unbounded

minOccurs=nonNegativeInteger

nillable=true|false

abstract=true|false

block=(#all|list of (extension|restriction))

final=(#all|list of (extension|restriction))

any attributes

annotation?,(simpleType|complexType)?,(unique|key|keyref)*

(The ? symbol declares that the element can occur zero or one time in the element element, and the * symbol declares that the element can occur zero or more times.)

Optional. Indicates whether an explicit zero value can be assigned to the element. This applies to the element content and is not an attribute of the element. The default value is false.

If nillable is true, it enables instances of the element to set the nil attribute to true. The nil attribute is defined as part of the XML Schema namespace of the instance.

property 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 the schema element.
ref Optional. A reference to another element. The ref attribute can contain a namespace prefix. This attribute is not used if the parent element is the 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 substitute for this element. The element must have the same type as, or a type derived from, the specified element type. This attribute cannot be used if the parent element is not the schema element.
default Optional. Specifies a default value for the element (used only when the element content is a simple type or textOnly).
fixed Optional. Specifies a fixed value for the element (used only when 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 the 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 can occur in the parent element. The value can be an integer greater than or equal to zero. If you do not want to set any limit on the maximum number, use the string "unbounded". The default value is 1.

    This attribute cannot be used if the parent element is the schema element.

    | | minOccurs |

    Optional. Specifies the minimum number of times the element can occur 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 the schema element.

    | | nillable | | abstract |

    Optional. Indicates whether the element can be used in an instance document. If the value is true, the element cannot appear in the instance document. Instead, other elements whose substitutionGroup attribute contains the qualified name (QName) of this element must appear in its place. Multiple elements can reference this element in their substitutionGroup attribute. The default value is false.

    | | block |

    Optional. The derived type. The block attribute prevents elements with the specified derived type from being used to substitute for this element. The value can contain #all or a list that is a subset of extension, restriction, or substitution:

    | | final |

    Optional. Sets the default value of the final attribute on the element element. This attribute cannot be used if the parent element is not the schema element. The value can contain #all or a list that is a subset of extension or restriction:

    | | *any attributes* |

    Optional. Specifies any other attributes with a non-schema namespace.

    |

    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":

      xs:complexType

        xs:sequence

          

          

          

          

        

      

    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:

      xs:complexType

        xs:sequence

        

        

        

        

        

      


    XML Schema Reference Manual Complete XML Schema Reference Manual