Sample Implementation of TREX in Java

Version 2001-02-12

The implementation is available for download as a JAR file and as a Win32 executable for use with the Microsoft Java VM.

To invoke the Win32 executable, simply copy trex.exe to a directory in your path and run the command

trex file.trex file.xml

This will report errors if file.xml does not match file.trex. You can specify multiple XML files to be validated in a single command.

To use TREX packaged as a JAR file, you must have an XML parser in Java that implements SAX (either version 1 or version 2). You must ensure that the JAR file for your chosen parser is in your CLASSPATH along with trex.jar. You must also ensure that the SAX2 classes are in your CLASSPATH. Often they are included in your parser's JAR file. If not, you can download The main class for TREX is com.thaiopensource.trex.util.Driver. You must specify a system property to inform TREX of what SAX parser you are using. If you are using SAX2, then the system property com.thaiopensource.trex.util.XMLReader must be set to the fully qualified name of the class that implements the org.xml.sax.XMLReader interface. If you are using SAX1, then the system property com.thaiopensource.trex.util.Parser must be set to the fully qualified name of the class that implements the org.xml.sax.Parser interface. The first argument expected by the main class is the name of the file containing the TREX pattern. The second and subsequent arguments are the names of one or more files to be validated against this pattern. So, for example, on Windows, using XP (which implements SAX1), the command:

c:\jdk1.3\bin\java -Dcom.thaiopensource.trex.util.Parser=com.jclark.xml.sax.Driver -cp c:\lib\trex.jar;c:\lib\sax2.jar;c:\lib\xp.jar com.thaiopensource.trex.util.Driver doc.trex doc.xml

would validate the XML document contained in doc.xml against the TREX pattern contained in doc.trex. To use Sun's Crimson parser (included in Java API for XML Processing 1.1 Early Access 2 reference implementation available for download from Sun), the command would be

c:\jdk1.3\bin\java -Dcom.thaiopensource.trex.util.XMLReader=org.apache.crimson.parser.XMLReaderImpl -cp c:\lib\trex.jar;c:\lib\crimson.jar com.thaiopensource.trex.util.Driver doc.trex doc.xml

Obviously, you must replace c:\lib by the path to the directory where you have put the various JAR files.

The commands will be slightly different on non-Windows machines. Consult your Java documentation.

The implementation supports datatypes from XML Schema Part 2.

The source is also available.

There is a TREX task that allows TREX to be invoked by the Ant build tool.

James Clark