Menu
Predefined Entities in XML - Five Special Symbols by Kevin Howard Goldberg

Entities are a kind of autotext; a way of entering text into an XML document without typing it all out. There are many letters and symbols that can be inserted into HTML documents by using entities. In XML, however, there are only five predefined entities.


Figure 1.22 When this document is parsed, the &gt; entity will be displayed as >. So when the value of the height element is displayed, it will likely read something like "< 107 "

To write the five predefined entities:

Type &amp; to create an ampersand character (&).
Type &lt; to create a less than sign (<).
Type &gt; to create a greater than sign (>).
Type &quot; to create a double quotation mark (").
Type &apos; to create a single quotation mark or apostrophe (').

Tips

Predefined entities exist in XML because each of these characters have specific meanings. For example, if you used ( <) within the text value of an element or attribute, the XML processor would think you were starting a new element (Figure 1.22).

You may not use ( <) or (&) anywhere in your XML document, except to begin a tag or an entity, respectively. If you need to use one of these characters within the text value of an element or attribute, you must use one of the predefined entities.

You may use ("), ('), or ((>) within the text value of an element or attribute. However, when using (") or ('), be on the lookout for unintentionally matching existing quotes. Also, I always recommend using the predefined entity for (>) to avoid any possible confusion.

If you want to create additional entities for your XML documents, you must explicitly declare them (see Chapter 7 of Learn more about XML: Visual Quickstart Guide at amazon.com).

About the Author

Kevin Howard Goldberg has been working with computers since 1976 when he taught himself BASIC on his elementary school's PDP 11/70. Since then, Kevin's career has included management consulting, lead software development and in his current capacity, he runs technology operations for a world-class Internet Strategy, Marketing and Development company. Kevin holds a bachelor's degree in Economics and Entrepreneurial Management from the Wharton School of Business at the University of Pennsylvania, and is a candidate for a master's degree in Computer Science at the University of California, Los Angeles.

Reader J. Hatch says, "This book is a great way to get started if you have not done a lot of HTML and are looking for a way to get your feet wet with XML and it's interactions with HTML. It does a great job of step-by-step leading you through most of the basic concepts used in XML. If you don't know much about XML and want to get started and need a quick reference for figuring out what is going on in an XML file, this is a great starting point. It is compact and the approach is to explain something minimally and then show a example. There are example files to download that the book references. To get the most out of this book, you will have to download the examples."

Learn more about XML: Visual Quickstart Guide at amazon.com


Learn more at amazon.com