Click Here

Monday 6 November 2017

XSD Explanation in layman language

What is XSD?

In Layman term:-
  • X             -              XML (XML Markup Language)
  • S              -              Schema (Structure or Organisation)
  • D             -              Definition

Definition of XSD:-

An XML schema, commonly known as an XML Schema Definition (XSD), formally describes what a given XML document can contain(like elements order, child elements order, constraints etc.).

Anology:-

Just like how database schema describes the data that can be contained in a database (i.e. table structure, data types, constraints etc.).
Also, Just like we use architectural blueprints that describe the structural design of a house, an XML Schema provides the "structural design" of a any XML document.

Features with example of XSD?
Basic XSD for Understanding Purpose

Features/Explanation of Above XSD:-

<?xml version = "1.0"?>
           XML Schema files normally begin with an XML declaration.
           It has no closing tag, like </?xml>
           The version in the XML declaration specifies the XML standard that the XML document conforms to.
           The version attribute must be included if the XML declaration is declared.
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
           The root element of any XSD is <schema> and it is always required element and it must have a closing tag </xs:schema>.
           The XSD namespace declaration is provided with <schema> element to tell the XML parser that it is an XSD Schema.
           Namespace specification is used to avoid the duplication of attribute and element names defined under XML, and this is normally be used in URL format.
           Here, we see the xsd is used as a namespace prefix, but we can use any prefix.
<xs:element name = 'WorkingEmpDetails'>
           Elements are the main building block of any XML document.
           This must have a closing tag </xs: element >.
           An element in XML Schema must have the name property.
           The name value holds the tag name of XML document.
           Here the element ‘WorkfinEmpDetails’ is of Complex Element*.
<xs:complexType>*
Elements that can have sub-elements and/or attributes are considered as a complex type element.
These complex type elements are defined using the <xs:complexType> tag.
<xs:sequence>
This is used, so that the child elements must appears in the order in which they are written.
<xs:element name = "ITEmployee" type = "xs:string"/>
This type of element display is of simple type.
An simple element contains only text.
Simple element cannot contain elements or attributes in its value.
The type in the simple element has built-in data types. Like xs:string, xs:integer, xs:date etc.