Chapter 15
614
The DOMWriter class is actually a modification of the DOMWriter.java sample program from the Xerces
distribution. The original source can be found in the samples/dom directory of the Xerces distribution.
Here, we will detail the simple modifications that had been made to the DomWriter.java file. You can find
the modified file in the code/service/webapps/xmlrpc/classes/com/wrox/pjxml directory.
At the very top of the file, we added:
package com.wrox.pjxml;
We commented out the first two statements in the file to remove further dependencies on packages
within the DOMWriter sample that we will not need:
//package dom;
//import util.Arguments;
Next, we comment out the print() method that we will not use:
/** Prints the resulting document tree.
public static void print(String parserWrapperName, String uri,
boolean canonical ) {
...
} // print(String,String,boolean)
*/
We added two methods to the class to enable us to use the class on a PrintWriter:
public void setWriter(PrintWriter outlet) {
out = outlet;
}
public static void print(PrintWriter outlet, Node node) {
DOMWriter writer;
try {
writer = new DOMWriter(false);
writer.setWriter(outlet);
writer.print(node);
} catch ( Exception e ) {
//e.printStackTrace(System.err);
}
}
Finally, we remove the main() method from the file. This eliminates the reference to external
argument processing classes.
Instead of modifying the source code yourself, you can use the modified file provided in the
source code distribution.