XML Creating Entities

In the previous lesson, we learned what an entity is. We also saw the 5 predefined XML entities. In this lesson, we will learn how to create our own entities.

To create your own entity, you simply define the entity in your DTD. Once you've defined the entity in your DTD, you are ready to use it within your XML document.

We will be covering DTDs later so don't be too concerned if you don't know what a DTD is yet.

Defining Your Entity

You define your entity using the <!ENTITY> element using the following syntax:

Here, name is the entity's name. definition is the entity's definition.

Using Your Entity

Whenever you need to use your entity, you simply write the entity's name, surrounded by an ampersand (&) and a semi-colon (&).


Imagine you have some text that you want to repeat at the bottom of all your documents. Let's say the text goes something like "Thank you, please come again!".

Instead of typing all that text out every time you need to use it, you could create an entity called say, footer. That way, you just need to include &footer; whenever you want to include that text. Now, if you ever need to change the text you only need to change it in one place — the definition.