MarkupWriter w = new MarkupWriterImpl(new XMLMarkupModel());
w.comment(" preamble start ");
w.write("preamble text");
w.cdata("CDATA content");
w.writeRaw(" ");
w.element("root");
w.end();
// You really shouldn't have any text after the close tag of the document, so it
// gets moved to the top, to the "preamble", before the first element.
w.comment(" content after root element in preamble ");