Validating Code

You can use the HomeSite validator, or integrate the CSE HTML validator to work within HomeSite.

Using the default validator

You can use the HomeSite validator to check and report syntax errors in HTML (including different browser extensions), XHTML, CFML, JSP, SMIL, and WML.

Configuring the validator

There are a myriad of configuration options from which you can choose. This section contains a general procedure for configuring the validator, some procedures for setting specific options, and an example.


Note

If you validate both CFML and HTML in a single document, the validator cannot assess the pound sign (#). This is because, in CFML, the single pound is an error and the double pound is correct; while in HTML, the double pound is an error and the single pound is correct.


To configure the validator:

  1. Open the Options > Settings > Validation pane.
  2. Select the tag sets against which to validate.

    Some tag sets are built on top of other tag sets. For example, if you select HTML 4.0, HTML 3.2 and HTML 2.0 are automatically selected as well, because the definition for HTML 4.0 is incomplete without them.

  3. Click Validator Settings.
  4. In the Validator Configuration dialog box, complete the Options tab as needed:
  5. If you need to validate something beyond the scope of the specifications selected in the Options > Settings Validation pane, use the other tabs in this dialog box.

    Following is a description of what you can do on each tab:


    Caution

    The changes you make on these tabs take effect immediately and cannot be undone, even if you click Cancel. Be especially careful with the Remove buttons.


  6. Click OK.
  7. Back in the Settings dialog box, click Apply.

To require an attribute for a tag:

  1. Open Options > Settings > Validation and click the Validator Settings button.
  2. In the Validator Configuration dialog box, click the Tags tab.
  3. Expand a set of tags, for example HTML 4.0.
  4. Expand a tag in the list.
  5. Select the tag's Required folder and click Add.
  6. In the Required Attribute dialog box, type the name of an existing attribute and click OK.

    If the attribute is not in the Attribute folder, add it to the Attribute folder and then add it to the Required Attributes folder.

  7. To remove a required attribute, select the attribute in the Required folder and click Remove.
  8. If you are done setting validator options, click OK.
  9. Back in the Settings dialog box, click Apply.

Example: Validating against the HTML 4.0 specification

  1. In the Options > Settings > Validation pane, select HTML 4.0.
  2. Click Validator Settings.
  3. In the Validator Configuration dialog box, on the Options tab, in the Report box, select every type of error except CFML Compiler Errors.
  4. In the Other box, select the options to check for quotes in text and report special characters.

    Checking for quotes ensures that each quotation mark is followed by another of the same type (' or "). Reporting special characters catches errors like having "&" in the HTML as opposed to "&".

  5. On the Tags tab, expand the HTML 4.0 node and select the noframes node.
  6. In the Tag Options box, select Required in document and click Apply Options.
  7. Expand the img node, select the Attributes folder and click Add.
  8. In the New Attribute dialog box, type alt and click OK.
  9. Select the Required folder, and click Add.
  10. In the Add Required Attribute dialog box, type alt and click OK.

    The Versions tab is for if I need to extend the tag sets against which I can validate, and the Values tab is for validating regular expressions. These are unnecessary for a standard HTML 4.0 document, so this configuration is complete.

  11. Click OK.
  12. Back in the Settings dialog box, click Apply.

Running the validator

You can run the validator for the current document or for a selected tag.

Validating a tag only checks the contents of the specific tag. For example, it does not check if a tag has an end tag or if the tag is in the wrong place in the document.


Note

If you validate both CFML and HTML in a single document, the validator cannot assess the pound sign (#). This is because, in CFML, the single pound is an error and the double pound is correct; while in HTML, the double pound is an error and the single pound is correct.


To validate the current document:

  1. Select Tools > Validate Current Document.

    The Validation Results pane displays a "No errors or warnings" message or lists the syntax errors that it found.

  2. Double-click an error message to highlight it in the document.

To validate the contents of a single tag, do one of the following:

If something is wrong in the tag, an error message appears in red in the status bar.

Using the CSE HTML Validator

If you have installed this HTML validation tool, you can run it from HomeSite. The CSE Validator supports multiple languages and contains other useful features.

For more information, open the Options > Settings >Validation pane and click the CSE HTML Validator link to visit their Web site.

To use the CSE HTML Validator:

  1. In the Options > Settings > Validation pane, select Use CSE HTML Validator when validating the entire document.
  2. Click Configure CSE.
  3. Complete the CSE HTML Validator Pro Configuration Editor dialog box.

    For a description of each field on a tab, click the Help button.

  4. Click CSE Options.
  5. Complete the Validator Engine Options (Validator/Logging/Tools/Network) dialog box.

    For a description of each field on a tab, click the Help button.

  6. (Optional) To visit their Web site, click the CSE HTML Validator link.
  7. When you are done, click Apply.

Comments