Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
48 views5 pages

Child Elements or Any Attributes

XSD (XML Schema Definition) defines rules and structure for XML documents. It contains simple elements which have no child elements or attributes, and complex elements which can have child elements and/or attributes. Simple elements are defined with a name and data type, and restrictions can be placed on simple types like limiting integer values to a range or string lengths. Complex elements group simple elements in a defined sequence using complex types. Types can be declared internally or externally in XSD.

Uploaded by

Prabhakar Prabhu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views5 pages

Child Elements or Any Attributes

XSD (XML Schema Definition) defines rules and structure for XML documents. It contains simple elements which have no child elements or attributes, and complex elements which can have child elements and/or attributes. Simple elements are defined with a name and data type, and restrictions can be placed on simple types like limiting integer values to a range or string lengths. Complex elements group simple elements in a defined sequence using complex types. Types can be declared internally or externally in XSD.

Uploaded by

Prabhakar Prabhu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

XSD Introduction:-

XSD stands for XML Schema Design. It a file which provides


tags, attributes and their rules to construct an XML. In simple
words, XSD is a standard format for an XML.

XSD Contains two types of elements. They are

1) Simple Elements : These are the elements , which will never have any
child elements or any attributes.

2) Complex Elements: These are the elements which contains either


child or attribute , sometimes both.

Creating simple elements : A simple elements contains name and


data types. And we can even apply restrictions over the simple type.

Syntax to create a simple element:

<xs:element name="" type=""/>

or

<xs:element name="" type=""></xs:element>

Hear name indicates element name and type indicates element


data type.

ex: create an XML element empId as int type using XSD.

XSD:

<xs:element name="empId" type="xs:int"/>

We can use some other data types like

xs:int, xs:integer, xs:string,xs:decimal,xs:double etc..

Some other examples:

<xs:element name="empname" type="string"/>

<xs:element name="empsal" type="xs:decmal"/>


=========

Restrictions over Simple types:

empId element created as int type , it allows negative numbers and


positive numbers. But If i want to allow employee Id's from 100 to
300 then specify restrictions on input type.

Restrictions are given as:

1) Numeric/Integer restrictions :

minInclusive ,maxInclusive,minExclusive,maxExclusive.

Ex: crate an element voterAge that should accept only minimun 18


and Max 100 only.

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

or

<xs:element name="voterAge">
<xs:simpleType>
<xs:restriction base="xs:int">
<xs:minExclusive value="17"/>
<xs:maxExclusive value="101"/>
</xs:restriction>
</xs:simpleType>
</xs:element>

2) String length Restrictions:-

minLength,maxLength,length(exact length).

ex: create an element empName , that should accept minimum 5


characters and max 20 characters
ex:

<xs:element name="empName">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="5"/>
<xs:maxLength value="20"/>
</xs:restriction>
</xs:simpleType>
</xs:element>

ex: create an element empName , that should accept exact 10


characters

<xs:element name="empName">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:length value="20"/>
</xs:restriction>
</xs:simpleType>
</xs:element>

3) Decimal restrictions :

totalDigits,fractionDigits.

ex: Create a decimal number element that should accept at max 12


numbers and in that after decimal at max 3 numbers.

========

2) Complex Type elements:

ex: Design an complex type element that should accept two simple
elements

with given order

<employee>

<empId>101</empId>

<empName>ABCD</empName>

</employee>

XSD Code:
<xs:element name="employee">
<xs:complexType>
<xs:sequence>
<xs:element name="empId" type="xs:int"/>
<xs:element name="empName" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>

External declaration : We can declare the complex/simple type externally and


can be referred as data types. They are known as targetNamespace(tns) data
types.

ex:

<xs:complexType name="emptypeOne">
<xs:sequence>
<xs:element name="empId" type="xs:int" />
<xs:element name="empName" type="xs:string" />
</xs:sequence>
</xs:complexType>
<xs:element name="employee" type="tns:emptypeOne" />

==================

Simple Type :Internal Declaration:

<xs:element name="empSal">
<xs:simpleType>
<xs:restriction base="xs:decimal">
<xs:totalDigits value="25" />
<xs:fractionDigits value="3" />
</xs:restriction>
</xs:simpleType>
</xs:element>
External Declaration :

<xs:simpleType name="empSaltype">
<xs:restriction base="xs:decimal">
<xs:totalDigits value="25"/>
<xs:fractionDigits value="3"/>
</xs:restriction>
</xs:simpleType>
<xs:element name="empSal" type="tns:empSaltype"/>

You might also like