XHTML formatter: what it does

This utility is intended for web developers who want to:

  • format a block of HTML, XHTML or XML showing correct indentation
  • ensure that the document is compliant with XHTML tag markup rules
  • check for errors in the markup

Why is it needed?
XHTML is the new standard which will eventually replace HTML. XHTML is basically well-formed HTML which improves performance and compatibility across browsers. HTML will eventually be phased out in favour of XHTML but old browsers will support the XHTML documents now.

For an excellent explanation of why we should all be developing to XHTML standards can be found on the w3schools site at http://www.w3schools.com/xhtml/xhtml_why.asp

There are some basic rules for tag markup within XHTML which most HTML documents do not obey. This utility automatically converts HTML documents so that these rules are followed.

After modifying your web pages, check them with the w3c validator at http://validator.w3.org

What changes does it make?
The XHTML formatter utility makes a number of automated changes to the document and reports on any errors found in the original script.

A full list of the changes is as follows:

For XHTML standard:

  • tag names and attribute names are all converted to lower case
  • attribute values are enclosed in quotes
  • all tags are closed, even when this was not required in HTML (e.g. img, br, hr). Where a tag is closed that can be closed automatically, e.g. (<img ...></img>) this is handled correctly.
  • an altattribute is added for all <img> tags if not present, using alt="" if the src attribute contains 'transparent' or alt="TEMPalt:src" in all other cases to allow you to search for missing alt attributes.
  • an alt attribute is added for all <area> tags using alt="TEMPalt"
  • for attributes without a value, such as selected in an option tag, the attribute is rendered as selected="selected"

For tidier, error-free script:

  • block tags are indented
  • carriage returns are inserted where appropriate, for example tdtags do not have an automatic carriage return because this affects the visual appearance of a document but p tags have a carriage return inserted before them
  • blocks of text are wrapped and indented for readability
  • tags such as li and option are automatically closed before an element with the same name is used
  • li and option are closed when their container tag is closed
  • a space is inserted before the closing /> of a tag
  • when a tag is closed inside a tag it contains, the closure is delayeduntil all child tags are closed (e.g. <p><strong>jdsjjds</p></strong> becomes <p><strong>jdsjjds</strong></p>
  • errors are shown for tags that are not closed where the closure cannot be implied by the tag name (e..g OK for img, but not for p), but the utility assumes closure where appropriate
  • unexpected closure of tags is reported and removed but does not interrupt the formatting
  • missing close brackets (>) are reported but the tag is closed automatically (e.g. <tr <td is converted to <tr><td>)
  • <b> tags are replaced with <strong>
  • <i> tags are replaced with <em>

Note that the actual DTD of the document is not checked for confirmity by this routine to allow it to be used with nested inline VBscript, etc. Use other validators such as http://webxact.watchfire.com/ or http://validator.w3.org/ to check that the final rendered page conforms to the required standards.

If you would like to report any problems or suggest enhancements, please use the feedback page.

Microsoft Certified
UKWDA   
staff area client area public area

Do you plan meetings or events? Why not try agreeAdate, our new meeting planner online service.