Working XMP and LISTING Tag Element Examples

This file illustrates the actual proper use of the <XMP> and <LISTING> elements, or "tags," as they were used in the original conception for HTML, and clear through version 3.2. These elements served to enable the web designer to show the text in the file exactly as typed, as otherwise HTML automatically eliminates all the white space, reducing it down to a single space if even that, and lets the line breaks fall where appropriate given the screen and font size. This was also useful for printing such things as tabular data and ascii art, because of using a monospace font as opposed to the more variable width fonts used for HTML which are generally more presentable as simple reading text, but would fail to line up correctly the way a monospace font would do. One must also recall that in the earlier days of developing HTML, most writers and preparers of text documents on computers were long accustomed to using tabs and spacing to distribute characters on the screen as needed to portray their point visually.

In these earliest HTML days, if you wanted to draw something or format a table, there was only one way, and that needed tags for monospace letters which also respect the amount of white space (instead of collapsing all white space into a single space for display or a new line where needed, as is done all elsewhere in HTML). This was the one area where the old raw ASCII text documents were still advantageous, and HTML could only catch up by providing <XMP>, <LISTING>, and (somewhat later) the more advanced, useful, and SGML-compliant <PRE> tag, to enable extracts of the same to be inserted into an HTML document intact. So now you could get such things as:

ASCII ART: _-_ [o,o] \-/ (I think this guy is a member of Devo) DIAGRAMS: ^ ^ / \ / \ / X \ / / \ \ / / \ \ < A < C > B > \ \ / / \ \ / / \ X / \ / \ / V V (The intersection of A and B is C) TABULAR INFORMATION: Rainfall: Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec 1984: 23 22 18 12 6 7 2 0 1 16 8 24 1985: 21 20 6 8 7 5 1 1 1 9 16 22 1986: 20 10 8 4 2 0 0 0 0 6 9 12 (Looks like we are heading into a major drought here) COMPUTER PROGRAMS: main() /* Fahrenheit-Celsius table */ { int fahr; for (fahr = 0; fahr <= 300; fahr = fahr + 20) printf("%4d %6.1f\n", fahr, (5.0/9.0)*(fahr-32)); } (Anyone but me remember Kernighan and Ritchie?) TABLE OF CONTENTS: PREFACE .................................................... ii 1. INTRODUCTION ........................................... 1 1.1. Scope ............................................ 1 1.2. Communication Framework .......................... 2 2. NOTATIONAL CONVENTIONS ................................. 3 (Extracted from RFC822: Standard for ARPA Internet Text Messages)

It's companion tag <LISTING> was similarly introduced to portray wider outputs, particularly those which might be printed on the old 132-column-wide computer fanfold paper, for example:

CRSS - UTILITIES 17 APR 2002 11:26:07 ------------------------------- SIMULATED TELEMETRY DATA STREAM ------------------------------- Project : TEST5 Operation : const Version : 08 Stream : PCM01 ------------------------------------------------------------------------------------------------------------------------------------ DEFINE SIMULATION INFORMATION ----------------------------- Creation Analyst - rojas Date - 25 JAN 00 Time - 13:01:32 Last Update by - admin2 Date - 17 APR 02 Time - 10:47:08 Number of Formats - 1 Duration (seconds) - 60.00 Data Rate (bps) - 880000.00000 Duration (frames) - 60001 Format # 1 Number of frames - 60001 Frame size (bits) - 880 Word size (bits including parity) - 8 ------------------------------------------------------------------------------------------------------------------------------------ Major Frame # 1 Time (sec) - 0.00 Format # 1 Size (bits) - 880 Sync (bits) - 0 Parity - none ------------------------------------------------------------------------------------------------------------------------------------ 1 00 80 aa 80 80 80 aa aa 80 c0 00 c0 00 00 c0 00 80 aa aa c0 c0 00 00 80 aa 80 00 80 00 00 80 00 00 00 00 00 80 00 80 00 321 00 aa aa 00 aa 80 aa 80 0a 80 00 aa 80 aa aa aa 80 00 00 00 80 aa aa aa aa aa 80 80 aa 80 aa 80 aa aa 80 aa 00 aa aa aa 641 aa aa 80 aa aa aa aa aa 7f 80 00 80 aa 80 aa aa 80 aa aa aa aa 00 aa aa 80 2a aa fa f3 20 Major Frame # 2 Time (sec) - 0.00 Format # 1 Size (bits) - 880 Sync (bits) - 0 Parity - none ------------------------------------------------------------------------------------------------------------------------------------ 1 01 80 aa 80 80 80 aa aa 80 c0 00 c0 00 00 aa aa 80 aa aa c0 c0 00 00 80 aa 80 00 80 00 00 80 00 00 00 00 00 80 00 80 00 321 00 aa aa aa aa 80 aa 80 80 80 00 aa 80 aa 80 aa 80 00 aa 80 80 aa aa aa aa aa aa 80 aa 80 aa 80 aa aa 80 08 00 aa 08 aa 641 00 00 80 aa aa aa aa aa aa 80 00 80 aa 80 aa aa 80 aa aa aa aa 00 00 00 80 aa aa fa f3 20

