XML-Schema An XML schema, commonly known as an XML Schema Definition (XSD), formally describes what a given XML document can contain. The XML schema defines the shape, or structure, of an XML document, along with rules for data content and semantics such as what fields an element can contain, which sub elements it can contain and how many items can be present.
XML Elements Elements are the main building block of all XML documents, containing the data and determine the structure of the instance document. An element can be defined within an XSD as follows: <xs:element name="x" type="y" /> XSD must have a 'name' property, which is the tag name that will appear in the XML document. The 'type' property provides the description of what type of data can be contained within the element when it appears in the XML document. There are a number of predefined simple types, such as xs:string, xs:integer, xs:boolean and xs:date
Specifying Element Cardinality It is possible to constrain the number of instances (cardinality) of an XML element that appear in an XML document. The cardinality is specified using the minOccurs and maxOccurs attributes, and allows an element to be specified as mandatory, optional, or can appear up to a set number of times. The default values for minOccurs and maxOccurs is 1. Therefore, if both the minOccurs and maxOccurs attributes are absent, as in all the previous examples, the element must appear once and once only.
Defining Compositors Compositors provide rules that determine how and in what order there children can appear within XML document. There are three types of compositors <xs:sequence>, <xs:choice> and <xs:all>.
Defining XML Attributes An attribute provides extra information within an element. Attributes have name and type properties and are defined within an XSD as follows: <xs:attribute name="x" type="y" /> <xs:attribute name="ID" type="xs:string" /> <xs:attribute name="ID" type="xs:string" use="optional" />