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's discussion describes how to use attributes and entities with DTDs. You saw that you declare attributes in a DTD by using an <!ATTLIST> element.
You can assign various default values to attributes when you declare them. You can assign an explicit default value—#IMPLIED to make the attribute optional, #FIXED to give it a fixed value, and #REQUIRED to make an attribute required —enclosed in quotation marks,.
You can also declare the type of an attribute in an <!ATTLIST> element. The various attribute types are CDATA, which means character data; ENTITY, which means you can assign an entity name to an attribute; ENTITIES, which you can use to assign a list of entity names to an attribute; an enumeration, which specifies a list of possible values for an attribute; an ID value; an IDREF value, which holds the ID of another element; IDREFS, which holds multiple ID values; NMTOKEN, which can hold text made up of XML name characters; NMTOKENS, which can hold multiple NMTOKEN items; and NOTATION, which holds the name of a notation (that is, a format description).
In this discussion you also saw how to work with entities. You saw that you can declare entities by using the <!ENTITY> element. And you saw that entity is XML's term for a data item, and when you declare entities in a DTD, you can refer to them in the rest of the XML document.
In general, entity references in an XML document will be replaced by the entity they stand for when the entity is text. However, you can also create unparsed entities that will not be parsed by the XML processor; for example, external image files in binary format are usually unparsed external entities.
DTDs were introduced when XML was, and they haven't really grown since that time. They're still the technique of choice for validating XML documents with much of the software out there, but the real growth these days is in XML schemas. XML schemas give you the ability to pinpoint the format of your data in a way that DTDs can't, and you'll be hearing more about XML schemas over the next two days.

Account Sign In
View your cart