Working with XHTML Creating a Well-Formed Valid Document.

26
Working with XHTML Creating a Well-Formed Valid Document

Transcript of Working with XHTML Creating a Well-Formed Valid Document.

Page 1: Working with XHTML Creating a Well-Formed Valid Document.

Working with XHTML

Creating a Well-Formed Valid Document

Page 2: Working with XHTML Creating a Well-Formed Valid Document.

Introducing XHTML

• SGML (Standard Generalized Markup Language) – can be used with almost any type of document stored

in almost any format

– Introduced in the 1980s

– Metalanguage– used to created other languages

• HTML– standards get confusing among browsers

– can be applied inconsistently

Page 3: Working with XHTML Creating a Well-Formed Valid Document.

Introducing XHTML

• XML (Extensible Markup Language) – used to design markup languages

• XML documents must be evaluated with an XML parser

• An XML document with correct syntax is a well-formed document

• A well-formed document with correct content and structure is a valid document

• DTD specifies correct content and structure

Page 4: Working with XHTML Creating a Well-Formed Valid Document.

Introducing XHTML

• XHTML is an application of HTML, written in XML

Page 5: Working with XHTML Creating a Well-Formed Valid Document.

DTDs associated with XHTML 1.0

- transitional: supports many of the presentational features of HTML, including the deprecated elements and attributes Best used for older documents that contain deprecated features

Page 6: Working with XHTML Creating a Well-Formed Valid Document.

DTDs associated with XHTML 1.0

- frameset: used for documents containing frames, and also supports deprecated elements and attributes

Page 7: Working with XHTML Creating a Well-Formed Valid Document.

DTDs associated with XHTML 1.0

- strict: does not allow any presentational features or deprecated HTML elements and attributes. Does not support frames or inline frames. It is best used for documents that need to strictly conform to the latest standards.

Page 8: Working with XHTML Creating a Well-Formed Valid Document.

Creating a Well-Formed Document

Rules for well-formed XHTML documents

Page 9: Working with XHTML Creating a Well-Formed Valid Document.

Creating a Well-Formed Document

• XHTML documents must also include a single root element that contains all other elements– For XHTML, that root element is the html element

• Attribute minimization is when some attributes lack attribute values– XHTML doesn’t allow attribute minimization

Page 10: Working with XHTML Creating a Well-Formed Valid Document.

Attribute minimization in HTML and XHTML

Page 11: Working with XHTML Creating a Well-Formed Valid Document.

Creating a Valid Document

• The DTD used depends on the content of the document and the needs of your users

• To support old browsers, use the transitional DTD

• To support old browsers in a framed Web site, use the frameset DTD

• To support more current browsers and want to weed out any use of deprecated features, use the strict DTD

Page 12: Working with XHTML Creating a Well-Formed Valid Document.

Creating a Valid Document

• Elements not allowed under the strict DTD:– applet - isindex

– basefont - menu

– center - s

– dir - strike

– font - u

– iframe

Page 13: Working with XHTML Creating a Well-Formed Valid Document.

Creating a Valid Document

• Some attributes are restricted, while others are required in XHTML

Page 14: Working with XHTML Creating a Well-Formed Valid Document.

Attributes prohibited in the strict DTD

Page 15: Working with XHTML Creating a Well-Formed Valid Document.

Attributes prohibited in the strict DTD

Element Attribute

Page 16: Working with XHTML Creating a Well-Formed Valid Document.

Required XHTML attributes

Page 17: Working with XHTML Creating a Well-Formed Valid Document.

Creating an XHTML Document

• The first line of an XTHML document should contain a declaration indicating that the document adheres to the rules and syntax of XML

• XML (and thus XHTML) documents are based on a character set– A character set is a set of abstract symbols

matched to code numbers

Page 18: Working with XHTML Creating a Well-Formed Valid Document.

Adding an xml Declaration

• For XHTML documents, use the declaration:

<?xml version=“1.0” encoding=“UTF-8” standalone=“no” ?>

Page 19: Working with XHTML Creating a Well-Formed Valid Document.

The XML Declaration

Page 20: Working with XHTML Creating a Well-Formed Valid Document.

Setting the XHTML Namespace

• To set XHTML as the default namespace for a document, add the xmlns attribute to the html element with the following value:

<html xmlns=http://www.w3.org/1999/xhtml>

Page 21: Working with XHTML Creating a Well-Formed Valid Document.

Testing an XHTML Document

• To test your document, you need to send the file to an XML parser or an XHTML validator

• Sometimes the same mistake results in several errors are noted in the report

- fixing one mistake can solve several errors

Page 22: Working with XHTML Creating a Well-Formed Valid Document.

Strict XHTML Document

• You’ll need the following DOCTYPE declaration

Page 23: Working with XHTML Creating a Well-Formed Valid Document.

Tips for Converting old HTML Code to XHTML

• Include an xml declaration in the first line of your file so that your document can be accessed by XML parsers

•Add a DOCTYPE declaration for one of the XHTML DTDs and check your document for well-formedness and validity whenever you make a change to the code

•Add the XHTML default namespace to the html element of your document

Page 24: Working with XHTML Creating a Well-Formed Valid Document.

Tips for Converting old HTML Code to XHTML

• Make sure that all element and attribute names are in lowercase letters and that all attribute values are placed in quotes

•Make sure that all empty elements are entered as one-sided tags. Look especially for improper syntax in the img, hr, and br elements

•Make sure that all two-sided tags are properly closed. Old HTML code often does not have closing tags for the p element

Page 25: Working with XHTML Creating a Well-Formed Valid Document.

Tips for Converting old HTML Code to XHTML

• Make sure that all inline images contain the alt attribute

•Look for deprecated attributes such as align, bgcolor, and background, and replace them with the float (or text-align), background-color, and background-image styles

•Replace the name attribute with the id attribute

•Fix all instances of attribute minimization

Page 26: Working with XHTML Creating a Well-Formed Valid Document.

Tips for Converting old HTML Code to XHTML

• Replace the use of the font element with either the span element or with a style that applies the same formatting specified by the font element

•Replace the use of the width attribute in the td or th element with the width style