Wattle Software - producers of XMLwriter XML editor
 Home | Search | Site Map 
XMLwriter
 Screenshots
 Features
 About Latest Version
 Awards & Reviews
 User Comments
 Customers
Download
 Download XMLwriter
 Download Plug-ins
 Download Help Manual
 MSXML Updates
 Downloading FAQ
Buy
 Buy XMLwriter
 Pricing
 Upgrading
 Sales Support
 Sales FAQ
Support
 Sales Support
 Technical Support
 Submit a Bug Report
 Feedback & Requests
 Technical FAQ
Resources
 XML Links
 XML Training
 XMLwriter User Tools
 The XML Guide
 XML Book Samples
Wattle Software
 About Us
 Contact Details
ENTITY 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)
  • EXTERNAL (PARSED)
  • EXTERNAL (UNPARSED)


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:

  • entity value: any character that is not an '&', '%' or ' " ', a parameter entity reference ('%Name;'), an entity reference ('&Name;') or a Unicodeglossary character reference.
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:

  • URI: In practice, this is a URL where the external parsed entity can be found.
  • public_ID: This may be used by an XML processor to generate an alternate URI where the external parsed entity can be found. If it cannot be found at this URI, the XML processor must use the normal URI.
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:

  • INTERNAL (PARSED)
  • EXTERNAL (PARSED)

Rules:

  • Parameter entity references may not be used within markup in an internal DTDwell-formedness constraint.


INTERNAL (PARSED) PARAMETER ENTITY Declaration:

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

<!ENTITY % name "entity_value">

where:

  • entity_value: any character that is not an '&', '%' or ' " ', a parameter entity reference ('%Name;'), an entity reference ('&Name;') or a Unicodeglossary character reference.
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:

  • Note the use of external DTD examples above. Parameter entity references may not be used within markup in an internal DTDwell-formedness constraint.


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:

  • URI: In practice, this is a URL where the external parameter entity can be found.
  • public_ID: This may be used by an XML processor to generate an alternate URI where the external parameter entity can be found. If it cannot be found at this URI, the XML processor must use the normal URI.
Example:
<?xml version="1.0" standalone="no"?>
<!DOCTYPE student [
  <!ENTITY % student SYSTEM "http://www.university.com/student.dtd">
  %student;
]>


XML Guide TOC

XML Declaration
DOCTYPE Declaration & DTDs
ELEMENT Type Declaration
ATTLIST Declaration
ENTITY Declaration
NOTATION Declaration
CDATA Section
Processing Instruction
Conditional Section
Comments

Glossary

© Wattle Software 1998-2013. All rights reserved.