Chapter 50. Editing

Table of Contents

1. Overview
1.1. XML Editors
2. XML Schema
2.1. Types of Schema
3. Namespaces and OpenLaszlo Schema

1. Overview

LZX source files are text files. Any standard text editor can be used to edit them.

1.1. XML Editors

LZX source files are XML files. An XML-aware editor such as Eclipse, BBEdit, or Emacs(with psgml-mode or nxml-mode ) will provide additional editing facilities such as automatic indentation, syntax highlighting (coloring markup characters such as < and tag names such as <canvas>), and well-formedness checking (letting you know when you have an unbalanced <or quotation mark).

To configure an XML-aware editor to edit LZX files, you must configure it to edit those files in XML mode. This is done by registering the lzx extension with the XML mode of the editor. How to do this depends on the exact editor; consult your editor documentation for configuration details. Also see the OpenLaszlo Wiki for instructions for some popular editors.

2. XML Schema

An XML schema lists the tag and attribute names that can occur within an XML document. Many XML editing tools are schema-aware. These tools can associate an XML document with a schema file, and use the schema file for code completion (to complete a tag or attribute name, or suggest a list of valid attribute values) and validation (to indicate invalid tag or attribute names within the editor, so that you don't have to wait until you compile the file).

The method for associating an XML document with a schema file depends on the editor; consult your editor documentation for configuration details.

2.1. Types of Schema

There are three types of schemas in popular use: DTDs, XSD, and RNG (and its associated format RNC). The LZX schema is distributed in each of these formats. They can be found in the WEB-INF/lps/schema directory.

A Document Type Definition (DTD) is the oldest type, and is recognized by the most editors. Unfortunately, the DTD format is very weak compared with the other schema description languages, and can't indicate certain contextual information such as that a <dataset> can contain arbitrary XML. A DTD should only be used in an editor that doesn't support the other formats.

W3 and OASIS are standards bodies. The W3 standard for describing XML documents is the XML Schema Definition (XSD). The OASIS standard is RELAXNG. RNG and RNC files are RELAXNG files that contain schema definitions. RNG files are in XML; RNC files are intended to be human-readable.

3. Namespaces and OpenLaszlo Schema

OpenLaszlo applications can be written with a namespace:

<canvas
      xmlns="http://www.laszlosystems.com/2003/05/lzx">...</canvas>

or without:

      <canvas>...</canvas>

If there is no namespace, the compiler defaults it to the LZX namespace ( http://www.laszlosystems.com/2003/05/lzx").

As of OpenLaszlo release 3.1, the schema in lax.rnc has three deficiencies:

  • It only works for sources that include the namespace declaration; for example it won't validate <canvas/> because it doesn't declare any elements in the empty namespace.

  • It only knows about the foundation classes, not the components; for example it won't validate <canvas xmlns="..."><button/></canvas> because <button> isn't a foundation class.

  • It isn't aware of tags that are defined in the application or its libraries; for example <canvas xmlns="..."><class name="myclass"/><myclass/></canvas>

The difficulty is that the <class> tag in LZX actually extends the schema by adding new tags and attributes. We have a hand-written basic schema (WEB-INF/lps/schema/lzx.rnc) which is used to start with, but then user and system component libraries can extend the schema, depending on the application.

<window>, for example, is defined in a source library in lps/components/lz/window.lzx, so it is not in the base schema. So it is difficult to use a static RNG schema, because it needs to be modified as the application defines new classes.

The LZX compiler can be asked to give you the RNG schema from a source file, so something might be able to be hooked up to keep regenerating the schema from the source file, although it would be hard because the sources are often in an inconsistent state as you develop your application, so the parser has to be very forgiving about badly formed XML.

We have worked around the first problem with a transform of that schema that strips out the namespace declaration. That's tools/lzx+libraries-nons.rnc. We have worked around the second problem with a script that makes a copy of the schema and adds the components. This is tools/lzx+libraries.rnc. The third problem can't be fixed without modifying nxml-mode to either add declarations for <class> declarations that it sees, or request the schema for an application from the compiler. (From the command line, the --schema option does this.) OpenLaszlo does neither of these.

The LZX tag set is defined in a relax.ng schema located in the lps/toolsdirectory.

If you are going to use the schema,

  • Use tools/lzx+libraries.rnc for files that include the XML namespace declaration

  • Use tools/lzx+libraries-nons.rnc for files that don't include a namespace declaration.