XML Completion

Daniel Naber

This plugin gives hints about what is allowed at a certain position in an XML file, according to the file's DTD. It will list possible elements, attributes, attribute values or entities, depending on the cursor position (e.g. all entities are listed if the character on the left of the cursor is &). It's also possible to close the nearest open tag on the left.

The DTD must exist in XML format, as produced by the Perl program dtdparse. We will call a DTD in this format meta DTD. Some meta DTDs are supplied. They are installed in $KDEDIR/share/apps/katexmltools/, which is also the default folder when you choose Assign Meta DTD.... To produce your own meta DTDs, get dtdparse from http://dtdparse.sourceforge.net.

How to Use

Start Kate and open the configuration dialog under SettingsConfigure Kate.... Then select XML Completion which will appear in the Application/Plugins section and close the dialog. After that, select XMLAssign Meta DTD.... If your document contains no DOCTYPE or the doctype is unknown, you will have to select a meta DTD from the file system. Otherwise the meta DTD that matches the current document's DOCTYPE will be loaded automatically.

You can now use the plugin while typing your text:

< (less than key)

This will trigger a list of possible elements unless the cursor is inside a tag already. Note that you currently cannot use this to insert the top level element (e.g. <html>).

</(less than key + slash)

Entering these characters will offer to close the current element (nearest open one to the left of the cursor). Press Enter to accept the suggestion. Unlike the Close Element menu item, this works only with a DTD assigned.

" (quote key)

The quote key will trigger a list of possible attribute values (if there are any) if you are inside a tag.

  (space key)

This key will trigger a list of possible attributes for the current element if you are inside a tag.

& (ampersand key)

This key will trigger a list of named entities.

Features and Limitations

You can test all functions and limitations by loading $KDEDIR/share/apps/katexmltools/testcases.xml into Kate and following the instructions.

Menu Structure

XMLInsert Element... (Ctrl+Return)

This will open a dialog that lets you insert an XML element. The <, > characters and the closing tag will be inserted automatically. If you have selected text when this menu item is selected, the selected text will be surrounded by the opening and the closing tag. The dialog also offers completion of all elements that may be inserted at the current cursor position if you have assigned a meta DTD by using Assign Meta DTD....

XMLClose Element (Ctrl+<)

This will search your text for a tag that is not yet closed and will close it by inserting the corresponding closing tag. The search starts at the cursor position and goes left. If it cannot find an open tag nothing will happen.

XMLAssign Meta DTD...

This will tell the plugin which meta DTD to use for the current document. Note that this assignment will not be saved. You will have to repeat it when you start Kate the next time.

Thanks and Acknowledgments

Kate Plugin XML Completion copyright 2001,2002 Daniel Naber .

KDE SC 4 version copyright 2010 Tomáš Trnka

Documentation copyright 2001,2002 Daniel Naber