In this document, you'll find a brief package description, some quick start information and the basic rules for xml2class usage.
xml2class provides you with a simple XML parser, which instantiates data structures written in Java out of a XML description (and supports storing them back as XML code). It is thought as an aid for programmers, as it won't do all the work for you.
With the aid of xml2class you may describe most data structures (such as linked lists, binary trees, tables, menus, and so on) in easy to modify XML. Following the XML descriptions, it won't be difficult to write the corresponding Java classes. Then the XML2ClassParser will read in and instantiate the entire structure in a way that you may save it back to disk easily (in XML).
Implement the data structure in XML. Think of one XML element as one Java class. E.g. for...
<RootElementName att1="Constructor Parameter 1" att2="Constr. Param. 2">
<method>
any parameters (any Objects)
</method>
<AnotherElement att3="Constr. param."/>
<methodName/>
...
</RootElementName>
...write the following Java class:
public class ElementName {
public ElementName(String anyValue1, String anyValue2) { ... }
public void setMethod([ParameterObjectsClassType] value) { ... }
public void addAnotherElement(AnotherElement element) { ... }
public void methodName()
...
}
Note how the tags correspond to classes, methods and parameters. Implement now the data structure like this. Have a look at the explicit rules for more precise information to be considered.
Now you can load it into your program with the following line:
[RootElement] root = XMLFile.parse("[directory/filename.xml]", "[package.name]");
And save it back by using
XMLFile.save([RootElement], "[directory/filename.xml]");
supposing your objects provide a toXMLString() method.
For more concrete information, have a look at the example.
--> set[MethodName]( ) or [methodName]( )<methodName/>).add[ClassName]( ) .set[...]( ) and add[...]( ) method may have only one parameter, so that there will be several method calls for several objects / elements.set[...]( ) and add[...]( ) methods may be overloaded. xml2class will then automatically select the right method.[methodName]( ) calls won't have any parameters.<_[methodName]>. This will result in a [methodName]( ) call, but with the same parameters as the corresponding set[...]( ) method.XML2ClassParser ignores the attribute's names).<Double value='x'/> ("java.lang" doesn't have to be added to the classpath).XMLFile.parse( )), the entire package name should be written (or the relative one from where one of the classpaths has been set to).XMLFile should use whitespace (e.g. spaces) as separators| Character | & | < | > | " | ' |
| Entity | & | < | > | " | ' |
&#[value]; or &#x[hexvalue];.XMLFile.toEntityString(String s) (necessary for saving data back to a XML file).XMLFile.parse([...]) methods.XMLFile.parse([...]) into your own code and adapt it there.parse(reader, rootElementName).PrintWriter to the parser by setVerbose(printWriter).For any comments, bug reports ("it's not a bug, it's a feature!") and so on - I am aware of the insufficient quality of this documentation - just contact me:
Simon Bünzli, zeniko@gmx.ch
Version 05/08/01 - Copyleft (C) 2001