Converting pages and doctype declarations using KompoZer
KompoZer is capable of creating pages using one of several versions of HTML. The file will use code appropriate to the chosen version and the first line of the file will be the Doctype Declaration which identifies the version. It is fundamental that the code and the this declaration must match.
KompoZer is not designed to convert from one version to another hence there is no logical need to rewrite or modify the Doctype Declaration and any attempt to do so within KompoZer will be thwarted and the original declaration will remain.
In spite of this, authors sometimes do want to change the doctype and declaration and usually resort to using external text editors. While this is often not difficult problems can occur if the editor does not support the character encoding used on the page and conversion using KompoZer is preferable. In spite of appearances this is a simple process the greater difficulty arises in determining if such rewriting is admissible. Of this more later.
After a few preliminary checks to ensure that the change will be valid, or can be edited to be so, simply proceed as follows:
- Open the file to be changed
- Switch to source view
- Select all and copy
- Using KompoZer create a new file using the required new doctype
- Switch to source view
- Select all and paste
- Switch to normal view
The document may now be saved and will have a changed doctype declaration. Checks may need to be made to ensure that the code matches the declaration and any necessary changes made.
Why you might want to change a declaration
Converting a page from one version of HTML to another is not a trivial matter and may require extensive rework which will rarely be justified but there are a few cases where the work required is less and conversion may be.
- Transitional doctype created using Nvu
When Nvu creates documents using transitional doctype it omits the URL part. The result is that MSIE6 and MSIE7 are triggered into Quirks mode so that files may not render as expected. Changing such files to correct transitional mode is completely safe and will correct rendering errors.
- Change strict mode page to transitional
This change is completely safe though normally inadvisable. One case where it might be considered required is if you wish to use the target attribute with a href. This is not allowed with strict doctype but is allowed with transitional. (Since strict doctype is a better approach to design, violating it in this one respect might be considered an acceptable compromise.)
- Change XHTML to HTML or vice versa
This change is safe *. KompoZer will make the required changes
to the code. Since XHTML offers most designers no benefit many will
prefer to standardise all their designs to strict HTML.)
* Though the change is 'safe' a small amount of rework is sometimes required.
- Upgrade old files
Those who have files based on earlier versions of HTML or using faulty tools may wish to upgrade them. Though considerable rework may be required converting to Transitional HTML may ease the task.
When converting a web page from one version to another there are three issues to consider
- Language change html ↔ xhtml
- Strict ↔ Transitional
- Standards compliant mode ↔ Quirks mode
In general any of these conversions is possible but it is a question of how much work needs to be put in. Some conversions would require reworking of the page from the ground up. It also depends on what code has actually been used on a page. With some very simple pages probably any of these conversions could be carried out by simply rewriting the doctype declaration and no difference in rendering or validity would result but that is the exception.
Let's suppose you are using KompoZer and, not being a code expert, you work mainly in wysiwyg mode. Designers working this way sometimes get a long way through a design only to discover that they want to use some feature not possible with the version they are using. For example they may want to use the 'target' attribute with 'href' but are using a strict doctype which precludes this. For those not experts, maybe pretty shaky on CSS who started using a strict doctype they may wish they had used transitional because they need to use 'center' or some other deprecated attribute. An other possibility is that the doctype they are using triggers MSIE into quirks mode to that 'the page looks different in IE and Firefox'.
Safe and easy changes
It is NEVER really safe just to change the doctype declaration unless you know the code is valid for the new doctype or you change it to be so. But there are a few changes that are relatively safe.
- Any strict doctype can be changed to transitional unless you are using target.
- Any transitional doctype which is missing the URL can have the URL added unless you are relying on MSIE rendering it in quirks mode.
- Any html or xhtml doctype may be changed to the corresponding xhtml or html doctype bearing in mind the warnings in the KompoZer User Guide appendix 3 and provided that a few simple changes are made to the code.
Scope of method
The method described will always change the doctype but should be restricted to cases where the code will be changed or remains valid.
- Code generated by KompoZer generally complies with both html and xhtml requirements. Where it does not (e.g. in treatment of 'empty' tags) the process described will make any necessary changes.
- Faulty, wrong or old doctypes that trigger quirks mode can be changed to valid transitional doctypes without any problem.
- Transitional doctypes can be changed to strict but you must rework any deprecated elements or attributes either before or after the conversion. If the anchor element has been used with target attribute there is no valid change other than removal.
The tables show changes which will probably work with few if any problems however be warned I have not made comprehensive tests and you should always check validity and cross-browser operation after any conversion.
|Original doctype||Target doctype|
|Original doctype||Target doctype|
|Transitional||Not safe (4)||-|
Notes (referring to numbers in tables)
- KompoZer will convert code e.g. empty tags, as required.
- Changing between HTML and XHTML may require a few code changes. e.g. the placing of background on the page.
- KompoZer will leave all code unchanged
- Changing from transitional to strict doctype may require extensive recoding to remove deprecated elements. If this is undertaken the change will become safe.
- Pages using Transitional doctype created using Nvu triggered Quirks mode. Changing to transitional doctype will change rendering in some browsers but normally for the better.