XML editors

From Apertium
Revision as of 10:06, 12 February 2015 by Unhammer (talk | contribs)
Jump to navigation Jump to search

If you are editing Apertium language data (e.g. dix and transfer files), you should use a real XML editor. These can show the errors as you type, so you won't have to parse the output of make.

There are two main kinds of XML errors:

  • well-formedness errors are things like missing a " or end-tag; most editors are able to catch these or at least show you that you forgot a " by syntax highlighting;
  • validation errors require some knowledge of what a .dix or .t1x file should look like, and may tell you things like that "you've referred to a pardef that hasn't been defined". Not all editors are able to do full validation.


Some popular editors for XML:

  • Gedit – a simple GUI code editor (written in C/Python)
    • sudo apt-get install gedit gedit-developer-plugins
    • Does syntax highlighting for XML out of the box, which does show some well-formedness errors
    • There's an XML validation plugin at https://launchpad.net/gedit-xmltools but it only works with gedit2
  • XML Copy Editor – a simple GUI editor (written in C++) purely meant for XML
    • sudo apt-get install xmlcopyeditor
    • XML Copy Editor will check well-formedness (that you have your brackets and quotes in place) out of the box
    • To get validation you may have to click XML→Associate→System DTD and select dix.dtd from lttoolbox (typically in /usr/local/share/lttoolbox or /usr/share/lttoolbox). This will insert a DOCTYPE line in your xml, but that's fine.
    • There seems to be a bug that gives wrong line numbers on some validation errors.
  • Jedit – a "programmers" GUI editor (written in Java) with frillions of options and menus
    • sudo apt-get install jedit
    • Does syntax highlighting for XML out of the box
    • Install the plugin named "XML" to get validation (you can put <code><!DOCTYPE dictionary SYSTEM "/usr/share/lttoolbox/dix.dtd"></code> before the <document> element to make it use the dtd automatically).
  • Vim – a lightweight, modal editor
    • Does syntax highlighting for XML out of the box if you have "syntax on" in your ~/.vimrc
    • See Vim for more infor
  • Emacs – a self-documenting, extensible lisp machine


Converting DTD to XSD/RNC/RNG

An XML editor can check if you XML is well-formed (the brackets match up and so on), but to check for validity, you need to give it the schema for the file type you're editing. Some editors can read the DTD schemas in the lttoolbox/apertium directories, while some editors require other schema formats.

The java program "trang" can convert the dix and transfer DTD's to other formats like XSD, RNC or RNG, if your favourite editor doesn't support DTD's.

cd
wget http://jing-trang.googlecode.com/files/trang-20091111.zip
unzip trang-20091111.zip
cd trang-20091111

java -jar trang.jar -I dtd -O xsd ~/src/apertium/trunk/lttoolbox/lttoolbox/dix.dtd ~/src/apertium/trunk/lttoolbox/lttoolbox/dix.xsd
java -jar trang.jar -I dtd -O rng ~/src/apertium/trunk/lttoolbox/lttoolbox/dix.dtd ~/src/apertium/trunk/lttoolbox/lttoolbox/dix.rng
java -jar trang.jar -I dtd -O rnc ~/src/apertium/trunk/lttoolbox/lttoolbox/dix.dtd ~/src/apertium/trunk/lttoolbox/lttoolbox/dix.rnc

XML Copy Editor can also convert between DTD and other formats.

See also