Jump to content

Doubts About Dtd


tecnitek
 Share

Recommended Posts

Hi,I've been studying HTML & XHTML recently. But I tried to focus on HTML & XHTML DTD. When we use the :<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'>http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> in theory I'm telling the browser where to go (http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd) to get the dtd, and contrast de document against it. This combined with the xml version tag and namespace (xmlns):<?xml version="1.0" encoding="UTF-8"?><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">would let us construct strict xhtml. But instead of this, I wrote this code, and even with the errors you can find ( no body tag or no head tag contained), the browser is able to print de message in the right style:<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'>http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><h1>Hello World</h1></html>Why if the xhtml dtd tells us clearly that html tag must contain a head and a body tag, no error message occurs when this code is read by the popular browsers?Thanks in advance.P.D:Sorry for my bad english. I'm newbie in the HTML & XHTML world.

Link to comment
Share on other sites

The error messages would only appear if there were XML errors on your page, like mismatched tags or entities that aren't closed.Only the validator will tell your if your page is right or wrong.

Link to comment
Share on other sites

The code is well-formed (what proper XML parsers check for), but it isn't valid (what a validator like the W3's will tell you). Also, by the way, unless you give your document the application/xhtml+xml MIME type, browsers will actually just read your document as HTML, regardless of the DTD.

Link to comment
Share on other sites

Thanks!I understand the difference between "xml well-formed" and "xhtml valid". But there's a way to modify the dtd and tell the browser to contrast the html or xhtml page against our personal dtd? I think this could be useful to create new elements or attributes. Maybe with the application/xhtml+xml MIME type ... but I don't understand how it works ...Thanks in advance.

Link to comment
Share on other sites

In theory, what you say about the DTD is correct. In practice, not really. Browsers don't download the DTD, and do validation against it. Not on HTML and (AFAIK) XHTML documents at least (again AFAIK, they have a "hard cache" where they keep the DTD, and use that instead of the official URL). In XML they do download it and validate against it, but at that point, you realize why they don't do it (hint: performance).Only validators always open the DTD and validate against it.You can indeed point to another DTD of your own instead of the offical one, and thus present your own elements and/or attributes as valid. Note however that the browser still won't know how to render your elements and attrbutes. You'll have to specify their behaviour yourself with JavaScript or something else, in turn (almost) killing the point of creating them.The MIME type is yet another kind of a switch. It's a trigger for a separate XHTML mode in browsers, where there are some differences in CSS and JavaScript rules (it's supposed to be "cleaner" and all that), but it's not supposed in IE (any version, up to and including 8). It's the mode where your XHTML code must validate against a DTD, or not have a DTD at all (in which case the browser may default to any version of XHTML; and even then your code must be well formed).It's also the mode which holds other great potentials, which are currently not explited by browsers. Namely, the ability to validate by Schema instead of DTD, and since the use of schema, allow elements from other namespaces to be directly mixed within the XHTML document (e.g. SVG, MathML, XForms, etc.). I'm guessing browser vendors prefer not to exploit it in favor of having a standard DTD along with a specification that specifies how should the various components interact because they want to get consistent behaviour with mixtures. This is proven so by the existance of the XHTML+SVG+MathML DTD, and the fact that XHTML 2 includes XForms directly in its grammar.You can set the MIME type on the server by various means, depending on what you have. For example, in PHP, you can do it like so:

<?php header('Content-Type: application/xhtml+xml'); ?>

Plugging this at the very top of your PHP file (and making the rest of the file as a regular, valid XHTML file) will make PHP output XHTML.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...