CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Jeffrey Palermo (.com)

Blog moved to www.jeffreypalermo.com

XHtml DocType or DTD - level 200

Especially as we move to ASP.NET 2.0, it's important to use an XHtml DocType or DTD.  ASP.NET 2.0 server controls will render valid XHtml transitional markup, so that's the most compelling Doctype, and that's the one I prefer, but pick one of the following:

  • XHtml 1.0 Transitional
    • <!DOCTYPE html
      PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  • XHtml 1.0 Frameset (if you need to use <iframe />
    • <!DOCTYPE html
      PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
  • XHtml 1.0 Strict
    • <!DOCTYPE html
      PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

The DocType needs to be the first line in the page; however, since XHtml is valid Xml, you can optionally add an Xml declaration at the top:

<?xml version="1.0"?>

And if you do this, the Xml declaration has to first, and then the DocType would come directly after.



Comments

Chris Wallace said:

You forgot XHTML 1.1

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
# July 29, 2005 12:23 PM

Jeffrey Palermo said:

I left that out because it's very difficult to get ASP.NET to emit valid Xhtml 1.1 as well as Xhtml 1.0, so I've settled on Xhtml 1.0 transitional.
# July 29, 2005 1:04 PM

Harris said:

Jeffrey,

I took a look at the DTDs and found that the XHTML Frameset DTD is not required if you need the IFRAME element. Frameset is specifically for FRAMESET and FRAME elements; it does include the IFRAME element as well.

XHTML Transitional defines the IFRAME element. XHTML 1 Strict does not.

Search <a rel="nofollow" target="_new" href="http://www.w3.org/TR/xhtml1/dtds.html">the DTDs</a> for IFRAME, FRAMESET, and FRAME elements and you should find the same.

If I'm wrong, please correct me.

Thanks,

Harris
# July 29, 2005 2:13 PM

Sam said:

I started out assuming XHTML was somehow better than HTML. Then resources like this: http://turnipspatch.com/archives/2005/05/31/xhtml-vs-html/ helped to enlighten me a bit (hopefully).

I've found that by sticking to HTML4.01 strict, cross-browser compatibility is improved, and since I never used namespacing anyways (do you? I haven't seen anyone who does in their XHTML), I lost *nothing*.

And that really appeals to the pragmatic programmer in me. If XHTML causes more work, has it's own quirks to work around between different broswers, and most importantly, offers me nothing in the way of advantages (come to find out I never was using the correct content-type anyways, so my XHTML wasn't XML), then why use it?

That's not to say specifying a DOC-TYPE isn't a Very Good Thing, and your message deserves a wider audience. But before jumping on the XHTML bandwagon, I think it can help to understand why or why not a certain DOC-TYPE might be appropriate for your development.
# July 30, 2005 2:11 PM

Sam said:

Sorry for the double-post, but are you saying that by including the XML declaration you can add XSLT processing directives for example? That would obviously be a pretty major advantage...

It's all a little hard for amatuers like myself to sort out. ;)
# July 30, 2005 2:15 PM

Chris Wallace said:

While it's true 1.x is difficult to make XHTMl compliant in any form, 2.0 emits XHTML 1.1 compliant code (mostly anyway) by default.
# July 31, 2005 8:17 PM

Jeffrey Palermo said:

Sam,
Yes, if you put an Xm declaration at the top, and your page meets Xml form specs, then it is Xml, and you can treat it as such.
# August 1, 2005 10:31 AM

Peter's Gekko said:

VS 2003, VS 2005, the datagrid and controlstate
I have built a lot of web application with Visual Studio...
# August 3, 2005 3:16 PM

Peter's Gekko said:

VS 2003, VS 2005, the datagrid and controlstate
I have built a lot of web application with Visual Studio...
# August 3, 2005 3:24 PM

Peter's Gekko said:

VS 2003, VS 2005, the datagrid and controlstate
The DataGrid with Visual Studio 2003 is a very nice...
# August 15, 2005 10:43 AM

Peter's Gekko said:

Author: &lt;a href=&quot;/blogs/peter.van.ooijen&quot;&gt;Peter Van Ooijen&lt;/a&gt;&lt;br /&gt;
The DataGrid with Visual Studio 2003 is a very nice control, however, when it comes to the viewstate and &quot;pushing your app through the wire&quot; it does have some serious drawbacks. Visual Studio 2005 does go a long way towards fixing these issues, but a better general approach to optimizing DataGrid performance is fighting viewstate size.
# August 22, 2005 11:16 AM

Peter's Gekko said:

Author: &lt;a href=&quot;/blogs/peter.van.ooijen&quot;&gt;Peter Van Ooijen&lt;/a&gt;&lt;br /&gt;
The DataGrid with Visual Studio 2003 is a very nice control, however, when it comes to the viewstate and &quot;pushing your app through the wire&quot; it does have some serious drawbacks. Visual Studio 2005 does go a long way towards fixing these issues, but a better general approach to optimizing DataGrid performance is fighting viewstate size.
# August 22, 2005 11:16 AM

About Jeffrey Palermo

Jeffrey Palermo is a software management consultant and the CTO of Headspring Systems in Austin, TX. Jeffrey specializes in Agile coaching and helps companies double the productivity of software teams. Jeffrey is an MCSD.Net , Microsoft MVP, Certified Scrummaster, Austin .Net User Group leader, AgileAustin board member, INETA speaker, INETA Membership Mentor, Christian, husband, father, motorcyclist, Eagle Scout, U.S. Army Veteran, and Texas A&M University graduate. Check out Devlicio.us!

This Blog

Syndication

News

Headspring Systems

View Jeffrey Palermo's profile on LinkedIn

See my new blog at .jeffreypalermo.com