The <xs:element> allows you to define an element within the XML document. An element can either be defined globally i.e. as a child of the <xs:schema>, or locally within a compositor (<xs:all>, <xs:choice>, <xs:sequence>). A globally defined <xs:element> can be used as the root element within an XML document, and can also be re-used within the schema. Locally defined elements can only appear within there containing element.
There are a number of forms that an element can take.
- Data - The element has the type set to an existing simpleType (int, datetime, base64 etc). The resulting XML element then just contains data conforming to the rules given by the data type.
- Child Elements - The element contains a compositor (<xs:all>, <xs:choice>, <xs:sequence>), and this compositor contains definitions for other child elements.
- Simple Content - The element extends or restricts an existing type. This can either be a built in type or one defined using the <xs:simpleType> construct.
- Complex Content - The element extends or restricts an existing <xs:complexType>.
Depending on the form a given element takes, the properties applicable to it can be greatly changed.
This topic covers the 'Complex Content' form. Typically you can change the form that an element takes by changing the Type property.
In this form an element extends or restricts an existing <xs:complexType>, in this way the new element can be constructed reusing some common definition.
An <xs:element> that extends or restricts an existing <xs:complexType> can be created by selecting a compositor (<xs:all>, <xs:choice>, <xs:sequence>) or <schema> object. Then right clicking and selecting Add Child->Element, the type property can then be set to an existing ComplexType.
Name - The name the complex type will be referred to as. This must be unique, and its a good standard to postfix it with 'Type').
Type - The <xs:complexType> that this element will extend or restrict.
Abstract - Indicates that the element can not actually appear in the XML document. But can be used as a building block or substitution for other elements.
Block - Indicates that the element can not be substituted, extended or restricted - see 'Derived By' Property and Substitution Groups on <xs:element>.
Default - The default value given to the element. If the element is not specified then a parser should use this value in its place (Default and Fixed are mutually exclusive).
Final - .
Fixed - The value that the element has to take (Default and Fixed are mutually exclusive).
Id - A user defined ID to uniquely identify the entity within the schema.
Nillable - Indicates that the element in the XML document can be omitted (there are compatibility issues when using this flag and XML Data Binding, for this reason it is best avoided if possible).
The following XSD code
<xs:element name="Name" type="xs:string" />
<xs:element name="DeliveryAddress" type="cmn:AddressType" />
<xs:element name="BillingAddress" type="cmn:AddressType" />
<xs:element name="VipNumber" type="xs:int" />
Will be represented like this
Sample XML would look like this
<?xml version="1.0" encoding="utf-16"?>
Properties that apply to a type are shown inline at the bottom of the items container.
Values that are inherited from the base types are shown in brackets, values specifically set against the item are shown without brackets.
If a facet is not valid for a given type (typically because of its data type), then its value is shown in red.
|Inline properties can be disabled in the Options.|