SGML entity

From Wikipedia, the free encyclopedia

(Redirected from HTML entity)
Jump to: navigation, search

In SGML and its derived markup languages HTML and XML, an entity is a named body of data associated with a document, or the unnamed document entity itself. Once defined, a named entity can be referenced any number of times within the document, via entity references.

An entity typically consists of a sequence of one or more characters, either encapsulated within a declaration of the entity's existence, or encoded and stored externally in a text file. Such entities and their references are comparable to macros and include files in programming languages. However, entities don't necessarily have to contain parseable text; they may also be binary files that are included in a document only by reference, with the entity name as the value of an ENTITY-type attribute.

Contents

Entities are classified as general or parameter:

  • A general entity can only be referenced within the document content.
  • A parameter entity can only be referenced within the DTD.

Entities are further classified as internal or external:

  • An internal entity exists within its own declaration.
  • An external entity exists in an external file.

Entities are also further classified as parsed or unparsed:

  • A parsed entity contains text which will be incorporated into the document and parsed, if the entity is referenced. A parameter entity can only be a parsed entity.
  • An unparsed entity contains any kind of data, and a reference to it will result in the application merely being notified of the entity's presence; the content of the entity will not be parsed, even if it is text. An unparsed entity can only be external.

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.

In SGML, entities have additional capabilities and nuances that are not described here.

In HTML, the DTDs are immutable; new entities cannot be defined. In XML, new entities can be defined, but XML only supports a limited subset of SGML entity functionality.

Standard entity sets for SGML and some of its derivatives have been developed as mnemonic devices, to ease document authoring when there is a need to use characters that are not easily typed or that are not widely supported by legacy character encodings. Each such entity consists of just one character from the Universal Character Set. Although any character can be referenced using a numeric character reference, a character entity reference allows characters to be referenced by name instead of code point.

HTML 4, for example, has 252 built-in character entities that don't have to be explicitly declared. XML has five. XHTML has the same five as XML, but if its DTDs are explicitly used, then it has 253 (' being the extra entity).

The terms entity, character entity, character reference, character entity reference, and entity reference are often used interchangeably.

Advanced Search
Included Web Search Engines


Safe Search

close

Top Matching Results

Occasionally Search.com will highlight specialized results that are based on the context of your query. Examples of specialized results include specific links to news, images, or video.

Top Matching Results may highlight information from other Search.com pages, content from the CNET Network of sites, or third party content. The listings are based purely on relevance. Search.com does not receive payment for listings in this section but our partners that provide this data may get paid for listing these products.

Sponsored Links

This section contains paid listings which have been purchased by companies that want to have their sites appear for specific search terms and related content. These listings are administered, sorted and maintained by a third party and are not endorsed by Search.com.

Search Results

Search.com sends your search query to several search engines at one time and integrates the results into one list which has been sorted by relevance using Search.com's proprietary algorithm. You can customize the list of search engines included in your metasearch from the preferences.

The search engines that are used in your metasearch may allow companies to pay to have their Web sites included within the results. To view the Paid Inclusion policy for a specific search engine, please visit their Web site. Search.com does not accept payment or share revenue with any search engine partner for listings in this section.