In this tutorial you will learn how to read and create XML Schemas, why XML Schemas are more powerful than DTDs, and how to use them in your application.
XML Schema is a W3C Standard. It is an XML-based alternative to DTDs. It describes the structure of an XML document. The XML Schema language is also referred to as XML Schema Definition (XSD).
We think that very soon XML Schemas will be used in most Web applications as a replacement for DTDs. Here are some reasons:
What is an XML Schema?
XML Schema is used to define the legal building blocks of an XML document, just like a DTD.
An XML Schema defines user-defined integrants like elements, sub-elements and attributes needed in a xml document. It defines the data types for elements and attributes along with the occurrence order . It defines whether an element is empty or can include text. It also defines default and fixed values for elements and attributes
Why Use XML Schemas?
XML Schemas are much more powerful than DTDs.
Features of XML Schemas :
XML Schemas Support Data Types
One of the greatest strengths of XML Schemas is its support for data types. With support for data types:
XML Schemas use XML Syntax
Another great strength about XML Schemas is that they are written in XML. Simple XML editors are used to edit the Schema files. Even the same XML parsers can be used to parse the Schema files.
XML Schemas are Extensible
XML Schemas are extensible, because they are written in XML.So a user can reuse a Schema in other Schemas and can also refer multiple schemas in the same document. He can also create his own data types derived from the standard types
Well-Formed is not Enough alone
A well-formed XML document is a document that conforms to the XML syntax rules.Even if documents are well-formed they can still contain errors, and those errors can have serious consequences.
Think of the following situation: you order 5 gross of laser printers, instead of 5 laser printers. With XML Schemas, most of these errors can be caught by your validating software.
XML Schemas Secure Reliable Data Communication
When sending data from a sender to a receiver, it is essential that both parts have the same "expectations" about the content. With XML Schemas, the sender can describe the data in a way that the receiver will understand. A date like: "03-11-2004" will, in some countries, be interpreted as 3.November and in other countries as 11.March.However, an XML element with a data type like this: <datetype="date">2004-03-11</date> ensures a mutual understanding of the content, because the XML data type "date" requires the format "YYYY-MM-DD".