The Standard Generalized Markup Language (SGML; ISO 8879:1986) is a standard for defining generalized markup languages for documents. ISO 8879 Annex A.1 states that generalized markup is "based on two postulates": Declarative: Markup should describe a document's structure and other attributes rather than specify the processing that needs to be performed, because it is less likely to conflict with future developments. Rigorous: In order to allow markup to take advantage of the techniques available for processing, markup should rigorously define objects like programs and databases.
DocBook SGML and LinuxDoc are examples which used SGML tools.
Standard versions SGML is an ISO standard: "ISO 8879:1986 Information processing – Text and office systems – Standard Generalized Markup Language (SGML)", of which there are three versions:
Original SGML, which was accepted in October 1986, followed by a minor Technical Corrigendum. SGML (ENR), in 1996, resulted from a Technical Corrigendum to add extended naming rules allowing arbitrary-language and -script markup. SGML (ENR+WWW or WebSGML), in 1998, resulted from a Technical Corrigendum to better support XML and WWW requirements.
SGML is part of a trio of enabling ISO standards for electronic documents developed by ISO/IEC JTC 1/SC 34 (ISO/IEC Joint Technical Committee 1, Subcommittee 34 – Document description and processing languages) :
SGML (ISO 8879) – Generalized markup language SGML was reworked in 1998 into XML, a successful profile of SGML. Full SGML is rarely found or used in new projects. DSSSL (ISO/IEC 10179) – Document processing and styling language based on Scheme. DSSSL was reworked into W3C XSLT and XSL-FO which use an XML syntax. Nowadays, DSSSL is rarely used in new projects apart from Linux documentation. HyTime – Generalized hypertext and scheduling.ISO/IEC 10744 – Hytime HyTime was partially reworked into W3C XLink. HyTime is rarely used in new projects.
SGML is supported by various technical reports, in particular
ISO/IEC TR 9573 – Information processing – SGML support facilities – Techniques for using SGML Part 13: Public entity sets for mathematics and science In 2007, the W3C MathML working group agreed to assume the maintenance of these entity sets.
History SGML descended from IBM's Generalized Markup Language (GML), which Charles Goldfarb, Edward Mosher, and Raymond Lorie developed in the 1960s. Goldfarb, editor of the international standard, coined the "GML" term using their surname initials. Goldfarb also wrote the definitive work on SGML syntax in "The SGML Handbook". The syntax of SGML is closer to the COCOA format. As a document markup language, SGML was originally designed to enable the sharing of machine-readable large-project documents in government, law, and industry. Many such documents must remain readable for several decades—a long time in the information technology field. SGML also was extensively applied by the military, and the aerospace, technical reference, and industrial publishing industries. The advent of the XML profile has made SGML suitable for widespread application for small-scale, general-purpose use.
Document validity SGML (ENR+WWW) defines two kinds of validity. According to the revised Terms and Definitions of ISO 8879 (from the public draft):
A type-valid SGML document is defined by the standard as:
A tag-valid SGML document is defined by the standard as:
Terminology Tag-validity was introduced in SGML (ENR+WWW) to support XML which allows documents with no DOCTYPE declaration but which can be parsed without a grammar, or documents which have a DOCTYPE declaration that makes no XML Infoset contributions to the document. The standard calls this fully tagged. Integrally stored reflects the XML requirement that elements end in the same entity in which they started. Reference-free reflects the HTML requirement that entity references are for special characters and do not contain markup. SGML validity commentary, especially commentary that was made before 1997 or that is unaware of SGML (ENR+WWW), covers type-validity only.
The SGML emphasis on validity supports the requirement for generalized markup that markup should be rigorous. (ISO 8879 A.1)
Syntax An SGML document may have three parts: the SGML Declaration, the Prologue, containing a DOCTYPE declaration with the various markup declarations that together make a Document Type Definition (DTD), and the instance itself, containing one top-most element and its contents.
An SGML document may be composed from many entities (discrete pieces of text). In SGML, the entities and element types used in the document may be specified with a DTD, the different character sets, features, delimiter sets, and keywords are specified in the SGML Declaration to create the concrete syntax of the document.
Although full SGML allows implicit markup and some other kinds of tags, the XML specification (s4.3.1) states:
For introductory information on a basic, modern SGML syntax, see XML. The following material concentrates on features not in XML and is not a comprehensive summary of SGML syntax.
Optional features SGML generalizes and supports a wide range of markup languages as found in the mid 1980s. These ranged from terse Wiki-like syntaxes to RTF-like bracketed languages to HTML-like matching-tag languages. SGML did this by a relatively simple default reference concrete syntax augmented with a large number of optional features that could be enabled in the SGML Declaration. Not every SGML parser can necessarily process every SGML document. Because each processor's System Declaration can be compared to the document's SGML Declaration it is always possible to know whether a document is supported by a particular processor.
Many SGML features relate to markup minimization. Other features relate to concurrent (parallel) markup (CONCUR), to linking processing attributes (LINK), and to embedding SGML documents within SGML documents (SUBDOC).
The notion of customizable features was not appropriate for Web use, so one goal of XML was to minimize optional features. However, XML's well-formedness rules cannot support Wiki-like languages, leaving them unstandardized and difficult to integrate with non-text information systems.
Concrete and abstract syntaxes The usual (default) SGML concrete syntax resembles this example, which is the default HTML concrete syntax:
<QUOTE TYPE="example"> typically something like <ITALICS>this</ITALICS> </QUOTE>
SGML provides an abstract syntax that can be implemented in many different types of concrete syntax. Although the markup norm is using angle brackets as start- and end-tag delimiters in an SGML document (per the standard-defined reference concrete syntax), it is possible to use other characters—provided a suitable concrete syntax is defined in the document's SGML declaration. For example, an SGML interpreter might be programmed to parse GML, wherein the tags are delimited with a left colon and a right full stop, and an :e prefix denotes an end tag: :xmp.Hello, world:exmp.. According to the reference syntax, letter case (upper- or lower-case) is not distinguished in tag names, so the three tags <quote>, <QUOTE>, and <quOtE> are equivalent. (A concrete syntax might change this rule via the NAMECASE NAMING declarations.)
Markup minimization SGML has features for reducing the number of characters required to mark up a document, which must be enabled in the SGML Declaration. SGML processors need not support every available feature, thus allowing applications to tolerate many types of inadvertent markup omissions; however, SGML systems usually are intolerant of invalid structures. XML is intolerant of syntax omissions, and does not require a DTD for checking well-formedness.
OMITTAG Both start tags and end tags may be omitted from a document instance, provided: the OMITTAG feature is enabled in the SGML Declaration, the DTD indicates that the tags are permitted to be omitted, (for start tags) the element has no associated required (#REQUIRED) attributes, and the tag can be unambiguously inferred by context.
For example, if OMITTAG YES is specified in the SGML Declaration (enabling the OMITTAG feature), and the DTD includes the following declarations: <!ELEMENT chapter - - (title, section+)> <!ELEMENT title o o (#PCDATA)> <!ELEMENT section - - (title, subsection+)>
then this excerpt:
<chapter>Introduction to SGML <section>The SGML Declaration <subsection> ...
which omits two tags and two tags, would represent valid markup.
Omitting tags is optional – the same excerpt could be tagged like this:
<chapter><title>Introduction to SGML</title> <section><title>The SGML Declaration</title> <subsection> ...
and would still represent valid markup.
Note: The OMITTAG feature is unrelated to the tagging of elements whose declared content is EMPTY as defined in the DTD: <!ELEMENT image - o EMPTY>
Elements defined like this have no end tag, and specifying one in the document instance would result in invalid markup. This is syntactically different from XML empty elements in this regard.
SHORTREF Tags can be replaced with delimiter strings, for a terser markup, via the SHORTREF feature. This markup style is now associated with wiki markup, e.g. wherein two equals-signs (==), at the start of a line, are the "heading start-tag", and two equals signs (==) after that are the "heading end-tag".
SHORTTAG SGML markup languages whose concrete syntax enables the SHORTTAG VALUE feature, do not require attribute values containing only alphanumeric characters to be enclosed within quotation marks—either double " " (LIT) or single ' ' (LITA)—so that the previous markup example could be written:
<QUOTE TYPE=example> typically something like <ITALICS>this</> </QUOTE>
One feature of SGML markup languages is the "presumptuous empty tagging", such that the empty end tag </> in <ITALICS>this</> "inherits" its value from the nearest previous full start tag, which, in this example, is <ITALICS> (in other words, it closes the most recently opened item). The expression is thus equivalent to <ITALICS>this</ITALICS>.
NET Another feature is the NET (Null End Tag) construction: <ITALICS/this/, which is structurally equivalent to <ITALICS>this</ITALICS>.
Other features Additionally, the SHORTTAG NETENABL IMMEDNET feature allows shortening tags surrounding an empty text value, but forbids shortening full tags:
<QUOTE></QUOTE>
can be written as
<QUOTE//
wherein the first slash ( / ) stands for the NET-enabling "start-tag close" (NESTC), and the second slash stands for the NET. NOTE: XML defines NESTC with a /, and NET with an > (angled bracket)—hence the corresponding construct in XML appears as .
The third feature is 'text on the same line', allowing a markup item to be ended with a line-end; especially useful for headings and such, requiring using either SHORTREF or DATATAG minimization. For example, if the DTD includes the following declarations:
<!ELEMENT lines (line*)> <!ELEMENT line O - (#PCDATA)> <!ENTITY line-tagc "</line>"> <!SHORTREF one-line "&#RE;&#RS;" line-tagc> <!USEMAP one-line line>
(and "&#RE;&#RS;" is a short-reference delimiter in the concrete syntax), then:
<lines> first line second line </lines>
is equivalent to:
<lines> <line>first line</line> <line>second line</line> </lines>
Formal characterization SGML has many features that defied convenient description with the popular formal automata theory and the contemporary parser technology of the 1980s and the 1990s. The standard warns in Annex H:
A report on an early implementation of a parser for basic SGML, the Amsterdam SGML Parser, notes and specifies various differences.
There appears to be no definitive classification of full SGML against a known class of formal grammar. Plausible classes may include tree-adjoining grammars and adaptive grammars.