You are here: Reference > appendix > xml > entities

XML entity references

There are two additional ways in XML documents to reference characters:
  • a numeric character reference refers to a character
  • an entity reference refers to a series of characters
Where entities are used, the referenced characters appear.

Numeric character references:

A numeric character reference can be specified in two formats:
&#nnnn; or &#xhhhh;
where the n decimal digits or the h hexadecimal characters identify the Unicode character code of the referenced character.

Entity references:

An entity reference is an alternative name for a series of characters. You can use an entity in the &name; format, where name is the name of the entity. There are some predefined entities in XML, furthermore you can declare entities in a DTD (Document Type Definition).

Predefined entities:

The following predefined entities exist in XML:
Entity name Character Decimal reference Hexadecimal reference
quot " " "
amp & & &
apos ' ' '
lt < &#60; &#x3C;
gt > &#62; &#x3E;

Declaring entities:

You can declare entities in a DTD in the following format:
<!ENTITY name "text">
where name is the name of the entity and text is the referenced text that appears where the entity is used.

Example 1:

This example declares an entity named 'dotto' and uses it and the predefined 'lt' entity in an XML document:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE sample [
    <!NOTATION vrml PUBLIC "VRML 1.0">
    <!ENTITY dotto "Dottoro"> 
]>
<entityTest>
    <predefined>2 &lt; 5</predefined>
    <declared>&dotto;</declared>
</entityTest>
Did you find this example helpful? yes no
The document tree of the previous example:
<entityTest>
    <predefined>2 < 5</predefined>
    <declared>Dottoro</declared>
</entityTest>
Did you find this example helpful? yes no

External links:

User Contributed Comments

Post Content

Post Content