Bookmark and Share

XML Entity

An entity is a symbolic representation of information. What does that mean? Well, let's imagine for a moment that we want to create an introduction that is included in every single memo that we write. It would be monotonous to have to type out a three sentence introduction for every letter, but not to worry! XML entities can help us out.

Advertise on Tizag.com

With symbolic representation of information, a lot of text, such as, "Hello my name is Tizag.com and I am an artificial intelligence that teaches the general public how to program in web languages for free," can be represented by an entity symbol.

Entity Syntax

You may have used entities in the past. The format of an entity in XML is an ampersand (&), followed by the name of the symbol, and concluded with a semicolon.

  • Generic Entity - &name;

HTML is another markup language that supports entities. Below are some example entities and the information they represent.

  • © = ©
  • &lt; = <
  • &amp; = &
  • &quot; = "

Creating an XML Entity

An entity must be created in the Document Type Definition (DTD). Once you know where to place the entity, the rest is easy. Here is the syntax for creating your own XML entities.

  • <!ENTITY entityName "The text you want to appear when the entity is used">

Below, we have created an entity for the default introduction we want to include on all of our documents.

XML Code:

<!ENTITY intro "Hello
my name is Tizag.com and I am an artificial intelligence that teaches the general public how to program in web languages for free">

Using Your Entity

After the entity has been created in the DTD, it can then be referenced. An example email XML document that uses such an entity would look like:

XML Code:

<!ENTITY intro "Hello
my name is Tizag.com and I am an artificial intelligence that teaches the general public how to program in web languages for free">
<email>
	<to>A. Nony Mouse</to>
	<body>&intro;</body>
</email>

Entities are great for many situations. Such as when you...

  • Use something a lot. If you have a default introduction, signature, or something else that is commonly used, you should use an entity.
  • Change something often. If you have a relatively static document that has one or two pieces of frequently-changing information that are used throughout the document, replace them with entities. You only need to change the value of the entity to change hundreds or maybe even thousands of references that are in your XML document.
  • Are using complex ASCII characters that don't occur on your keyboard: © and ® are easy when you use entities.
Bookmark and Share




Download Tizag.com's XML Book

If you would rather download the PDF of this tutorial, check out our XML eBook from the Tizag.com store.

Found Something Wrong in this Lesson?

Report a Bug or Comment on This Lesson - Your input is what keeps Tizag improving with time!

Advertise Here

More Tutorials!
Microsoft Office Tutorials Artist Tutorials