"1.0" "UTF-8" "Qualified" "Employee": XML Xs:schema

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

XSD Example:

Consider Storing of employee details like eid,ename,esal.


eid should be in range of 10 to 100 and ename should have firstName and
lastName and firstName can be at max 12 characters.
esal should have basic and hra both should have fraction digits max : 2.
XSD:-
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org/employee"
xmlns:tns="http://www.example.org/employee"
elementFormDefault="qualified">

<xs:element name="employee">
<xs:complexType>
<xs:sequence>

<xs:element name="eid">
<xs:simpleType>
<xs:restriction base="xs:int">
<xs:minInclusive value="10" />
<xs:maxInclusive value="100" />
</xs:restriction>
</xs:simpleType>
</xs:element>

<xs:element name="ename">
<xs:complexType>
<xs:sequence>

<xs:element name="fName">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="12" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="lName" type="xs:string" />

</xs:sequence>
</xs:complexType>
</xs:element>

<xs:element name="esal">
<xs:complexType>
<xs:sequence>
<xs:element name="basic">
<xs:simpleType>
<xs:restriction base="xs:decimal">
<xs:fractionDigits value="2" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="hra">
<xs:simpleType>
<xs:restriction base="xs:decimal">
<xs:fractionDigits value="2" />
</xs:restriction>
</xs:simpleType>
</xs:element>

</xs:sequence>
</xs:complexType>
</xs:element>

</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Creating XSD using Eclipse :
Create a new Java Project -> right click on src-> new -> others-> XML Schema
(select this option). -> Next -> Enter File name-> Finish.

Ex 2:
Create XSD for storing book. book is root tag for xml and it must contains
bookId , bookName and bookCost. bookId range should be 10 to 500. And
author,version of book should be defined at last.
bookName should contains at max 15 characters. Author name must contain
firstName and last name. version should contain minor version and major
version.
Try This:

You might also like