XmlWriter writer;
try {
writer = new StreamingXmlWriter(documentFactory
.createXMLStreamWriter(out));
DefaultDocumentBuilder builder = type.createDocumentBuilder(writer);
ArticleDocument document = new DefaultArticleDocument(builder,
codec.getCodecDescriptor().getTitle());
document(codec, document);
document.end();
} catch (XMLStreamException e) {
// In the unlikely event this happens:
throw new RuntimeException("Failed to create stream writer.");
}
}