How to use Schema in XML

This article tell you how to define XML Schema in XML
  • 2181

How to use XML Schema

You may already learn about DTDs. DTDs are and XML Schema both are similar to each. In that they are used to create classes of XML documents. The work of DTDs and Xml Schema to define the structure of XML document. But DTDs is the previous it has the some flow. Although DTDs are still common, XML Schema is a much more powerful language.

 Means of understanding the power of XML Schema first see the limitation of DTDs

  • DTDs have not built-in data types.

  • It is also not support user-derived data type

  • In DTDs does not support multiple declarations in parenthesis.

To overcome these flow use XML Schema

First create simple XML document

<?xml version="1.0"?>
  <heading>Remember me</heading>
  <body>Don't forget me this year</body>

Note: This is a simple XML document

Simple DTDs declaration 

<!ELEMENT note (to, from, heading, body)>
<!ELEMENT heading (#PCDATA)>

Note: This is a simple DTDs declaration

XML Schema file


<?xml version="1.0" encoding="utf-8"?>
<xs:schema elementFormDefault="qualified" xmlns:xs="">
  <xs:element name="note">
        <xs:element ref="to" />
        <xs:element ref="from" />
        <xs:element ref="heading" />
        <xs:element ref="body" />
  <xs:element name="to" type="xs:string" />
  <xs:element name="from" type="xs:string" />
  <xs:element name="heading" type="xs:string" />
  <xs:element name="body" type="xs:string" />

Note: This is the Example of XML Schema

A Reference to a DTD

<?xml version="1.0"?>
"D:\satya prakash\dtd note.txt">
  <heading>Remember me</heading>
  <body>Don't forget me this  year</body>

Note: This is reference type of DTD means we make DTD in system directory and used it in the XML document.

Further Readings

You may also want to read these related articles :

Ask Your Question 

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

Programming Answers here

© 2020 DotNetHeaven. All rights reserved.