The ENTITY Type Declaration

Entities reference data that act as an abbreviation or can be found at an external location. Entities help to reduce the entry of repetitive information and also allow for easier editing (by reducing the number of occurrences of data to edit). There are two types of entity declarations: GENERAL entity declarations, and PARAMETER entity declarations.

The GENERAL ENTITY Declaration:

The types of general entities include:

INTERNAL (PARSED) GENERAL ENTITY Declaration:

Internal parsed entities generally reference text. The correct definition is that they refer to data that an XML processor has to parse.

<!ENTITY name "entity_value">

where:
Example:
<?xml version="1.0" standalone="yes" ?>
<!DOCTYPE author [
	<!ELEMENT author (#PCDATA)>
	<!ENTITY js "Jo Smith">
]>
<author>&js;</author>

EXTERNAL (PARSED) GENERAL ENTITY Declaration:

External parsed entities generally reference text. The correct definition is that they refer to data that an XML processor has to parse. External entities are useful for creating a common reference that can be shared between multiple documents. Any changes that are made to external entities are automatically updated in the documents they are referenced. There are two types of external entities: private, and public. Private external entities are identified by the keyword SYSTEM, and are intended for use by a single author or group of authors. Public external entities are identified by the keyword PUBLIC and are intended for broad use.

<!ENTITY name SYSTEM "URI">
<!ENTITY name PUBLIC "public_ID" "URI">

where:
Example:
<?xml version="1.0" standalone="no" ?>
<!DOCTYPE copyright [
	<!ELEMENT copyright (#PCDATA)>
	<!ENTITY c SYSTEM "http://www.xmlwriter.net/copyright.xml">
]>
<copyright>&c;</copyright>
<?xml version="1.0" standalone="no" ?>
<!DOCTYPE copyright [
	<!ELEMENT copyright (#PCDATA)>
	<!ENTITY c PUBLIC "-//W3C//TEXT copyright//EN" "http://www.w3.org/xmlspec/copyright.xml">
]>
<copyright>&c;</copyright>

EXTERNAL (UNPARSED) GENERAL ENTITY Declaration:

External unparsed entities generally reference non-XML data. The 100% correct definition is that they refer to data that an XML processor does not have to parse.

<!ENTITY name SYSTEM "URI" NDATA name>
<!ENTITY name PUBLIC "public_ID" "URI" NDATA name>

Example:
<?xml version="1.0" standalone="no" ?>
<!DOCTYPE img [
	<!ELEMENT img EMPTY>
	<!ATTLIST img src ENTITY #REQUIRED> 
	<!ENTITY logo SYSTEM "http://www.xmlwriter.net/logo.gif" NDATA gif>
	<!NOTATION gif PUBLIC "gif viewer">
]>
<img src="logo"/>
<?xml version="1.0" standalone="no" ?>
<!DOCTYPE img [
	<!ELEMENT img EMPTY>
	<!ATTLIST img src ENTITY #REQUIRED> 
	<!ENTITY logo PUBLIC  "-//W3C//GIF logo//EN" "http://www.w3.org/logo.gif" NDATA gif>
	<!NOTATION gif PUBLIC "gif viewer">
]>
<img src="logo"/>

Using entities within entities:

The following examples show how general entities can be used in the DTD.

CORRECT Example:
<?xml version="1.0"?>
<!DOCTYPE author [
	<!ELEMENT author (#PCDATA)>
	<!ENTITY email "josmith@theworldaccordingtojosmith.com">

	<!--the following use of a general entity is legal if it
	is used in the XML document-->
	<!ENTITY js "Jo Smith &email;">
]>
<author>&js;</author>

INCORRECT Example:
<!--the two entity statements are infinitely recursive-->
<!ENTITY email "user@user.com &js;">
<!ENTITY js "Jo Smith &email;">

Predefined GENERAL entities:

Predefined entities are entities already used for markup. The table below lists the predefined entities and how to declare them in a DTD.

Predefined entities:How to declare these entities in a DTD:
&lt;<!ENTITY lt "&#38;#60;">
&gt;<!ENTITY gt "&#62;">
&amp;<!ENTITY amp "&#38;#38;">
&apos;<!ENTITY apos "&#39;">
&quot;<!ENTITY quot "&#34;">

The PARAMETER ENTITY Declaration:

The types of parameter entities include:

Rules:

INTERNAL (PARSED) PARAMETER ENTITY Declaration:

Internal parameter entity references are used to declare entities existing only in the DTD.

<!ENTITY % name "entity_value">

where:
Examples:
<!--external DTD example-->
<!ENTITY % p "(#PCDATA)">
<!ELEMENT student (id,surname,firstname,dob,(subject)*)>
<!ELEMENT id %p;>
<!ELEMENT surname %p;>
<!ELEMENT firstname %p;>
<!ELEMENT dob %p;>
<!ELEMENT subject %p;>
<!--external DTD example-->
<!ELEMENT author (#PCDATA)>
<!ENTITY % js "Jo Smith">

<!--note that the general entity statement below is used
to reference a parameter entity-->
<!ENTITY wb "written by %js;">
<!--external DTD example-->
<!ENTITY % info "(id,surname,firstname)">
<!ELEMENT lab_group_A %info;>
<!ELEMENT lab_group_B %info;>
<!ELEMENT lab_group_C %info;>

Note:

EXTERNAL (PARSED) PARAMETER ENTITY Declaration:

External parameter entity references are used to link external DTDs. There are two types of external entities: private, and public. Private external entities are identified by the keyword SYSTEM, and are intended for use by a single author or group of authors. Public external entities are identified by the keyword PUBLIC and are intended for broad use.

<!ENTITY % name SYSTEM "URI">
%name;
<!ENTITY % name PUBLIC "public_ID" "URI">
%name;

where:
Example:
<?xml version="1.0" standalone="no"?>
<!DOCTYPE student [
	<!ENTITY % student SYSTEM "http://www.university.com/student.dtd">
	%student;
]>

<<Previous Section Contents
Main Contents
Next>>