USING ENTITIES TO CONNECT OTHER FILES

SGML uses something called a general entity to include other files inside a document. There are other types of entities in SGML, but this is the most common. A general entity is identified by an entity declaration in the internal subset of your main document. It looks like this:

<!DOCTYPE  MyDocuments PUBLIC "-//Joan Duvall//DTD Joan's Documents//EN" [
...
<!ENTITY Chapter1 SYSTEM "chp1.sgm">
... ]>

The <!ENTITY indicates this is an entity declaration. Chapter1 is the name you give to the entity. SYSTEM is a keyword that tells an SGML system that the identifier for the file for this entity is specific to your computer system - most commonly this means that you supply the file name to include directly in the declaration. In this example chp1.sgm is the file name that should be included and this is all the path information that the system needs to find the file.

With entities, the declaration simply identifies the file or content to use - you decide where that should actually be included by inserting the entity in your document. To include the entity, you insert an ampersand, the entity name, and a semi-colon. For example:

<!DOCTYPE  MyDocuments PUBLIC "-//Joan Duvall//DTD Joan's Documents//EN" [
...
<!ENTITY Chapter1 SYSTEM "chp1.sgm">
... ]>
<MyDocuments>
<Title>My First Novel</Title>
<Author>Joan Duvall</Author>
&Chapter1;
</MyDocuments>

This document has only one chapter, which is included where &Chapter1; appears. Any file that is included that contains text and SGML tags must also fit properly within the structure of the document, as that is defined in the DTD. They also must be balanced - any tag that starts in a separate file must end in that file. In this example, the file chp1.sgm contains text marked up in SGML and the contents are all enclosed within <Chapter> ... </Chapter> tags as the Chapter element is valid content at this point within the document.