Chapter 5. Creating XML Schemas

For the past two chapters, we've been working with document type definitions (DTDs). Over time, many people have complained to the World Wide Web Consortium (W3C) about the complexity of DTDs and have asked for something simpler. The W3C listened, assigned a committee to work on the problem, and came up with a solution that is much more complex than DTDs ever were: XML schemas.

On the other hand, schemas are also far more powerful and precise than DTDs ever were. With schemas, you can specify not only the syntax of a document as you would with a DTD, but also the actual data types of each element's content, inherit syntax from other schemas, annotate schemas, use them with multiple namespaces, create simple and complex data types, specify the minimum and maximum number of times an element can occur, create list types, create attribute groups, restrict the ranges of values that elements can hold, restrict what other schemas can inherit from yours, merge fragments of multiple schemas, require that attribute or element values be unique, and much more.

Currently, the specification for XML schemas is in the working draft stage, which means it will probably change before becoming a recommendation. You can find the specification in these three documents:

  • http://www.w3.org/TR/xmlschema-0/ XML schema primer, a tutorial introduction to schemas

  • http://www.w3.org/TR/xmlschema-1/ XML schema structures, the formal details on creating schemas

  • http://www.w3.org/TR/xmlschema-2/ XML schema data types, all about the data types you can use in schemas

There were a few issues that the schema working group expressly set out to tackle: using namespaces when validating documents, providing for data typing and restrictions, allowing and restricting inheritance between schemas, creating primitive data types, and other issues.

As with most issues in this book, this is all best seen with an example. One of the major applications that does support schemas is Internet Explorer, so let's take a look at that first.



Real World XML
Real World XML (2nd Edition)
ISBN: 0735712867
EAN: 2147483647
Year: 2005
Pages: 440
Authors: Steve Holzner

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net