Attributes Entitites   «Prev  Next»

Lesson 1

How to build the DTD

In addition to declaring elements, DTDs may be used to define attributes and entities.
An attribute describes properties of the XML element in which it is included. Entities refer to data items. Two types of entities may be defined in a DTD: general entities and parameter entities. In this module we describe how to declare attributes and entities in DTDs for use in XML document instances .

Module learning objectives

After completing this module, you will have the skills and knowledge necessary to:
  1. Determine the best way to use attributes in a DTD
  2. Declare lists of attributes
  3. Define entities in a DTD
  4. Create entities to use within a DTD
  5. Explain the concept of namespaces
  6. Explain the purpose of XML schemas

XML Corporate Portals

System Identifiers

A system identifier enables you to specify the location of an external file containing DTD declarations. It is comprised of two parts: the keyword SYSTEM, and a URI reference pointing to the document's location. A URI can be a fi le on your local hard drive, a fi le on your intranet or network, or even a fi le available on the Internet:

<!DOCTYPE name SYSTEM "name.dtd" [...]>
You must type the word SYSTEM after the name of the root element in your declaration. Following the SYSTEM keyword is the URI reference to the location of the file, in quotation marks. The following examples use system identifi ers:

<!DOCTYPE name SYSTEM "file:///c:/name.dtd" [ ]>
<!DOCTYPE name SYSTEM "http://wiley.com/hr/name.dtd" [ ]>
<!DOCTYPE name SYSTEM "name.dtd">

Notice that the last example has no [and] characters. This is perfectly normal. Specifying an internal subset is optional. An XML document might conform to a DTD that uses only an internal subset, only an external subset, or both. If you do specify an internal subset, it appears between the [and], immediately following the system identifier. You will see how to use an external DTD in the next section. Take a look at an alternative way to refer to external DTDs:
The next lesson shows you how to determine the best way to use attributes in a DTD.

What is an Entity in XML?

Logically speaking, an XML document is composed of a prolog followed by a root element that strictly contains all other elements; but physically the content of an XML document can be spread across multiple files. For example, each SHOW element might appear in a separate file even though the root element contains several thousand shows broadcast on one day. The storage units that contain particular parts of an XML document are entities. An entity can be a file, a database record, or any other item that contains data. For example, all the complete well-formed XML examples in this book are entities.