From the 1991-1992 era of HTML there are many surviving examples of <XMP> being used in the W3C archives (For example: A, B, C, D, E, F, G, H, and I), and I have found one <LISTING> example here. The oldest surviving instance of both of these tags, albeit only as demonstrations however, is found here.

With HTML versions from the oldest surviving DTD to 1 through 3 of the of HTML specification, the <XMP> and <LISTING> elements (along with the <PLAINTEXT> element) were depreciated. Notice how HTML 2 survives now in four basic varieties, two of which accept, and the other two of which are Strict and do not tolerate, these non-SGML-compliant tags, but of HTML 3.2, only the non-strict version can be validated:

HTML "0.a" - from the beginning through January 10, 1991
A demonstration test file exists from this period which uses both of these tags, but it is not clear whether they had been implemented as of yet since no other examples are of these tags have been found from this period.
HTML "0.c" - from January 23, 1991 though November 23, 1992
This early version of HTML saw considerable use of <XMP> and shortly after, <LISTING>, though these tags permitted non-SGML compliant contents that might parse like tags but are merely text to be displayed as is.
HTML "0.d" - from November 26, 1992 through May 24, 1993
During this span, <XMP> and <LISTING> are rapidly falling into disuse and a DTD (HTML "0.h") generated during this period shows them as depreciated.
HTML "1.k" - Version 1 (first release)
In this first published draft of HTML, <XMP> and <LISTING> are still listed as depreciated, but still part of the language.
HTML "1.m" - Version 1 (second release)
In the next published draft of HTML, <XMP> and <LISTING> are still listed as depreciated, but still part of the language.
HTML Version 2 Level 1
This is like the level 2 default but it excludes all the forms elements, i. e. <FORM>, <INPUT>, <TEXTAREA>, <SELECT>, and <OPTION>. <XMP> and <LISTING> are permitted by this version of HTML.
HTML Version 2 Strict Level 1
This is like regular Level 1 but it also excludes <XMP> and <LISTING>, along with such constructs as nesting a header (<H*> element) within a link (<A> element).
HTML Version 2 Level 2
This is the default and includes and permits all HTML Level 2 functions and elements and attributes. <XMP> and <LISTING> are also permitted by this version of HTML.
HTML Version 2 Strict Level 2
This excludes <XMP> and <LISTING> and also forbids such constructs as nesting a header (<H*> element) within a link (<A> element), or having a forms <INPUT> element which is not within a block level element such as <P>.
HTML Version 3.2
<XMP> and <LISTING> both continue as depreciated in the loose form of this HTML (There is no public document type declaration for Strict HTML 3.2).
HTML Version 4.0 and 4.01
<XMP> and <LISTING> have finally vanished altogether, never to be heard from again.

Typically (and with reasonably good cause), the web designer is advised against using these depreciated/obsolete tags in favor of <PRE>. What is not often made clear is how <PRE> differs from <XMP> and <LISTING>. Perhaps it is obvious that <LISTING> is meant to use a narrower font than <XMP> and <PRE>, but a more fundamental difference is seldom explained plainly for the novice, let alone is he told why there was such a push to eliminate these older tags. Superficially, <XMP> looks exactly like <PRE>, as for example the famous Irish toast, actually using here <XMP>:

St. Patrick was a gentleman Who through strategy and stealth Drove all the snakes from Ireland, Here's a toasting to his health; But not too many toastings Lest you lose yourself and then Forget the good St. Patrick And see all those snakes again.

In most browsers it looks no different using <PRE>:

St. Patrick was a gentleman
Who through strategy and stealth
Drove all the snakes from Ireland,
Here's a toasting to his health;
But not too many toastings
Lest you lose yourself and then
Forget the good St. Patrick
And see all those snakes again.

However, it is not merely a matter of eliminating a redundant tag, as there is a difference. Lets try the same thing, but with a little bit of emphasis, using the <B> Bold font tag, and also replacing "and" with "&". First, here is this poem using <PRE>:

