Use of XML Schema in XML

In this article I am going to explain about XML Schema.
  • 2257

XML Schema

An XML schema show the structure of XML Document. XML Schema is an XML based alternative to DTD. XML schema is also referred to XML schema definition. An XML schema is more powerful than Document type Definition (DTD).

The purpose of XML schema is:-

  • defines how many element appear in XML document.
  • defines how many attribute appear in XML document.
  • defines no of child element in XML document.
  • defines the number of child elements
  • defines the which element is child element.
  • defines whether an element is empty or can include text
  • defines data types of elements and attributes
  • defines default and fixed values for elements and attributes


An XML Document

<?xml version="1.0" encoding="ISO-8859-1"?>

<Demo orderid="889923"
    <city>4000 Delhi</city>
    <title>Employee detail</title>
    <company>MCN solution</company>


Schema of above XML Document.

<?xml version="1.0" encoding="ISO-8859-1" ?>
<xs:schema xmlns:xs="">
<xs:element name="Demo">
      <xs:element name="orderperson" type="xs:string"/>
      <xs:element name="detail">
            <xs:element name="name" type="xs:string"/>
            <xs:element name="address" type="xs:string"/>
            <xs:element name="city" type="xs:string"/>
            <xs:element name="country" type="xs:string"/>
      <xs:element name="item" maxOccurs="unbounded">
            <xs:element name="title" type="xs:string"/>
            <xs:element name="company" type="xs:string" minOccurs="0"/>
            <xs:element name="salary" type="xs:decimal"/>
    <xs:attribute name="orderid" type="xs:string" use="required"/>


Further Readings

You may also want to read these related articles: here

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

© 2020 DotNetHeaven. All rights reserved.