contentBuilder.createDefaultRootContent(cmDocument, cmElementDeclaration, namespaceInfoList);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream, charset);
DOMWriter domWriter = new DOMWriter(outputStreamWriter);
// TODO... instead of relying on file extensions, we need to keep
// track of the grammar type
// better yet we should reate an SSE document so that we can format it
// nicely before saving
// then we won't need the DOMWriter at all
//
domWriter.print(xmlDocument, charset, cmDocument.getNodeName(), getNonWhitespaceString(getPublicId()), getNonWhitespaceString(getSystemId()));
outputStream.flush();
outputStream.close();
return outputStream;
}