开发者

Is XHTML really Xtensible?

开发者 https://www.devze.com 2023-01-28 01:14 出处:网络
Is there any way (server- or client-side) that I can actually extend HTML to include new tags?For example, it would be cool if I could write something like a schema fragment that defined a blogpost, w

Is there any way (server- or client-side) that I can actually extend HTML to include new tags? For example, it would be cool if I could write something like a schema fragment that defined a blogpost, which contains a postname, a postauthor, a posttime, and a postcontent, and thereafter refe开发者_如何学Gor to blogpost in my HTML rather than resorting to the basic HTML div and p tags.


Sounds like HTML5 is right up your alley!

You can use elements like section to wrap up all your posts, and article for each post, plus basics like header, nav, and footer. There isn't fine grained elements like postauthor or posttime but you can provide other attributes to help define these.

Hmm, seems I spoke to soon, you can use this too:

<time pubdate datetime="2010-11-13T20:00+09:00">Posted Nov 13.</time>


That would be awesome. Here is an article explaining why it won't work. Basically, you can extend the markup. But HTML browsers won't know how to interpret your new tags.


For the general web developer, no. You'd need to write your own DTD to have your own tags, and even then, it really will not benefit you semantically for anything other than your own sanity.

Also, some browsers ahem IE will not know how to handle your custom tags, and you'll have to resort to JavaScript to teach it. Not really recommended...


While the browser won't readily understand extensions based on the XML-derived extensibility, that doesn't mean people aren't working on this problem.

HTML5 additions like <section> aside, the best solution for what you're trying to do is probably microformats. In the case of your blog example, hAtom.

Then you get something that browsers understand, but can be progressively enhanced as more systems support hAtom and you can style entries using class references like .hentry, .entry-title, and .author.


You can add custom tags to the DOM tree. You won't get valid XHTML, but browsers will understand those tags as long as you style them correctly.

A very interesting project making use of this browser behavior is WebODF, a tool for bringing ODF documents to the browser. Check out the video on the site and the live demo to get some understanding how this works.


You can add custom tags by mixing XHTML with your custom language. The language is no longer XHTML but a compound language including XHTML, but that was always the intent of XHTML anyway.

You will, however need to use XHTML properly, and serve it with an XML mime type, such as application/xhtml+xml, which means no IE support before IE9.

You can see an example using blogpost, postname, postauthor etc here:

http://www.alohci.net/application/xhtml+xml/custom1.xhtml.ashx

(Works in Firefox, Chrome, Safari, Opera and IE9)


[Of course, you can just put invalid tags into HTML and style them, but to me, that doesn't seem to me to be the point of question, which was specifically about the extensibility nature of XHTML.]

0

精彩评论

暂无评论...
验证码 换一张
取 消