Съдържание

XML Schema element Element

Definition and Usage

The element element defines an element.

Element Information

Syntax

<element
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)*))
 
</element>

(The ? sign declares that the element can occur zero or one time, and the * sign declares that the element can occur zero or more times inside the element element)

Example 1

The following example is a schema with four simple elements named “fname”, “lname”, “age”, and “dateborn”, which are of type string, nonNegativeInteger, and date:

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
 
<xs:element name="fname" type="xs:string"/>
<xs:element name="lname" type="xs:string"/>
<xs:element name="age" type="xs:nonNegativeInteger"/>
<xs:element name="dateborn" type="xs:date"/>
 
</xs:schema>
<code>
 
===== Example 2 =====
 
The following example is a schema with an element named "note" that is of a complex type. The "note" element contains four other simple elements; "to", "from", "heading", and "body":
 
<code XML>
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
 
<xs:element name="note">
    <xs:complexType>
      <xs:sequence>
	<xs:element name="to" type="xs:string"/>
	<xs:element name="from" type="xs:string"/>
	<xs:element name="heading" type="xs:string"/>
	<xs:element name="body" type="xs:string"/>
      </xs:sequence>
    </xs:complexType>
</xs:element>
 
</xs:schema>

Example 3

This example is equal to Example 2, but here we have chosen to use the ref attribute to refer to the element names:

<code XML> <?xml version=“1.0”?> <xs:schema xmlns:xs=“http://www.w3.org/2001/XMLSchema”>

<xs:element name=“note”>

<xs:complexType>
  <xs:sequence>
    <xs:element ref="to"/>
    <xs:element ref="from"/>
    <xs:element ref="heading"/>
    <xs:element ref="body"/>
  </xs:sequence>
</xs:complexType>

</xs:element>

<xs:element name=“to” type=“xs:string”/> <xs:element name=“from” type=“xs:string”/> <xs:element name=“heading” type=“xs:string”/> <xs:element name=“body” type=“xs:string”/>

</xs:schema> <code>