The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Custom XML tags in XHTML

This afternoon I came across some text that needed to be formatted and it contained the name of a ship. I remembered reading something on a mailing list about what tag to use for ship names, but couldn't remember. So I went on a hunt for it and ended up with no concrete answer, despite the fairly large amount of discussion I found over something seemingly trivial.

Not satisfied with any one answer, I added <shipname> tags around it and styled it. I served the page as application/xhtml+xml and Firefox didn't complain and displayed it with the styling I'd given it. The validator whined about it. But it also seems to think I'm serving text/html for some reason. I'm not serving that, I checked.

Is this acceptable in theory? I would think yes, since it's "xhtml + xml", I can put whatever I want in there.

Not satisfied with any one answer, I added <shipname> tags around it and styled it.

Is this acceptable in theory? I would think yes, since it's "xhtml + xml", I can put whatever I want in there.

No it isn't. The xhtml DTD you are using specifies an XML language with a specified set of tags and <shipname> is not among them. Period. Semantic structures that will reflect the meaning you intend are surely available in xhtml, so use it.

No, you're not allowed to put whatever you want in your XHTML files. In particular, you're not free to make up element names and use them in the XHTML namespace. Using a custom DTD doesn't help; being DTD valid is next to meaningless, especially if you use your own DTD.

What you can do is using your own namespace for your custom elements. It still won't be valid XHTML but it is "allowed".

I added <shipname> tags around it and styled it. I served the page as application/xhtml+xml and Firefox didn't complain and displayed it with the styling I'd given it. The validator whined about it.

As it should, because your document is no longer valid XHTML. Firefox won't complain, because it doesn't use a validating XML parser. It will apply styling, but that's as far as it goes; it won't 'understand' the <shipname> tag.

That's the problem with the extensibility aspect of XHTML: there is no way to define semantics. You can't just add new elements in your own namespace, because they won't mean anything to anyone. You'll have to write browser plug-ins for that, as has been done for, e.g., MathML.

Originally Posted by Raffles

But it also seems to think I'm serving text/html for some reason. I'm not serving that, I checked.

If the validator says to do, you probably do. It's easy to verify with Opera: use the Info panel, or just hold the mouse cursor over the tab in Opera9 and it will tell you what Content-Type header your server sent. Firefox can show the same information in the Page Info dialog.

Originally Posted by Raffles

Is this acceptable in theory? I would think yes, since it's "xhtml + xml", I can put whatever I want in there.

No, because you cannot specify what 'whatever' means. It's pointless. If you're only doing it for styling then <i>Titanic</i> is better than <shipname>Titanic</shipname> because it's valid XHTML and browsers understand it. You're only adhering to a typographic convention, after all. If you need to indicate that it is a ship name (e.g., for some script processing) then <i&#160;class="ship">Titanic</i> should suffice.

This is why the B and I element types are not deprecated in Strict doctypes, despite being presentational. There are typographic conventions that say, e.g., that boat names should be italicised. X/HTML has specific element types for some of these conventions (DFN, EM, STRONG, VAR) but not for all. For the rest we will have to make do with B and I.

Besides, XHTML is XML all in itself. That allows you to mix in elements from other namespaces (like MathML or SVG) but you cannot extend the XHTML namespace.

it's just that I was giving anything that isn't FF, Opera or Safari text/html. Stupid.

Yes, that can be a problem when using content negotiation. I've included a URI switch – adding ?xml=yes for XML or ?xml=no for HTML – on my blog, so that I can run either version through the validator. Others choose to include the validator's UA signature in their content negotiation script, so that they always send the XHTML version for validation.