Quackit Logo
FREE Hosting!
With every domain you register with ZappyHost you get FREE hosting.
Create free Flash websites

XML Creating Entities

Print Version

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.

Note: 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:

<!ENTITY name definition>

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 (&).

&entity_name;

Example

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.

<?xml version="1.0"?>
<!DOCTYPE tutorials [
<!ENTITY footer "Thank you, please come again!">
<]>
<tutorials>
  <tutorial>
    <name>XML Tutorial</name>
    <url>http://www.quackit.com/xml/tutorial</url>
    <footer>&footer;</footer>
  </tutorial>
  <tutorial>
    <name>HTML Tutorial</name>
    <url>http://www.quackit.com/html/tutorial</url>
    <footer>&footer;</footer>
  </tutorial>
</tutorials>

Enjoy this website?

  1. Add this page to your Favorites
  2. Link to this page (copy/paste into your own website or blog):
  3. Help support Quackit by making a donation

Oh, and thank you for supporting Quackit!

Need Website Content?
Get unique, quality digital content for your website.
  • 270+ Website Templates
  • 800+ Flash Templates
  • 25,000+ Images, Logos
  • 30,000+ e-Books
  • 15,000+ Scripts
  • 27,000+ Animated GIFs
  • 21,000+ Ringtones
  • ...and much more!
Get your content now!
$1.99 .info domain names!
© Copyright 2000 - 2010 Quackit.com