How to use the xmlmapper package ?
note: currently, the only xmlParser available is "XercesDom". It means
that the parser that will be used to realize the mapping is DOM from
Apache Xerces. The procedure to add new parsers is described here.
Generate the java source code realizing the mapping you want
xmlmapper.ClassBuilder is the object doing what you want.
You have two possibilities of using the ClassBuilder object depending
if you want to use a properties file or not:
-
public static void generate(String xmlParser, String xmlUrl, String packageName,
String targetDirName) throws IOException;
-
public static void generate (String xmlParser, String propertiesFile) throws
IOException;
The properties file is usefull if you want someone to use this mapping
without any knowledge of the ClassBuilder object. It also allows you to
easily modify one characteristic of your generation without having to recompile
any of your code.
Compile the generated classes and begin to use it in your code
Initialize your objects with the xml document values you want
xmlmapper.ClassPopulater is the object doing what you want.
Again, you have two options depending if you want to use a properties
file or not:
-
public static Object popule(String xmlParser, String xmlUrl, String packageName)
throws IOException;
-
public static Object popule(String xmlParser, String propertiesFile) throws
IOException;
the returned object is the root object from where you can access all objects.
The children objects are stored in ArrayLists, attributes are stored in
String and text (or CDATA) fields as String.
Write back XML !
xmlmapper.XmlBuilder is the object doing what you want.
There is only one method to use here:
-
public static void generate(String xmlParser, Object obj, OutputStream
out) throws IOException;
It will generates the xml corresponding to the object (which should be
part of the generated package) you gave as input to the given OutputStream.