SGML Entity - Syntax

Syntax

An entity is defined via an entity declaration in a document's DTD. For example:

This DTD markup declares the following:

  • An internal general entity named "greeting1" exists and consists of the string "Hello world".
  • An external general entity named "greeting2" exists and consists of the text found in the resource identified by the URI "file:///hello.txt".
  • An internal parameter entity named "greeting3" exists and consists of the string "¡Hola!".
  • An internal general entity named "greeting4" exists and consists of the string "¡Hola! means Hello!".

Names for entities must follow the rules for SGML names, and there are limitations on where entities can be referenced.

Parameter entities are referenced by placing the entity name between "%" and ";". Parsed general entities are referenced by placing the entity name between "&" and ";". Unparsed entities are referenced by placing the entity name in the value of an attribute declared as type ENTITY.

The general entities from the example above might be referenced in a document as follows:

'&greeting1;' is a common test string. The content of hello.txt is: &greeting2; In Spanish, &greeting4;

When parsed, this document would be reported to the downstream application the same as if it has been written as follows, assuming the hello.txt file contains the text "Salutations":

'Hello world' is a common test string. The content of hello.txt is: Salutations In Spanish, ¡Hola! means Hello!

A reference to an undeclared entity is an error unless a default entity has been defined. For example:

Additional markup constructs and processor options may affect whether and how entities are processed. For example, a processor may optionally ignore external entities.

Read more about this topic:  SGML Entity