How to create an XML language and its XML editor in 5 minutes


Introduction

This tutorial explains how to create a configuration file for Jaxe including the menu definitions to insert the XML elements, the way XML elements are displayed, and the XML language. It also gives an example of an XSLT stylesheet. The example has been used to create the file you are just reading.


Creation of the configuration file

The configuration files are stored in Jaxe's config folder, and their names end with _Jaxe_cfg.xml. For instance, the configuration file for configuration files (whose root element is JAXECFG), has the name JAXECFG_Jaxe_cfg.xml. To start the tutorial, we start Jaxe, choose the "New button", and select "JAXECFG - Jaxe configuration file".

There are two options for the creation of a Jaxe configuration file:

Here we will use the simplified syntax, which can only be used to define elements, attributes, sub-elements, and which elements can contain text. If we used an XML schema instead, we should not give any rule about the XML language in the configuration file.

To begin the construction of the configuration file, we insert a description that will be displayed in the dialog used to create new documents.

JAXECFG>
    DESCRIPTION>Tutorial for config files<DESCRIPTION
<JAXECFG

Then, we define the root element for the language, TUTORIAL. Every new document will include this element at the start.

JAXECFG>
    DESCRIPTION>Tutorial for config files<DESCRIPTION
    RACINE>
        BALISE 'TUTORIAL'>
        <BALISE
    <RACINE
<JAXECFG

Creation of the menus

We can now define the menus used to insert new elements. All the elements in the XML language must have a corresponding menu. For the tutorial, we will use the menus "Organisation", "List" and "Text".

MENU 'Organisation'>
<MENU 'Organisation'

MENU 'List'>
<MENU 'List'

MENU 'Text'>
<MENU 'Text'

Definition of the elements

Let's start with the TITLE element. Since it will be inserted with the Organisation menu, it will be defined there. We use the attributes nom='TITLE', titre='Title' (which will be used for the menu), and type='string'. The type attribute specifies the Jaxe element type, which corresponds to the way an element is displayed and edited. Here, with the 'string' type, Jaxe will display it as a simple string with start and end tags. Jaxe element types are described in the syntax documentation.

TITLE will be found for instance under the root element, TUTORIAL. To specify that, a SOUSBALISE (sub-element) element is added under TUTORIAL, with the attribute nom='TITLE'.

Since we want to have text in the titles, we add this information with the TEXTE element in the element definition.

RACINE>
    BALISE 'TUTORIAL'>
        SOUSBALISE 'TITLE'
    <BALISE
<RACINE

MENU 'Organisation'>
    BALISE 'TITLE'>
        TEXTE
    <BALISE 'TITLE'
<MENU 'Organisation'

More display options

Some type attributes often used are division, zone (area) and string. division displays an element with two long horizontal bars in the text, which is very useful to separate large areas in the document. It will be used in the tutorial for the element SECTION. zone displays an element by also adding newlines, but taking less horizontal space. We will use it for the elements PARAGRAPH and EXAMPLE, which will be found under SECTION. Finally, string also displays the element with ELEMENT> and <ELEMENT, but without adding newline characters. We will use it here for all the other elements.

It is possible to make editing with Jaxe more pleasing by specifying for example styles. For a title, we would like to have text in bold, which can be obtained with a parameter. A PARAMETRE element has just to be added under BALISE 'TITLE', with the attributes nom='style' and valeur='GRAS' (value='BOLD'). The complete list of parameters is given in the syntax documentation.

BALISE 'TITLE'>
    PARAMETRE 'style'
    TEXTE
<BALISE 'TITLE'

Element sets

Rather than adding several times the same SOUSBALISE elements, they can be gathered in element sets, and used with SOUSBALISE ensemble='setname' each time we want to add a set of SOUSBALISE. For instance, we want here to use the elements EMPHASIS, CODE and LINK in the text. We just have to create a set under JAXECFG, and use each time we want to use text with all these elements: SOUSBALISE ensemble='text' instead of just using TEXTE.

    ENSEMBLE 'text'>
        TEXTE
        SOUSBALISE 'EMPHASIS'
        SOUSBALISE 'CODE'
        SOUSBALISE 'LINK'
    <ENSEMBLE 'text'

<JAXECFG

Tutorial file

Here is the complete configuration file: TUTORIAL_Jaxe_cfg.xml.

If we had used an XML schema file separate from the configuration file, we would have had to give the path to the file with the element FICHIERSCHEMA. We would also have defined the menus, but we would not have used the elements to define the language : SOUSBALISE, ATTRIBUT, VALEUR, TEXTE, ENSEMBLE.

Here is the same example if we use an XML schema separate from the Jaxe configuration file, by separating the language from the way it is displayed in Jaxe: TUTORIAL2_Jaxe_cfg.xml - TUTORIAL2.xsd.


Creation of the stylesheet

The only thing left is to define a way to display documents created with this new XML language. Jaxe is using XSLT stylesheets transforming XML into HTML for this task.

An XSLT document is created by choosing the "New" menu and selecting "stylesheet - XSLT". XSLT files mix several XLM languages in a document, and we see here the menus for XSLT together with the menus for XHTML.

The XSLT version should be defined with the value "1.0" for the attribute version of the root element. The transformation output has also to be defined. For instance, to obtain XHTML, xsl:output is used with the attributes doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" encoding="ISO-8859-1" indent="yes" method="xml".

In general, an HTML equivalent can be defined for every element. For instance, to display CODE as with tt in HTML, we write:

    <xsl:template match="CODE">
        <tt><xsl:apply-templates/></tt>
    </xsl:template>

Once the XSL file is created, a link to it has to be added in the configuration file, at the beginning. The stylesheet should also be placed in Jaxe's config folder.

JAXECFG>
    FICHIERXSL 'TUTORIAL.xsl'>
    <FICHIERXSL 'TUTORIAL.xsl'

Top chrono!

Finally, we just need to choose the "Open configuration..." menu and to select our configuration file, TUTORIAL_Jaxe_cfg.xml, to create a new document with it. We could also move the configuration file to Jaxe's config folder, so that it appears in the list when a new document is created with the "New" menu.