SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    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.

  2. #2
    SitePoint Evangelist Ed Seedhouse's Avatar
    Join Date
    Aug 2006
    Location
    Victoria, B.C. Canada
    Posts
    592
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Raffles View Post
    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.

    Or make up your own dialect of XML and create your own DTD for it.
    Ed Seedhouse

  3. #3
    bronze trophy
    Join Date
    Dec 2004
    Location
    Sweden
    Posts
    2,670
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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".

    However, personally I'd probably use <i> to mark up ship names.
    Simon Pieters

  4. #4
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Interesting, thanks for the replies. It was only for experimentation.

    Yes, I think <i> is probably best too, since ship names are supposed to be written in italic text and not said with emphasis or anything like that (<em> would be less appropriate).

  5. #5
    In memoriam gold trophysilver trophybronze trophy Dan Schulz's Avatar
    Join Date
    May 2006
    Location
    Aurora, Illinois
    Posts
    15,476
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yep, <i></i> is perfect for this. IIRC, AutisticCuckoo mentioned this in a previous post here on the forums.

  6. #6
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Raffles View Post
    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.

    Quote Originally Posted by Raffles View Post
    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.

    Quote Originally Posted by Raffles View Post
    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.
    Birnam wood is come to Dunsinane

  7. #7
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AutisticCuckoo
    you cannot extend the XHTML namespace.
    The key to it all, I get it now. As for what I was serving, the validator was right, but so was Firefox - it's just that I was giving anything that isn't FF, Opera or Safari text/html. Stupid.

    Thanks for the very informative reply.

  8. #8
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Raffles View Post
    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.
    Birnam wood is come to Dunsinane

  9. #9
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I added the validator's UA string to my script.

    Incidentally, since you stopped blogging, have you ever felt the urge to start again?

  10. #10
    Robert Wellock silver trophybronze trophy xhtmlcoder's Avatar
    Join Date
    Apr 2002
    Location
    A Maze of Twisty Little Passages
    Posts
    6,316
    Mentioned
    60 Post(s)
    Tagged
    0 Thread(s)
    You may also want to consider cite.

    Yes he (Tommy) has had the urge…

  11. #11
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Cite was mentioned in some of the discussions I found but I don't agree with it. I think <i> is more fitting, ship names don't seem too much like citations to me.

  12. #12
    In memoriam gold trophysilver trophybronze trophy Dan Schulz's Avatar
    Join Date
    May 2006
    Location
    Aurora, Illinois
    Posts
    15,476
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's because they're not.

  13. #13
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Off Topic:

    Quote Originally Posted by Raffles View Post
    Incidentally, since you stopped blogging, have you ever felt the urge to start again?
    Occasionally. But it will require a complete rewrite of my blogging software and that's going to take some time.


    Quote Originally Posted by xhtmlcoder View Post
    You may also want to consider cite.
    Certainly, but not for this!
    CITE marks up a citation; a reference to a source you are quoting – either directly via BLOCKQUOTE or Q, or indirectly via paraphrasing.

    Unless the ship has said something or written something, it's not appropriate to use CITE.
    Birnam wood is come to Dunsinane

  14. #14
    Robert Wellock silver trophybronze trophy xhtmlcoder's Avatar
    Join Date
    Apr 2002
    Location
    A Maze of Twisty Little Passages
    Posts
    6,316
    Mentioned
    60 Post(s)
    Tagged
    0 Thread(s)
    Yes, but you might be referencing her, and her name and actions. Regalskeppet Vasa


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •