Quackit Logo
HTML
CSS
Scripting
Database
Hosting
Design
XML
IMCreator - Free Website Builder

XML Entities

XML entities allow you to use text to refer to a data item, instead of using the data item itself.

You can use entities to represent:

  • Characters that would otherwise cause problems for the XML processor
  • Large blocks of data that need to be repeated throughout the document
  • Characters that you can't type on your keyboard (i.e. ©)

Problematic Characters

Some characters have a special meaning in XML. For example, the less than sign (<) marks the beginning of a tag. And, of course, the greater than sign (>) marks the end of the tag. When the XML processor parses the document, it looks for these characters (and others) to determine how to interpret the document.

This is fine, as long as your data doesn't contain any of these characters. But what if it does? What if your data contains say, a less than sign?

Imagine you had the following text within an element: 10 < 5. When the XML processor encounters the <, it will assume it's the start of an opening tag. Problem is, it's not.

In order to include characters such as < and & etc, you need to use their entity reference instead of the character itself.

Entity Syntax

You start an entity reference using the & character and close it using the ; character.

Example:

CodeResult

<

Predefined Entity References

There are 5 predefined entity references in XML. These are:

Entity ReferenceCharacter
&lt;<
&gt;>
&amp;&
&quot;"
&apos;'

Enjoy this page?

  1. Link to this page (copy/paste into your own website or blog):
  2. Link to Quackit using one of these banner ads.

Thanks for supporting Quackit!