Differences Between XHTML and HTML

As you know, XML is more particular about many aspects of writing documents than HTML is. For example, you need to place all attribute values in quotation marks in XML, although HTML documents can use unquoted values because HTML browsers will accept that. One of the problems the W3C is trying to solve with XHTML, in fact, is the thicket of nonstandard HTML that's out there on the Web, mostly because browsers support it. Some observers estimate that half of the code in browsers is there to handle nonstandard use of HTML, and that discourages any but the largest companies from creating HTML browsers. XHTML is supposed to be different: If a document isn't in perfect XHTML, the browser is supposed to quit loading it and display an error, not guess what the document author was trying to do. Hopefully, that'll make it easier to write XHTML browsers.

Here are some of the major differences between HTML and XHTML:

  • XHTML documents must be well- formed XML documents.

  • Element and attribute names must be in lowercase.

  • Non-empty elements need end tags; end tags can't be omitted as they can sometimes in HTML.

  • Attribute values must always be quoted.

  • You cannot use "standalone" attributes that are not assigned values. If need be, assign a dummy value to an attribute, as in action = "action" .

  • Empty elements must end with the /> characters . In practice, this does not seem to be a problem for the major browsers, which is a lucky thing for XHTML because it's definitely not standard HTML.

  • The < a> element cannot contain other < a> elements.

  • The < pre> element cannot contain the < img> , < object> , < big> , < small> , < sub> , or < sup> elements.

  • The < button> element cannot contain the < input> , < select> , < textarea> , < label> , < button> , < form> , < fieldset > , < iframe> , or < isindex> elements.

  • The < label> element cannot contain other < label> elements.

  • The < form> element cannot contain other < form> elements.

  • You must use the id attribute and not the name attribute, even for elements that have also had a name attribute. In XHTML 1.0, the name attribute of the <a> , <applet> , <form> , <frame> , <iframe> , <img> , and <map> elements is formally deprecated. In practice, this is a little difficult in browsers such as Netscape Navigator, which support name and not id ; in that case, you should both attributes in the same element (even though it's not legal XHTML).

  • You must escape sensitive characters. For example, when an attribute value contains an ampersand ( & ), the ampersand must be expressed as a character entity reference, as &amp; .

As we'll see in the next chapter, there are some additional requirements. For example, if you use the < character in your scripts, you should either escape it as &lt; or, if the browser can't handle that, place the script in an external file (the W3C's suggestion of placing scripts in CDATA sections is definitely not understood by any major browser today).



Real World XML
Real World XML (2nd Edition)
ISBN: 0735712867
EAN: 2147483647
Year: 2005
Pages: 440
Authors: Steve Holzner

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net