XML Schemas

XML > XML Schemas

An XML schema is a description of the data that can be contained within a given XML document. It defines the names and types of the elements and attributes within an XML document and the hierarchy that these elements form.

Some of the benefits of an XML Schema

Over the years several different methods for describing XML data have been developed.

Document Type Definition (DTD)

The DTD standard forms part of the XML 1.0 spec and is the original method of specifying the structure of XML data. Its basic, but easy to processes it is still in the XML 1.1 spec, but has largely been dropped in favor of XSD's.

See Document Type Definition for a full description.

XML Schema Definition 1.0 (XSD)

The DTD specification within in the XML 1.0 spec was deemed to limiting so the XSD spec was developed to address its limitation. In 2001 the W3C XSD 1.0 was released (it had a few issues and was updated in 2004). XSD's had many improvements over DTD's including its own extensible type system, a number of features making it easier to modularize large schemas and improve reuse. But all these features and functionality came at a price, the XSD standard is very complex and writing it by hand is no longer a practical option, so an XSD Editor is now required. 

Despite its complexity the XSD standard has been embraced across the industry with 1000's of standards now being published using it, a host of parsers, validators and tools are also available for all the main languages and platforms.

XML Schema Definition 1.1 (XSD)

The XSD 1.1 standard is (practically) backwardly compatible with the XSD 1.0 standard. It introduces a few concepts like asserts (similar to schematron) and allows more flexibility in the construction of the schemas. On significant addition is the abbility to make an element defintion open (using xs:openContent), meaning it will allow other content to be placed in it that has not yet been defined (similar to xs:any, but much more powerful).

The only downside is support. Currently there are not many XSD 1.1 validating parsers (Xerces being the main one).

Schematron

Schematron was released in 2006 and is typically used as an adjunct to an XSD or DTD. It allows rules to be specified as a set of assertions, which makes it possible to incorporate more complex business logic into a schema, particularly where rules are dependant on data from distant parts of the XML document.

However the assertion style make it less suitable for specifying the structure of an XML document, and makes the creation of graphical editors which deal with this structure impractical.

RelaxNG

RelaxNG is another schema specification. It provides much of the functionality of the XSD standard and is much simpler. A number of parsers and validators exist for it, but at the end of the day its not a W3C standard, and as such has not been embraced by the industry, accordingly tools for authoring it are minimal. Its arguably better than the XSD standard, but if you look at the XML Schema standards being created the overwhelming majority are using XSD.

See Also

Try Liquid XML Free and see how we can help you today Free Trial