XSD (XML Schema Definition) :

XSD stands for XML Schema Definition. It specifies how to formally describe the elements in an XML document. This description can be used to verify that each item of content in a document adheres to the description of the element in which the content is to be placed.

Data Model

With XML Schemas you specify how your XML data will be organized, and the data types of your data. That is, with XML Schemas you model how your data is to be represented in an instance document.

A Contract

Organizations agree to structure their XML documents in conformance with an XML Schema. Thus, the XML Schema acts as a contract between the organizations.

A rich source of metadata

An XML Schema document contains lots of data about the data in the XML instance documents, such as the data type of the data, the data’s range of values, how the data is related to another piece of data (parent/child, sibling relationship), i.e., XML Schemas contain metadata

Example for XSD:

<?xml version="1.0"?>

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"

targetNamespace="http://www.books.org"

xmlns="http://www.books.org"

elementFormDefault="qualified">

<xsd:element name="BookStore">

<xsd:complexType>

<xsd:sequence>

<xsd:element ref="Book" minOccurs="1" maxOccurs="unbounded"/>

</xsd:sequence>

</xsd:complexType>

</xsd:element>

<xsd:element name="Book">

<xsd:complexType>

<xsd:sequence>

<xsd:element ref="Title" minOccurs="1" maxOccurs="1"/>

<xsd:element ref="Author" minOccurs="1" maxOccurs="1"/>

<xsd:element ref="Date" minOccurs="1" maxOccurs="1"/>

<xsd:element ref="ISBN" minOccurs="1" maxOccurs="1"/>

<xsd:element ref="Publisher" minOccurs="1" maxOccurs="1"/>

</xsd:sequence>

</xsd:complexType>

</xsd:element>

<xsd:element name="Title" type="xsd:string"/>

<xsd:element name="Author" type="xsd:string"/>

<xsd:element name="Date" type="xsd:string"/>

<xsd:element name="ISBN" type="xsd:string"/>

<xsd:element name="Publisher" type="xsd:string"/>

</xsd:schema>

DTD (Document Type Definition):

  • The DTD specifies the logical structure of the document; it is a formal grammar describing document syntax and semantics
  • The DTD does not describe the physical layout of the document; this is left to the style sheets and the scripts
  • It is no mean task to write a DTD, so most users will adopt predefined DTDs
  • DTDs can be written in separate files to facilitate re-use.
  • Content-providers, industries and other groups can collaborate to define sets of tags.
  • Comprises a set of declarations that define a document structure tree
  • Declarations stored either at the top of each document that must conform to the rules, or alternatively, and more usually, in separate data files, referred by a special instruction at the top of each document.
  • Each DTD element must either be a container element, or be empty (a place holder). Container elements may contain text, child elements, or a mixture of both.
  • DTD also specifies the names of attributes, and dictates which elements they may appear in. For each attribute it specifies whether it is optional or required.
  • DTD tree describing a book as containing a number of Chapter elements, with each chapter containing either a number of Paragraph elements, or a single Sections element
  • A particular document tree has a node for each actual chapter and paragraph present, and may omit some of the optional elements

Related Posts

  1. XML and WebServices Basics – Part 1
  2. XML and WebServices Basics – Part 3 | XML Parsing
  3. XML and WebServices Basics – Part 4 | Webservices SOAP and WSDL
  4. Free Microsoft Press book offer
  5. Oracle PL/SQL: Sequences (Autonumber)

Tags: , , , , , ,

Leave a Reply

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>