Like DTDs, XML schema are a way to define the elements of an XML document. Unlike DTDs, however, XML schema use XML syntax to construct the definition.

As of this writeup, schemas are at the W3C Working Draft stage and are not widely implemented. However, it is expected that they will replace DTDs in the future.

The W3C formal specification (work in progress) lives here:

A language for describing the structure, content, and (to a degree) semantics of XML documents. While XML has a built-in means of doing this (DTDs), XML Schema is far more powerful.

XML Schemas are themselves written in XML, rather than using a special syntax like DTDs. (In fact, there is a schema for XML Schema that is written in XML Schema.)

Highlights of XML Schema include:

  • Support for XML Namespaces.
  • Elements which exist only in the scope of their parent element. This means that one can have two or more different elements with the same name, and exactly which element is being referred to depends on what its parent element is.
  • More specific restrictions on the textual content of elements. For instance, an element might be required to contain a number and nothing else. Such restrictions can be specified in various ways, including regular expressions that the content must match.
  • Annotations and documentation. Such annotations can be attached to elements, attributes, and so forth. This can be used by authors to understand what the document being described is for, what its semantics are, what each element means, and so on. This can be used by XML editors to both construct a skeletal instance document (which the author then fills in), as well as display these descriptions, perhaps in a schema browser or a popup window in the editor proper.

One important feature of DTDs that XML Schema does not replace is entity declarations. Even if the XML parser is validating against an XML Schema, it will still use entity declarations provided in a DTD and/or internal subset (though it will obviously ignore element declarations there). This way, authors do not lose the very useful ability to write their own entities as a result of using XML Schema instead of a DTD.

Log in or register to write something here or to contact authors.