This document may contain examples in another language or script.

Use accesskey "n" to jump to the internal navigation links at any point. Right now you can

 
ishida >> writing

My setup for editing XHTML with XMetal

I use XMetal for all my XHTML editing because it ensures validity and I find it very easy to add, move and change tags and attributes. This article describes how I set up my environment to handle XHTML, in the hope that others might find bits of it useful to get started quickly.

Stuff for the Rules directory

These are things you can add to the Rules subdirectory wherever your XMetal application is located. I tend to use the transitional flavour of XHTML 1.0 most of the time, so the links below are to that.

For off-line editing you'll need a copy of the DTD. The items in the Attribute Inspector are ordered according to the order in which they are declared in the DTD. This means that you have to search for some things like href, and that id and name attributes are not side by side. I (carefully) edited a version of the DTD that you can use if you like, to move some of these things into better positions.

You'll also need to add xhtml-lat1.ent, xhtml-symbol.ent and xhtml-special.ent files.

Especially if you use my adapted DTD, you will probably want to add an entry to your catalog file, so that XMetal uses the DTD on your hard drive. If nothing else, this can speed up the loading of a file. You should use a text editor to open the file in the Rules directory called catalog and add the following lines:

PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "xhtml1-transitional.dtd"
PUBLIC "-//W3C//ENTITIES Latin 1 for XHTML//EN"   "xhtml-lat1.ent"
PUBLIC "-//W3C//ENTITIES Symbols for XHTML//EN"   "xhtml-symbol.ent"
PUBLIC "-//W3C//ENTITIES Special for XHTML//EN"   "xhtml-special.ent"

Finally, you'll want a CSS file to lay out your XHTML nicely in the edit window. If you're in a hurry, you can start with mine (though I have to admit, it's currently more functional than nice).

Working on the .ini file

XMetal currently decides by default that any file with a .htm or .html extension is HTML rather than XML. This means that, by default, even if you have set up the img element to be an image using the Tools.Customizations.TreatAs dialogue, you still can't use the icons (and associated dialogue boxes) to insert images or tables in tags-on view in an XHTML document. It also means that in plain text view, where the icons DO work, they insert upper-case element names, which is annoying.

You can solve this problem by editing the xmetalX.ini file (where X is a number). It should look something like the following:

html_file_extensions =
xml_file_extensions = xml;ent;ux;html;htm

Now all .html/.htm files will be treated as XML, solving your problem.

You can now associate the img tag with the toolbar icon in XMetal 3.1 by selecting Tools/Customizations and the TreatAs tab. Ensure that img is selected on the left, then click on Image to the right and set the appropriate attribute information. I have still not figured out how to do this in XMetal 4 Developer, since its much easier to just use XMetal 3.1. You are welcome to just use my customization file instead. (Just drop it into the Rules directory.)

Encoding matters

I always edit in UTF-8. In general this improves your code because XMetal will use characters rather than escapes. In fact, on save XMetal will convert to characters any NCRs you use (with the exception of less than, greater than, etc.).

Generally this is useful. On the rare occasion, however, it can be a pain. For example, you may specifically want to use an NCR to represent things like supplementary characters, because some browsers handle them better that way. I also created a test for NCRs that had to be edited in another editor. Unfortunately, XMetal will convert everything to characters and you'll have to convert it back in another editor before publication. Not something that poses problems often, but a pain when it does.

XMetal (unfortunately) requires you to use an XML declaration to get the encoding right. Although it says it defaults to UTF-8, I find that it is much safer to explicitly declare that in the XML declaration. Example:

<?xml version="1.0" encoding="utf-8"?>

See also the post-processing section below that describes scripts for adding and removing the XML declaration. I haven't yet figured out how to add the XML declaration using XMetal macros as a file is being loaded and remove it just before it is saved.

File processing

I run a number of small programs on an XHTML file edited in XMetal just before I upload to the server. These are very rough and ready, but they work OK.

If I have removed the XML declaration from a file, I need to replace it before opening the file in XMetal again. To do that I use the following script:

Because I use command-line CVS to upload my files, I just link all these together in a single .bat file. Your mileage may vary.

Links

Author: Richard Ishida.

Valid XHTML 1.0!
Valid CSS!
Encoded in UTF-8!

Content created 29 July, 2004. Last update 2004-07-29 08:01 GMT