XSD Fu

XSD Fu is a Python application designed to digest OME XML schema and produce an object oriented Java infrastructure to ease work with an XML DOM tree.

Requirements:

NOTE: Genshi 0.5 was released on June 9th 2008. You can either install from source or download a compatible .egg for your system on the Genshi download page.

Checking out the source

svn co http://svn.openmicroscopy.org.uk/svn/specification/Xml/xsd-fu/trunk xsd-fu

Running the code generator

If you do have Genshi already installed you can run xsd-fu script with no arguments to examine the syntax:

$ ./xsd-fu 
Expecting single ome.xsd file path!
Usage: ./xsd-fu [-n xsd_namespace] [-p package] -o <output_dir> <path/to/ome.xsd>
Generates Java classes from an OME XML Schema definition.

Default package: "ome.xml.r2008"
Default namespace: "xsd:"

Examples:
  ./xsd-fu -n 'xs:' -p ome.xml -o ome/xml schemas/ome.xsd

Report bugs to Chris Allan <callan@blackcat.ca>

If you do not have Genshi installed you can use a downloaded Python .egg for your platform as follows:

$ export PYTHONPATH=Genshi-0.5-py2.4-linux-i686.egg
$ ./xsd-fu 
Expecting single ome.xsd file path!
Usage: ./xsd-fu [-n xsd_namespace] [-p package] -o <output_dir> <path/to/ome.xsd>
Generates Java classes from an OME XML Schema definition.

Default package: "ome.xml.r2008"
Default namespace: "xsd:"

Examples:
  ./xsd-fu -n 'xs:' -p ome.xml -o ome/xml schemas/ome.xsd

Report bugs to Chris Allan <callan@blackcat.ca>

Generating OME Java

The following commands are what we used to generate the OME-XML node hierarchies for the OME Java class library:

$ export PYTHONPATH=Genshi-0.5-py2.4-linux-i686.egg

$ mkdir -p ome/xml/r2003fc/ome
$ ./xsd-fu -n xs: -p ome.xml.r2003fc.ome -o ome/xml/r2003fc/ome ~/cvs/OME/src/xml/schemas/ome.xsd

$ mkdir -p ome/xml/r200706/ome
$ ./xsd-fu -p ome.xml.r200706.ome -o ome/xml/r200706/ome ~/svn/specification/Schemas/OME/2007-06/ome.xsd

$ mkdir -p ome/xml/r200706/spw
$ ./xsd-fu -p ome.xml.r200706.spw -o ome/xml/r200706/spw ~/svn/specification/Schemas/SPW/2007-06/SPW.xsd

$ mkdir -p ome/xml/r200802/ome
$ ./xsd-fu -p ome.xml.r200802.ome -o ome/xml/r200802/ome ~/svn/specification/Schemas/OME/2008-02/ome.xsd

$ mkdir -p ome/xml/r200802/spw
$ ./xsd-fu -p ome.xml.r200802.spw -o ome/xml/r200802/spw ~/svn/specification/Schemas/SPW/2008-02/SPW.xsd

If you want to generate the same source files yourself, note that the exact commands will vary depending on the locations of your ome.xsd schema files.

Compiling the classes (an example)

During compilation XSD Fu expects the ome.xml package to be available. Specifically the following classes:

  • CustomNode
  • DOMUtil
  • OMEXMLNode
$ ls -a ome/xml/*.class
ome/xml/CustomNode.class        ome/xml/DOMUtil.class           ome/xml/OMEXMLNode.class

$ mkdir -p ome/xml/r200706/ome

$ ./xsd-fu -p ome.xml.200706.ome -o ome/xml/200706/ome schemas/ome.xsd

$ javac ome/xml/200706/ome/*.java

Special Thanks

A special thanks goes out to Dave Kuhlman for his fabulous work on generateDS which XSD Fu makes heavy use of internally.


See also: DeveloperInfo, http://genshi.edgewall.org/