St. Patrick was a gentleman
Who through strategy & stealth
Drove all the snakes from Ireland,
Here's a toasting to his health;
But not too many toastings
Lest you lose yourself & then
Forget the good St. Patrick
& see all those snakes again.

And now see what the same code would give you if you used <XMP> (but this here can only simulate it with <PRE> for reasons I will get to):

St. <B>Pat</B>rick was a <B>gent</B>leman
Who through <B>strat</B>egy &amp; <B>stealth</B>
Drove <B>all</B> the snakes from <B>Ir</B>eland,
Here's a <B>toast</B>ing to his <B>health</B>;
But <B>not</B> too many <B>toast</B>ings
Lest you <B>lose</B> yourself &amp; <B>then</B>
For<B>get</B> the good St. <B>Pat</B>rick
&amp; see <B>all</B> those snakes a<B>gain</B>.

It can get messy when you have any of the "magic" characters (e. g. "<" or "&") in your file and wish to see them correctly, in converting from the sort of text that looks fine using <XMP> to text that looks the same using <PRE>, you must make all the suitable substitutions throughout the passage. If these characters appear (for example in HTML samples), it will not look good. If within <XMP> you had (again I use <PRE> to simulate <XMP> for the same reasons I will get to):

The <STRONG> tag (ending with </STRONG>) is more emphatic
than the <EM> tag (which ends with </EM>).  Use the &amp;
character entity to place an ampersand in the text.

Then merely replacing the <XMP> with <PRE> element, what you get is:

The  tag (ending with ) is more emphatic
than the  tag (which ends with ).  Use the &
character entity to place an ampersand in the text.

And so to fix it you would have to change it to look like (here I can and do use <XMP> to show easily what the raw HTML looks like):

The &lt;STRONG&gt; tag (ending with &lt;/STRONG&gt;) is more emphatic than the &lt;EM&gt; tag (which ends with &lt;/EM&gt;). Use the &amp;amp; character entity to place an ampersand in the text.

And that will fix the <PRE> version, arriving where you started, but now using <PRE> instead of <XMP>:

The <STRONG> tag (ending with </STRONG>) is more emphatic
than the <EM> tag (which ends with </EM>).  Use the &amp;
character entity to place an ampersand in the text.

Since, as seen in the examples above, the <XMP> element really is different from the <PRE> element, why eliminate it? This gets down to the nature of the structure of HTML. HTML's rules are actually derived from SGML rules. Where the rules have been followed there is absolutely no chance of any misunderstanding, and as the web is potentially read by all around the world, this is a serious and valid concern. For just as in poetry, the English language can be all turned around and still come out understandable (e. g. "Away went the boy, to the barbershop he went"), there are more normal standards that are normally meant to be used, lest one be misunderstood. ("The boy went away to the barbershop." - not as sonorous, but no chance of any misunderstanding.) Likewise, most user agents (browsers) can be astonishingly forgiving of the most horrid grammatical mistakes in HTML and still generate a pleasing presentation of the information so encoded, but for fear of misunderstanding (what looks great on one user agent can look like crap on another), there are again much more standard forms for the language's "grammar" to be followed.

In particular, there is no way within the scope of SGML and its parsing program to "turn off" this parsing for some stretch of text within a document purporting itself to be HTML. This means that the stretches of material contained between the <XMP> tags, or between the <LISTING> tags, or coming at all after the <PLAINTEXT> tag, though it is only copied like text to the user agent's screen, nevertheless continues to be parsed and checked. In all the places in this file where I have actually used <XMP> and <LISTING>, I have been judiciously careful to see to it that what is contained between these tags will still parse out harmlessly, no matter how goofy some will look as examples of what can happen when these preformatted tags are not used correctly. Imagine what would happen if one had between the <XMP> and </XMP> tags within a document (and again I am using <PRE> and </PRE> here as in the two places above to substitute for <XMP>, so I don't really have this in my source) the following:

... and then there comes the </BODY> tag & the
</HTML> tag which close out the document.

The parser, scanning this section, would encounter the </BODY> element closing tag, and having seen it, wonder what all that other stuff is in the file that comes after it. By the definition of HTML the only things which can come after the </BODY> tag are white space, comments, the </HTML> closing tag, or (where rarely applicable) <PLAINTEXT>. Then again it would do the same for the </HTML> element closing tag. And nothing (but empty white space and equally unimportant comments) comes after </HTML>. Finally, one could also get an error from having the & character not followed by any of the valid character entities (such as "&lt;"), and this too could be judged an error.

