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
Handling Entities
There's another type of item you can work with in XML documents—entities, which can be parsed or unparsed. An entity simply means a data item, such as a section of text or binary data. There are various ways to use entities, or to associate them with an XML document, as we'll be covering in the coming days, and it's appropriate to mention that now that we're discussing the parts of an XML document.
A parsed entity is one that you refer to with an entity reference. Entity references are replaced with the entities they refer to by the XML processor. There are two types of entity references: general entity references (starting with & and ending with ;) and parameter entity references (used in DTDs and starting with % and ending with ;). These references, such as one of the five predefined general entity references like ", will be replaced by the item the reference refers to. You can also specify characters with a general entity reference using the character's Unicode code—you saw that π is replaced by by an XML processor, for example.
You can define your own general entity references, as you're going to see in Day 5. For example, you could assign the general entity reference ©right; the text "(c)2005 Don't copy without permission.", and from then on, whenever you use ©right; in your XML document, the XML processor will replace it with (c)2005 Don't copy without permission.
Unparsed entities can be binary data that you don't want parsed, or even non-XML text, and they're usually external to your XML document. You don't refer to an unparsed entity with an entity reference (which the XML processor will replace with the entity itself), but by a name. When you refer to an entity by name instead of with an explicit entity reference, that entity will not be parsed or placed into your XML document directly. We'll see how this works in Day 5.
More on all this is coming up—for the purposes of our present discussion on the structure of XML documents, however, what's important to note is that you can come across entity references in an XML document, and that it is possible to associate named external data, including binary data, with an XML document.
That's it—we've covered the items that can go into an XML document now, completing today's discussion. We're ready to start creating real XML documents now, which are well-formed documents (for an XML processor to read your documents, they must be well-formed). We're going to turn to that tomorrow.
Summary | Next Section

Account Sign In
View your cart