Java Reference
In-Depth Information
Discussion
The Serialization demonstration in Saving and Restoring Java Objects showed an abstract
base class that called upon abstract methods to write the file out in some format.
Example 20-3 is the XML subclass for it. If you haven't read that section, all that matters is
that write() is called with one argument, the tree of objects to be saved.
Example 20-3. SerialDemoXML.java
public
public class
class SerialDemoXML
SerialDemoXML extends
extends SerialDemoAbstractBase {
public
public static
static final
final String FILENAME = "serial.xml" ;
public
public static
static void
void main ( String [] args ) throws
throws IOException {
new
new SerialDemoXML (). save ();
new
new SerialDemoXML (). dump ();
}
/** Save the data to disk. */
public
public void
void write ( Object theGraph ) throws
throws IOException {
XMLEncoder os = new
new XMLEncoder (
new FileOutputStream ( FILENAME ));
os . writeObject ( theGraph );
os . close ();
new
}
/** Display the data */
public
public void
throws IOException {
XMLDecoder inp = new
void dump () throws
new XMLDecoder (
new FileInputStream ( FILENAME ));
System . out . println ( inp . readObject ());
inp . close ();
new
}
}
Transforming XML with XSLT
Problem
You need to make significant changes to the output format.
Search WWH ::




Custom Search