Java tutorial
//package com.java2s; import java.io.ByteArrayOutputStream; import javax.xml.stream.XMLOutputFactory; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; public class Main { private static ByteArrayOutputStream stream = null; public static XMLStreamWriter createStreamWriter() { if (stream != null) { System.out.println("ERROR: there is already an existing stream."); } stream = new ByteArrayOutputStream(); XMLOutputFactory xmlFactory = XMLOutputFactory.newInstance(); try { XMLStreamWriter writer = xmlFactory.createXMLStreamWriter(stream); writer.writeStartDocument(); return writer; } catch (XMLStreamException e) { e.printStackTrace(); } return null; } }