Coding in XHTML

HomeSite makes it easy to code in XHTML. You can set XHTML-specific options, use coding tools that all support the XHTML 1.0 specification, reformat your code using a Code Sweeper or HTML Tidy, and validate against the XHTML 1.0 specification, all without leaving HomeSite.

You can also use the W3C XHTML validator sites for Web-based files or local files.

The rest of this section briefly defines XHTML, describes XHTML-specific options that you can set, and explains how to work in an XHTML document.

What is XHTML?

XHTML (Extensible Hypertext Markup Language) is a reformulation of HTML as an XML application. It is almost identical to HTML 4.01, but it is more strict and clean.

XHTML is designed to replace HTML. It works on most existing HTML browsers as well as on XML systems, so you can switch to XML without excluding anyone or waiting for XML-based browsers to become more prevalent. Because XHTML is so similar to HTML, it is not difficult to switch from HTML to XHTML.

For more information, see the W3C specification for XHTML 1.1 - Module-Based XHTML or XHTML 1.0. You can also search tutorialfind for XHTML. Other good resources are Beginning XHTML, published 2000 by Wrox Press, and Welcome to XHTML School.

Setting options for XHTML

This section has instructions for setting options that are optimal for XHTML coding.

For more information about these options and other language options that are not specific to XHTML, see "Setting Options for Markup Languages".

To set XHTML language options:

  1. Open the Options > Settings > Markup Languages pane.
  2. Make sure that the following options are selected: Lowercase all inserted tags, Include closing </p> when inserting paragraph tag, Insert numeric values surrounded by quotes (Tag Inspector), and Minimize empty tags (e.g., <br/>).
  3. In the Insert special characters as box, select Character entities.

    (Numeric references need to have the ampersand encoded; for example &#38;#38; instead of just &#38;.)

  4. Under the Markup Languages pane, in the HTML/XHTML pane, select Compatibility mode for older browsers (e.g., space before "/>").

    This ensures that your code displays properly in older browsers, for example by inserting a space before minimized empty tags (<br /> instead of <br/>).

  5. Select Display DTD selection dialog when the XHTML namespace is specified if, when you select Options > Set Document as XHTML, you want to be able to choose between inserting the DOCTYPE declaration for the XHTML Strict, Frameset, or Transitional DTD, or not inserting/replacing a DOCTYPE declaration. The dialog box that appears has options to Always replace with this DTD or Don't ask me again, in case you do not want it to appear again.

    If you clear this option, when you set a document as XHTML, no dialog box appears and no DOCTYPE declaration is inserted or replaced.

  6. Click Apply.

You can also set color coding for XHTML, validate against the XHTML 1.0 Strict specification, and specify the priority of XHTML in the Tag Definitions Library. For details, see "Using Color Coding Schemes", "Validating Code", and "Working with Tag Definitions".

Enabling XHTML support in a document

This section describes how to enable XHTML support for a document. Once the program recognizes a document as XHTML, it displays XHTML Tag Editors, and the attribute table and completion options in Tag Inspector and Tag Insight are appropriate for XHTML.

To validate against the XHTML 1.0 specification, see "Validating Code".

To automatically enable XHTML support, do one of the following:

To manually enable XHTML support:

  1. Select Options > Set Document as XHTML for the current document.

    This will have no effect if the current document is read-only.

  2. If Options > Settings > Markup Languages > XHTML/HTML > Display DTD selection dialog when the XHTML namespace is specified is selected, a dialog box appears. Select the DOCTYPE declaration for the DTD that you will use (there are three versions of the XHTML 1.0 specification).

    Select No replacement if you do not want to change or add a DOCTYPE declaration, for example if you are writing XHTML code to include in another page that already has its own DOCTYPE declaration.

  3. If you do not want the dialog box to display again and you will always use the same DOCTYPE declaration, then select Always replace with this DTD.
  4. If you do not want to display this dialog box, and you never want to replace or insert a DOCTYPE declaration, then select Don't ask me again.
  5. Click OK.
  6. If you need to undo this, select Options > Set Document as XHTML again with the XHTML document as the current document in the editor. In the Confirm dialog box, click Yes.

Comments