Forum Moderators: open

Message Too Old, No Replies

XMP tag equivalent

Is there an equivalent to this tag

         

crookyboy

11:01 am on Aug 24, 2004 (gmt 0)

10+ Year Member



Hi,

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

encyclo

11:42 am on Aug 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I believe that in IE3-6, Netscape 3+ and Mozilla all show markup within
<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 &lt; and > with &gt; in the sample markup. It's certainly longer to do, but is safer.


<pre>
&lt;table cellpadding="0" cellspacing="2"&gt;
&lt;tr&gt;
&lt;td&gt;
this is a table
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;</pre>

bachius

2:30 pm on Aug 24, 2004 (gmt 0)

10+ Year Member



Opera has supported XMP since version 7.50

Hester

2:59 pm on Aug 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Wow, this works in Firefox 0.9 and IE6 too! Not sure it's safe to use it though - the code might be acted on. I doubt it's XML compatible either.

encyclo

3:14 pm on Aug 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks for the information, bachius - that's very useful to know.

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.

encyclo

3:19 pm on Aug 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I doubt it's XML compatible either

It is an old HTML 3.2 tag which was dropped completely from HTML 4.0. It will only validate if you're using an HTML 3.2 doctype.

crookyboy

3:20 pm on Aug 24, 2004 (gmt 0)

10+ Year Member



cheers.

I think the pre tag should have an attribute to toggle the rendering of HTML code (i.e turns < into &lt;)

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!

Hester

3:22 pm on Aug 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The W3Schools list of HTML tags says:
<xmp> Deprecated. Defines preformatted text. Use <pre> instead

crookyboy

3:26 pm on Aug 24, 2004 (gmt 0)

10+ Year Member



yes it does - but <pre> and <xmp> are not the same, as i said in my first post.

Hester

3:34 pm on Aug 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I know - the point is we shouldn't use XMP, no matter how useful it is, because it is deprecated.

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!

crookyboy

3:36 pm on Aug 24, 2004 (gmt 0)

10+ Year Member



I know we shouldn't use them, thats why I was asking for an equivalent or alternative tag.

Hester

3:53 pm on Aug 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's just that you said this:

long live the XMP tag!

So I thought you were planning to use it. Reading back on your other posts, I see that's not so. I agree such a tag would be very useful - it takes me ages to convert all my code examples!

encyclo

3:53 pm on Aug 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The problem is not just because it is deprecated: if you are using a transitional doctype and deprecated markup to support older browsers, your document can still validate and it is often the only approach to certain problems.

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!