View Full Version : Cant understand the role of DTDs

12-26-2005, 05:14 PM
I am a complete newbie to XML. I just finished the DTD part. At first, I thought that going against a specified DTD in an XML document would give an error (like providing an element in an XML document which is not in the DTD or providing a value for an attribute in the XML markup other than the possible values specified in the DTD). But then some1 told me that it wont. And now I'm all confused. Why are DTDs there if someone can just give well-formed markup and go against the DTDs and get his XML markup to work just fine.

12-26-2005, 06:17 PM
Think of it like this:

You have well-formedness, and you have validity. If you are well-formed, any XML parser can read the document. If you are valid (via DTD, Schema, RelaxNG, whatever), then application-specific parsers can read the document.

You can get away with invalid XHTML in, say Firefox, because Firefox uses a non-validating parser. If you break the DTD, its error handling will take care of it. MSXML, however, is validating (though not terribly great at it). Try using an XHTML 1.1 doctype in IE with a page sent as XML -- it will throw a DTD error and not even render the document tree. So, whomever told you being invalid didn't matter only told you a partial truth.

12-26-2005, 06:25 PM
thanks u cleared my doubts