Creating a schema bundle

This guide prepares the XSD files for a schema for Fonto's schema compiler. The schema compiler is used once, or when the XSD's are updated, to compile a web-optimized version of the schema into your editor. This enables the editor to perform real-time, client side validation.

What you need

The XSD files of a schema. If you do not have a schema you can use our example schema from GitHub, run:

Terminal

Shell

git clone https://github.com/FontoXML/training-schema-bundle.git --depth 1
1

Create a fonto.json

The fonto.json file is used by the compiler to determine the repositories to place the compiled files in to and how a newly created Fonto Editor instance loads these for the relevant XML files.

Create a new file called fonto.json in the root folder of your schema. When using our example schema, the location for this file is training-schema-bundle/fonto.json. The contents of this file initially looks like this:

training-schema-bundle/fonto.json

JSON

{
    "rootSchemas": {}
}
2

Fill in the fonto.json for your XSD files

  • Add new properties to rootSchemas for every entry XSD your schema has, where the key is a relative file reference. When using the example schema, this is only the recipe.xsd file. If your XSD modules import or include other XSD modules, that will be handled automatically. Your fonto.json becomes:

    training-schema-bundle/fonto.json

    JSON

    {
        "rootSchemas": {
            "xsd/recipe.xsd": {}
        }
    }
  • Fill out the packageName and locations properties for every rootSchema. The package name affects the code structure generated by the schema compiler, so pick a descriptive name that does not contain special characters. The locations strings are used to match a given XML document with the schema. When using the example schema we can find what is already used from the XML files in training-schema-bundle/test/. The fonto.json file becomes:

    training-schema-bundle/fonto.json

    JSON

    {
        "rootSchemas": {
            "xsd/recipe.xsd": {
                "packageName": "recipe-sx-shell",
                "locations": ["urn:fontoxml:training:delicious:recipe.xsd"]
            }
        }
    }

The minimal folder structure should look like this:

Folder structure

Other

Training/
  training-schema-bundle/
    fonto.json
    xsd/
      recipe.xsd