Generate types

As already mentioned here, Xeditor uses it's own format representing the schema definition. Xeditor offers a tool for generating this JSON file based on any XSD file.

DTD to XSD

However, since you might be using a different schema file, like DTD, you would have to transform your existing DTD to an XSD first. In our experience, this transformation from DTD to XSD works best with trang, but you could also use other tools for this task.

The following part explains where to download and how to use this tool for achieving the proper transformation from DTD to XSD.

  1. Download the package trang-20081028.zip. It can be downloaded here.
  2. Use the command line to navigate to the unzipped Trang package: cd folder
  3. Note: Before running command line code you will need to adjust your file path depending on where you unzipped Trang and have your DTDs located. Enter the following on the command line:
java -jar trang.jar -o disable-abstract-elements pathToSourceDirectory/file.dtd pathToDestinationDirectory/file.xsd

Congratulations! You now successfully converted your DTD file(s) to the XSD format, which Xeditor is capable of handling properly. This generated XSD file(s) is the basis for the next steps of the configuration of Xeditor.

Types generation

This chapter describes how to configure your own schema according to Xeditor. If you are using DTD you need to transform it first to XSD. This was covered in the last section.

Installation

The tool for generating types can be downloaded from the repository. This can either be installed globally via npm install --global @xeditor/tool-xgen or added to the local project. The project from our last chapter already has this dependency, so you don't need to install it.

For another project, this can be installed as follows:

cd /path/to/project # this has to be you project path
npm install --save-dev @xeditor/tool-xgen

Adding your XSD files to the project

Xeditor needs the XSD files for the generation of the types and also for the validation when saving, loading. These files are usually stored under the path WEB-INF/xsd.

mv /path/to/xsd/*.xsd /path/to/project/WEB-INF/xsd/

Converting your XSD to Types

The next step is to convert our XSD to a JSON file, which we can embed in the Xeditor configuration. The best option here is to add a new script in package.json so that we can easily generate the schema in the future.

In the following code snippet of your package.json file the <PATH_TO_ENTRY_XSD_FILE> must be replaced by the real path. These should be located in the project under WEB-INF/xsd.

// path/to/project/package.json
{
// ...
"scripts": {
// ...
"update:types": "xgen types <PATH_TO_ENTRY_XSD_FILE> --output ./src/js/config/types.gen.json"
},
// ...
}

Afterwards we can simply run this script via the command npm run update:types and thus generate our types. We now have a new file ./src/js/config/types.gen.json in our project.

Of course, you can also run the tool without adding it as a script:

./node_modules/.bin/xgen types <PATH_TO_ENTRY_XSD_FILE> --output ./src/js/config/types.gen.json