Forum Moderators: open
I want to use the XMP tag but have heard that it is depreciated and sometimes wont even render in browsers.
I have searched on Google for an equivalent but all I seem to get are instructions to use <pre> which is not anything like the XMP tag!
Well, it is similar... but I need HTML to display inside the tag (whatever it might be) - <pre> renders the HTML!
I have also been told <samp> - but this also renders HTML as HTML.
There must be a way, I just cant find it.
Cheers
<xmp> directly without parsing as you require - but the problem is that Opera doesn't support <xmp> in this manner. Strictly speaking, Opera can do this because the specification does not explicitly specify this behaviour. For that reason, the best course of action is to avoid
<xmp> and use <pre> instead, but replacing < with < and > with > in the sample markup. It's certainly longer to do, but is safer.
<pre>
<table cellpadding="0" cellspacing="2">
<tr>
<td>
this is a table
</td>
</tr>
</table></pre>
However, the problem still remains that you can't be sure of the behaviour of
xmp cross-browser. I tried it in my favorite obscure browser [dillo.org] and xmp code blocks still get parsed there. I don't know how Googlebot, for example, sees it either (you could check the cache of a page with example code). It's your call whether the browser support is sufficient for you to use the tag - but I would ensure that the markup enclosed within the
xmp block won't completely break the layout if it gets rendered by the browser. Personally, I would favor the
pre tag approach I mentioned in my previous answer.
I think the pre tag should have an attribute to toggle the rendering of HTML code (i.e turns < into <)
Nevermind.. just means I have to do this:
<pre>
<?
print htmlspecialchars($code);
?>
</pre>
Where $code holds your HTML.
Only disadvantage is you need php installed and more than likely will need ".php" extensions on your pages.
long live the XMP tag!
I just checked the HTML 3.2 Specs [w3c.org] and they say this (my bold):
XMP, LISTING and PLAINTEXT%HTML.Deprecated [
<!ENTITY % literal "CDATA"
-- historical, non-conforming parsing mode where
the only markup signal is the end tag
in full
--><!ELEMENT (XMP¦LISTING) - - %literal>
<!ELEMENT PLAINTEXT - O %literal>]]>
These are obsolete tags for preformatted text that predate the introduction of PRE. User agents may support these for backwards compatibility. Authors should avoid using them in new documents!
A pity!
However,
xmp was deprecated in HTML 3.2, and is completely absent from HTML 4 - so if you are building pages with HTML 4 notation (it's hard not to these days) then you are asking for problems. The inconsistent browser handling of the tag is due to this obselesence and the lack of clarity of the original spec (where's my copy of the HTML 2.0 spec when I need it?!). long live the XMP tag!
Yeah, it was cool - or rather the popular browser implementation was. Unfortunately, it's dead, and we're back to
<pre>. If anyone out there is doing testing, the W3 validator is buggy when parsing
xmp with respect to closing tags of elements within the xmp block. It does validate (using a 3.2 doctype) if you take that into account, but it goes to show that using the tag can cause more problems than it solves!