It gets worse even than that. It ignores opening tags, merely noting their presence but not evaluating them, but closing tags (since it is watching carefully for the </XMP> tag) all get noted, but won't get matched up to an opening tag even if present. In short, trying to validate a file containing a lot of <XMP> or <LISTING> or <PLAINTEXT> text can be a real mess. But <PRE> on the other hand eliminates these problems, having real tags only where the web designer wants them (as for example with the <B> element in the poem above, or links, or italics), and the rest are mere text and harmless character entities from the standpoint of the parser. Notice how even in this demonstration file, three of the samples which should have been done with <XMP> had to be simulated using <PRE> just to keep this file actually in compliance to the standard. See here to view an SGML Failure Mode demonstration file using the actual <XMP> and other tags for the examples simulated above, and to see more of why these tags are just not good SGML. Then see what happens when you try to validate such a file with such monstrous constructions.

<LISTING> is meant to be just like <XMP> except of course for its narrower font size. In fact, it is supposed to be capable of fitting 132 characters within the same screen width as <XMP> fits 80 characters. This is a carryover from some of the most ancient line-mode user agents which ran on vt100-compatible terminals. Per the vt100 standard, it normally displays up to 80 characters across its screen width, but with a special "escape sequence" (called such because it begins with the <ESC> key code, as is entered using that key on the terminal keyboard) that puts it in a special 132 column display format. This way, if the text material is wider than 80 columns (up to 132), it will all display correctly. Otherwise either it wraps around, creating alternate lines on the screen (very ugly), or else it crops off everything to the right of the 80th column.

One should be able to deduce from this why it is that <XMP> has its 132 column version (<LISTING>) while <PLAINTEXT> does not. With <PLAINTEXT> you don't normally have a closing tag, and so if you had a hypothetical <PLAINTEXT-132> tag which set the screen to the 132 column wide mode, it would end up leaving it in that mode. So, where the <LISTING> opening tag would cause the escape sequence to be sent which widens the screen, the </LISTING> tag at the end would cause the opposite escape sequence to be sent so as to ensure that the terminal is set back to normal when display is concluded.

As it happens in font sizes available today however, it seldom works out to that exact 80 to 132 ratio. In fact what one may get is simply the next smaller font size, which might fit a little over 100 characters within the same width as <XMP> would fit 80. Furthermore, because they are smaller, they are also shorter, and not merely narrower, where they were only narrower on the vt100 and compatible display devices.

One other thing to know is that many popular user agents, through a mistake or bug in their program (and one they certainly won't care enough to fix), actually treat <LISTING> as though it were a reduced font <PRE> statement, thus honoring at least some of the elements and entities found therein as it is not supposed to do, and some don't even bother reducing the font size or even enlarge it! I enclose here a small test for one to find out about their own user agent. Each of the following line groups is the same, except for the fact that the <XMP> one only counts out 80 characters and the <LISTING> one counts out to 132 characters. First comes the <XMP> version:

12345678901234567890123456789012345678901234567890123456789012345678901234567890 <!-- Can you see this comment? -- -- Or this one? --> Is &amp; one character or 5? Do you see the INPUT <INPUT NAME="a1">

And here comes the <LISTING> version:

123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012 Is & one character or 5? Do you see the INPUT

Upgrades and Downgrades

I have created a small cluster of demonstration files to show the various upgrades possible as replacements for the <XMP> and <LISTING> elements contained in this <LISTING> demonstration file and this <XMP> demonstration file, showing a list of alternatives to using these elements.

Possible downgrades are:

Possible upgrades are:

This file, "listin.html," is HTML 2.0 Level 1 compliant.
The <LISTING> demonstration file "listind1.html" is HTML 2.0 Level 1 compliant.
The <XMP> demonstration file "listind2.html" is HTML 2.0 Level 1 compliant.
The <PRE> demonstration file "listind3.html" is HTML 2.0 Strict Level 1 compliant.
The <PRE WIDTH="132"> demonstration file "listind4.html" is HTML 2.0 Strict Level 1 compliant.
The <BASEFONT> demonstration file "listind5.html" is HTML 3.2 compliant.
The <FONT> demonstration file "listind7.html" is not any kind of HTML compliant.
The <PRE STYLE="font-size: 62%"> demonstration file "listind6.html" is HTML 4.01 Strict compliant.
The SGML Failure Mode demonstration file "listind8.html" is not any kind of HTML compliant.


Next Level Up