Top

XML Mode


In XML mode, the bottom pane of the sidebar normally displays a tree representing the document you're editing. The tree is enabled by default. To disable it, add the following line to your preferences file:

    enableTree=false

If the tree is enabled but no tree appears in the sidebar, the most likely reason is that j's XML parser was unable to parse the contents of the buffer. Parsing is done in a background thread, so it may take a little while for the tree to appear (or possibly a long while, if the document references a DTD on the Internet, for example).

The j distribution includes a version of the Ælfred XML parser from Microstar, taken from David Brownell's SAX2 XML Utilities.

If you would rather use a different XML parser, you need to do two things:

  1. Add the relevant jar file(s) to j's runtime CLASSPATH. If you build j from source, you can use the configure script's --with-extensions option to do this:
        ./configure --with-extensions=/usr/share/java/xerces.jar:/usr/share/java/xp.jar
    
    The j shell script that is automatically generated and installed will then use the correct CLASSPATH.

  2. Add a line to your preferences file to specify the org.xml.sax.parser property, which tells j the fully qualified class name of the parser to use. For example:
        org.xml.sax.parser=org.apache.xerces.parsers.SAXParser
    

When you have a tree in the sidebar, the selection in the tree will follow along as you navigate in the edit buffer, but the tree is not automatically expanded to show nested nodes. You can use xmlFindCurrentNode, mapped by default to Ctrl =, to force the tree to expand all the way down to the node corresponding to the location of the caret in the edit buffer.

Clicking on a node in the tree moves the caret to the corresponding location in the edit buffer.

By default, the tree is not refreshed automatically if you make changes to the buffer. If you'd like the tree to be refreshed automatically, add a line like this to your preferences file:

    refreshTree=500
The numeric parameter is the number of milliseconds the user must be idle before j refreshes the tree. A value of zero (which is the default) disables the automatic refresh functionality. In the current implementation, the minimum effective value is 500 milliseconds.

If the tree is enabled, you can use xmlParseBuffer, mapped by default to Ctrl P, to force the tree to be refreshed. The parser uses the image of the buffer in memory, rather than the file on disk, so there's no need to save any changes you've made to the buffer before refreshing the tree.

If xmlParseBuffer encounters an error, the tree is not updated. Instead, a message box displays the parser's error message, and the caret is moved to the location of the error in the edit buffer (as reported by the parser). You can use showMessage, mapped by default to Alt M, to have another look at the error message later.

Parser errors that occur when j is automatically refreshing the tree are not reported.

xmlParseBuffer invokes xmlFindCurrentNode automatically when it succeeds in updating the tree.

The following commands are also specifically relevant in XML mode: