 |
Visitor:
|
|
Please note!
This page is currently not up-to-date. The GUI looks a bit different and some features (like the ID-handling) has changed completely!
Installation and start
Download the XML2Java zip file from this web pages.
Unzip it to your favorite development tools directory.
Inside the zip file, you will find a jar file. This is a executable jar. If you configured your computer correctly you can double click it and the GUI will pop up. Otherwise open a shell and 'cd' your way to the installation directory. Then type:
java -jar xml2java.jar
There are, too, batch files present (xml2java.bat and xml2java.sh). I am sure you will manage to start the thing...
The GUI
The XML2Java GUI consists of three Tabs: the 'Input'-Tab, the 'Configuration'-Tab and the 'Output'-Tab. As long as there is no Input file specified, the Configuration and the Output tab are disabled.
The Input-Tab
|
So click on the Browse icon or type in the name of the DTD or XML file you want to be processed.
If there is any error, a message will be shown in the text area below the input file field. If the DTD could be read or extracted successfully, it is shown in this text area.
Now you can move on by clicking 'Next >>' or by selecting the appropriate Tab.
|
The Configuration-Tab
|
On the 'Configuration'-Tab you will find some Options, which modify the source code generated.
Specify an output directory in the upper most compartment. Here there is this old problem again, with selecting directories in a FileDialog. That's why you have to specify a file in the target directory. Or simply type in the path in the text field.
The next text field, titled 'package', is to specify the package of all classes generated. Note that for every package there will be subfolders created. So if your output directory is C:\src and the package is com.test.foo all source generated will reside in C:\src\com\test\foo.
Now its getting a bit more tricky. If there are ID attributes present in the DTD, the next compartement will be enabled. You can specify here, if you want XML2Java to generate classes for these IDs. They will all have a common super class (ID), which contains a Manager inner class. This Manager keeps track of the ID there are. So you can resolve the XMLElement for a ID. This comes in handy, if there are IDReferences present in the XML file. With this Manager you can resolve these IDRefs. There will be a link between the IDRefs and the Elements containing the specified ID.
To make it even more complicated, there are two flavors of ID.Manager. The one only has static methods, the other is a 'real' object. Select a 'static' ID.Manager if you want to work on the generated object model. It is much easier then. But you have to be sure, that you only edit _one_ XML file at a time. If you want to work with multiple XML file at once, use a non-static ID.Manager.
The next things are more straightforward. In the 'Reader' section you can specify if a reader is generated, as well as if it shall be of the SAX2 model. Note that even if it is SAX2, there will be no support for namespaces.
The Writer is always the same and its generation can be enabled or disabled in the 'Writer' section.
|
The Output-Tab
|
When you move on to the Output-Tab, the little progress bar indicates some activity. The java source code model is created and waits to be pumped onto hard disk.
But as you are the master of ceremony, there still is one step: specifying what classes really gets written. In the long list you can select them. I introduced this step because DTDs are changing. But normally you have added some functionality to the classes generated. So not to overwrite all and everything, you can pick the classes you want.
By default all classes are selected. A click on the 'Generate!' button writes them to disk.
|
The Menu bar
If you have a XML parser in your CLASSPATH, there will be a menu bar at the top of the frame. Here you can 'Open' and 'Save' the configuration of the tool. It gets written in XML files with the ending '.x2j'.
From the help menu you can launch a email client, to write me a message. This unfortunately is not very robust. But nevertheless please write me some feedback. I am dependant on it. Feel free to send me suggestions, enhancements, questions, marriage proposals and of course bugs. mailto:xml2java@jNerd.de
Summary
I think the whole tool is pretty easy to use. It is harder to get along with the code generated. With big DTDs some hundred classes are generated. I suggest tools like TogetherJ to get an overview.
Keep an eye on my pages. I really have to add some comments on the source code generated. Until then I hope you get along. If not, do not bother to contact me. mailto:xml2java@jNerd.de
Happy XMLing!
|