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
Summary
Today you practiced validating XML documents with DTDs and specified the syntax of XML documents for XML processors to check. In a perfect world, there would be no data-entry errors in XML documents, but real life is a different story. If you specify the syntax of an XML document, you can let an XML processor check that document automatically.
There are two ways to specify the syntax of XML documents—by using DTDs and XML schemas, both of which have syntaxes of their own. You saw today that you use the <!DOCTYPE> element to enclose a DTD and that DTD can either be internal to the XML document (in which case you set the XML declaration's standalone attribute to "yes"), external to the XML document (in which case you provide the DTD's URI and set the XML declaration's standalone attribute to "no"), or a combination of the two. You saw that XML validators can work with either type of DTD.
Today's discussion focuses on writing DTDs and using <!ELEMENT> to declare XML elements. You can use <!ELEMENT>, to use the following syntax for elements: <!ELEMENT name content_model >. Today you saw that there are various content models possible. You can use the content model ANY to allow any content and to turn off syntax checking, or use EMPTY to declare an empty element. You can list possible child elements by using <!ELEMENT document (employee)>, which allows a <document> element to contain an <employee> element.
You can also list the child elements an element can contain, in order, like this: <!ELEMENT employee (name, hiredate, projects)>. Such a list is called a sequence. You can also specify that an element contains text content—parsed character data—by using the term #PCDATA.
You saw today that you can use the symbols + (one or more), * (zero or more), ? (one or none), and | (choices) in DTDs so that you can work with multiple child elements. You can also use these symbols in sequences to specify exactly what child elements or combinations of child elements an element can contain.
Finally, you took a look at working with namespaces in DTDs. Because using a namespace changes the names of elements and attributes, you have to take the new names into account when we're writing a DTD with namespaces. You even have to declare the xmlns attribute that creates the namespace in the first place—and that's a topic we'll hear more about tomorrow.

Account Sign In
View your cart