throws WBDOMException {
// Set up for the serialisation.
// This involves setting up for the creation of an output string table
// if there was an input string table.
ReferenceResolver resolver;
StringTable outputStringTable = null;
StringTable inputStringTable = document.getStringTable();
if (inputStringTable != null && inputStringTable.size() > 0) {
outputStringTable = new StringTable();
StringReferenceFactory references = new StringReferenceFactory(
outputStringTable, document.getStringFactory());
resolver = new CopyReferenceResolver(references);
} else {
resolver = new NullReferenceResolver();
}
initialiseSerialisers(resolver);
// Serialise the document.
try {
// Kick off the document.
handler.startDocument(document.getVersion(),
document.getPublicId(), document.getCodec(),
outputStringTable, document.getStringFactory());
// Visit down in to the document to serialise it.
visitElement(document.getRootElement());
// Complete the output string table, if neccessary.
resolver.markComplete();
// Finish off the document.
handler.endDocument();
} catch (WBSAXException e) {
throw new WBDOMException(
exceptionLocalizer.format("wbdom-document-write-error"),