Kate XML Completion: Converting DTD to MetaDTD
Kate has this nifty little plugin called “XML Completion.” This plugin loads a Meta DTD file and uses this information for context sensitive completion. To use it, you first have to load it in the settings dialog, and then assign a Meta DTD through the XML menu:
In our example, we work on a Kate XML highlighting definition file and therefore loaded the file “language.dtd.xml” which is shipped with Kate. Having assigned a Meta DTD file, we now have these nice code hints:
Kate ships with several Meta DTD files, such as HTML4 (strict, loose) or XHTML 1.0 transitional, KConfigXT DTD, KPartsGUI or XSLT. While this is really cool, you may ask about arbitrary DTDs you may be using. Unfortunately, Kate only supports Meta DTD, so what now?
Installing dtdparser
Luckily, the tool dtdparser (on sourceforge) converts a DTD to Meta DTD. We first need to install dtdparse. Since openSUSE does not provide a package (what about other distros?), I downloaded SGML-DTDParse-2.00.zip, extracted it and ran (see README file)
perl Makefile.PL
Make sure there are no missing perl dependencies. I for instance had to install perl-Text-DelimMatch and perl-XML-DOM:
sudo zypper install perl-Text-DelimMatch perl-XML-DOM
Then continue with the build and install process (the result of make test should be PASS):
make
make test
sudo make install
Now we successfully installed dtdparse on the system. So we are finally ready to convert DTDs.
Converting DTD to Meta DTD with dtdparser
Having installed dtdparser, it is as easy as calling
dtdparse file.dtd > file.dtd.xml
to convert a DTD to Meta DTD. The conversion should work out of the box. If you want, you can edit the generated .xml file, for instance the “title” attribute is always set to “?untitled?”. While this is not used by the XML Completion plugin (yet?), it’s still nicer to have it properly fixed.
Contributing Meta DTDs to Kate
Whenever you have a DTD that is of use also for other users, please send the generated Meta DTD to kwrite-devel@kde.org (our mailing list). Further, it would be really cool if someone added support to convert DTDs on the fly to Meta DTD, so the Kate XML Completion plugin would just work for DTDs as well. Any takers?
Call at Distribution Packagers
Please consider including dtdparser by default, as it seems to be a very useful too. Are there alternatives to convert DTD to Meta DTD?