Sams Teach Yourself XML in 21 Days
- Table of Contents
- About the Author
- Acknowledgments
- We Want to Hear from You!
- Introduction
- Part I: At a Glance
- Day 1. Welcome to XML
- Day 2. Creating XML Documents
- Day 3. Creating Well-Formed XML Documents
- Day 4. Creating Valid XML Documents: DTDs
- Declaring Attributes in DTDs
- Day 6. Creating Valid XML Documents: XML Schemas
- Day 7. Creating Types in XML Schemas
- Part I. In Review
- Day 8. Formatting XML by Using Cascading Style Sheets
- Day 9. Formatting XML by Using XSLT
- Day 10. Working with XSL Formatting Objects
- Part II. In Review
- Part III: At a Glance
- Day 11. Extending HTML with XHTML
- Day 12. Putting XHTML to Work
- Day 13. Creating Graphics and Multimedia: SVG and SMIL
- Day 14. Handling XLinks, XPointers, and XForms
- Part III. In Review
- Part IV: At a Glance
- Day 15. Using JavaScript and XML
- Day 16. Using Java and .NET: DOM
- Day 17. Using Java and .NET: SAX
- Day 18. Working with SOAP and RDF
- Part IV. In Review
- Part V: At a Glance
- Day 19. Handling XML Data Binding
- Day 20. Working with XML and Databases
- Day 21. Handling XML in .NET
- Part V. In Review
- Appendix A. Quiz Answers
Day 6. Creating Valid XML Documents: XML Schemas
Yesterday and on Day 4, "Creating Valid XML Documents: DTDs," you took a look at working with DTDs to validate XML documents. Today and tomorrow you'll get a look at the other way of validating XML documents: using XML schemas. XML schemas allow you considerably more precision than DTDs do, as you're about to see. Here's an overview of today's topics:
- Validating XML documents by using XML schemas
- Creating XML schemas
- Using XML schema-generating tools
- Declaring elements
- Declaring simple and complex types
- Creating sequences of elements
- Setting the number of times elements may occur
- Giving elements default values
- Specifying attributes
- Specifying default values for attributes
As of this writing, this quote is available on the W3C XML Activity Page (http://www.w3.org/XML/Activity.html):
- While XML 1.0 supplies a mechanism, the document type definition (DTD) for declaring constraints on the use of markup, automated processing of XML documents, requires more rigorous and comprehensive facilities in this area.
For the past two days, you've been working with DTDs, but DTDs are actually pretty basic. As XML developed, XML authors asked the W3C for a more comprehensive and detailed way of specifying the syntax of XML documents, and the W3C responded with XML schemas. The W3C XML schema working group was originally created to tackle a number of issues that DTDs didn't handle well—handling namespaces when validating documents, allowing data typing, allowing and restricting inheritance for validation methods, creating our own data types, and other issues. As you're going to see, XML schemas let you spell out the syntax of XML documents far more precisely than DTDs ever could. Originally, there was very little software that could handle XML schemas, but today you'll find more and more XML schema-aware software available.
XML schemas are a W3C recommendation, and that recommendation is available in these three documents:
- http://www.w3.org/TR/xmlschema-0— This XML schema primer is a tutorial introduction to schemas.
- http://www.w3.org/TR/xmlschema-1— This document covers XML schema structures, including the formal details on creating schemas.
- http://www.w3.org/TR/xmlschema-2— This document discusses the data types you can use in schemas.
Right now, the XML schema recommendation is in version 1.0, but the W3C is starting to think about version 1.1. Nothing's been firmed up at this point, however. Here's what W3C says about version 1.1:
- The XML Schema WG is currently working to develop a set of requirements for XML Schema 1.1, which is intended to be mostly compatible with XML Schema 1.0 and to have approximately the same scope, but also to fix bugs and make whatever improvements you can, consistent with the constraints on scope and compatibility.
Using XML Schema Tools | Next Section

Account Sign In
View your cart