Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

XSD (XML Schema Definition) overview:

XSD is the main documents to be defined before you are starting any BPEL, ESB or
Webservice.
Here I would like to cover brief overview on XML Schema Definition (XSD):
XSD defines a template for what XML document contains.

XML schema is language and it is referred as XML schema Definition.


XSD defines Data types, Elements, Attributes.
One XSD can be import multiple XSDs
One WSDL can import multiple xsds, can be differentiated with namespaces.
But XSDs cant import WSDL

XML schema can contain:


Declaration: XML version and encoding like UTF8Etc
Definitions: namespaces, prefixes, name of the schema
Types: simple, complex types
Elements: element names in xsd
Attributes: attributes for defines elements.
Elements:
Elements are main building blocks of any xml documents. Elements are defined like
following in XML schema:
<xs:element name=nameof element type=type of element/>
For example:
<xs:element name=employeeID type=integer/>
<xs:element name=employeeName type=string/>
<xs:element name=salary type=decimal/>
Elements are either simple type or complex type. Simple type elements are defined with
default available types, string, integer, double, Boolean, date, time.
For example if your xml is on following format:
< employeeID >100</ employeeID >

< employeeName >John</ employeeName >


< salary >200.00</ salary >
Then corresponding elements definition in XSD is like following:
<xs:element name=employeeID type=integer/>
<xs:element name=employeeName type=string/>
<xs:element name=salary type=decimal/>
Complex Types:
Complex types are custom defined types. For instance if you want to define custom type
called employee, you can define like following:
<xs:element name=employee>
<xs:complextype>
<xs:element name=employeeID type=integer/>
<xs:element name=employeeName type=string/>
<xs:element name=salary type=decimal/>
</xs:complextype>
</ xs:element>
Or
Define first structure of complextype:
<xs:complextype name=employeeStruct>
<xs:element name=employeeID type=integer/>
<xs:element name=employeeName type=string/>
<xs:element name=salary type=decimal/>
</xs:complextype>
And then define the actual element:
<xs:element name=employee type=employeeStruct>
Restrictions on data:
You can put restriction on data using <xs:restriction> tag on simple types.

For example if you want to put restriction on class element which accepts data between
1 to 12, define like following:
<xs:simpletype name=classtype>
<xs:restriction base=xs:integer>
<xs:minInclusive value=1/>
<xs:maxInclusive value=12/>
</xs:restriction>
</xs:simpletype>
If you want limit the content of xml element to set of acceptable values use
<xs:enumaration> tag.
More on XSD Restrictions/Facets can be found on following link :
http://www.w3schools.com/schema/schema_facets.asp
Finally example xml schema definition file:
<! Declaration>
<?xml version=1.0 encoding=UTF-8?>
<! Definations>
<xs:schema xmlns:xs=http://www.w3.org/2001/XMLSchema&#8221;
targetNameSpace=http://www.rayalasoft.com/employee.xsd&#8221;
xmlns:tns=http://www.rayalasoft.com/employee.xsd&gt;
<! Imports if you have any imports
<xs:include schemaLocation=anotherschemaname.xsd>
>
<! Elements declaration >
<xs:element type=tns:employeeStruct/>
<! Types declaration >
<xs:complexType name=employeeStruct>
<xs:sequence>
<xs:element name=employeeID type=integer/>

<xs:element name=employeeName type=string/>


<xs:element name=salary type=decimal/>
</xs:sequence>
</xs:complexType>
</xs:schema

You might also like