Read the whole "Jato: The New Kid on the Open Source Block" series:
This article, the second in a series of three, moves from the general to the specific by examining Java-to-XML transformations in detail. In that context, we'll see examples illustrating how to:
The techniques covered in this article represent ideal generating scripts to persist application-configuration information,
serialize Java objects for long-term storage, and dynamically generate XML for viewing in Web browsers. As a vehicle for discussing
these topics, we will develop a Jato script that converts a directory structure as represented by the java.io.File class into XML. The completed script will perform the following tasks:
The following listing provides sample output from the finished script:
<?xml version="1.0" encoding="UTF-8"?>
<root path="E:\ARTICLES\jw-jato-2\examples">
<dir name="examples" modified="Mon, Jan 15, '01" permissions="rw">
<dir name="step-1" modified="Tue, Jan 16, '01" permissions="rw">
<file size="1403" modified="Sat, Mar 17, '01" permissions="rw">
java-to-xml.xml
</file>
<file size="3620" modified="Fri, Feb 09 '01" permissions="rw">
FileToXML.java
</file>
</dir>
</dir>
</root>
Like many XML documents, our example can generate deeply nested XML elements. With recursive macro calls, we can handily generate
and process such documents. One of the difficulties with recursive programs is tracking what the program is currently processing.
Jato provides an excellent means for tracking program execution with the <Jato:debug> tag. We'll see macros and debugging next.
Note: At the time of this writing, Jato is in beta 2, with tremendous development work being piled into it. Occasionally, a change is made that will break backwards compatibility. To ensure the article examples work properly, the distribution will include all the samples from this series.