Datatypes are one of the big addition to XML Schema language over the DTD. Some of them are:
- A document can be validated by deciding which particular type of data can be used in a particular marked text.
- They defines the data restrictions.
- Datatypes will help the data to convert between different data types.
XSD language separates the datatypes into two types. They are:
- Simple Datatype
- Complex Datatype
Simple datatype element is used only in the text context. Numbers, Strings, Dates, etc are few pre-defined simple datatypes. For Example,
[xml]
<xs:element name="phone_number" type="xs:int" />
[/xml]
Complex Data is a mixed element, sequences element that have to be in a particular sequence for the particular number of things happening. Complex datatypes are built upon simple datatypes.
In the below example,
Address
is the root element and all the elements like name, company and phone are set to
String
type and also the file did followed a sequence which is nothing but a schema of complex datatype.
[xml]
<xs:element name="Address">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string" />
<xs:element name="company" type="xs:string" />
<xs:element name="phone" type="xs:int" />
</xs:sequence>
</xs:complexType>
</xs:element>
[/xml]