Java Reference
In-Depth Information
<col>F</col>
<col>0.1</col>
<col>400.0</col>
<col>40.0</col>
<col>percent</col>
<col>12.5</col>
<col>35.0</col>
</row>
</data>
</RowSet>
The XML file generated by the WebRowSet object is divided into the three following main sections:
 
<property> — This section contains all the property data associated with the WebRowSet bean.
 
<metadata> — This section contains a metadata element describing each of the columns.
 
<data> — This section contains the actual data.
Note that only one column-definition element is shown in Listing 18-11 , since all 12 are very similar.
As it stands, this XML output does not meet the requirements of the LEDES 2000 specification. There
are three obvious ways to deal with this:
 
Apply an XSL transform to generate the desired XML from the WebRowSet XML.
 
Write a custom XmlWriter to generate the desired XML directly.
 
Generate an XML document directly from a CachedRowSet .
The approach used for this example is to generate the XML directly from a CachedRowSet . The reason
for this is that the WebRowSet XML, designed to serialize the entire bean, contains far more data than is
needed for the application. Moreover, the data is organized in such a way as to make reconstitution of
the RowSet easy rather than to make it suitable for this application.
Using an XSL transform is a very heavyweight solution. Similarly, writing a custom XmlWriter is much
more complex than just writing the required XML for the application; unless you design it to write out all
the data required to serialize the bean and support it with a corresponding XmlReader, it negates the
advantages of XML serialization without giving you any obvious benefits.
Since the XML is intended for transmission to the client as a file, it is generated by writing strings to an
OutputStream, as shown in Listing 18-12 . If you intend to do any additional processing, you can use
a Xerces Document object and build it as a DOM.
Listing 18-12: Generating XML using a CachedRowSet
package JavaDatabaseBible.ch18;
import java.io.*;
import sun.jdbc.rowset.*;
public class CachedRowSetToXML{
public static void main(String[] argv){
String url = "jdbc:odbc:LEDES";
String login = "jod";
String password = "jod";
Search WWH ::




Custom Search