XML schemas

XML schema is a an XML document that can validate the content and structure in other XML documents. The schemas is a modern trend in the XML development; they were introduced to compensate the limitations of the DTD. These DTD and schema approaches are not competing with each other, but really complement each other. It is not uncommon that a document has both DTD and schema.

Feature DTDs Schemas
Document language Extended Backus Naur Form (ENBF) XML
Standards one standardmultiple standards
Supported data types 10 44
Customized data types noyes
Mixed content difficult to developeasy to develop
Namespaces only namespace prefixes are supportedcompletely supported
Entities support yesno

XML shema is always placed in a separate file, usually with extension .xsd The root element in the XML schema file is always called schema. The general structure of the XML schema file is:

<schema xlmns="http://www.w3.org/2001/XMLSchema">
  schema content
</schema>

By convention, an xsd or xs prefix is applied to the schema namespace. Of course, the XML schema file has to have a standard xml tag. With these additions, the general template of an XML schema document is as follows:

<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xlmns:xs="http://www.w3.org/2001/XMLSchema">


</xs:schema>

The type of contents of the XML schema can be either simple or complex. A simple type contains a single value (an attribute or an element containing only text and no other elements). A complex type contain multiple values (several attributes in an empty element, element contents including plain text along with some child elements, a mixture of child elements and attributes, etc.).