Writing stax XML to String
<p>I am using stax to create XML document that I need for my web app. 
Currently I am creating my XML in a file like this: </p>

<pre><code>    XMLOutputFactory factory = XMLOutputFactory.newInstance();
    String output=null;
     try 
     {
             XMLStreamWriter writer = factory.createXMLStreamWriter(
                     new FileWriter("C:\\Junk\\xmlDoc.xml"));
             writer.writeStartDocument();
             writer.writeStartElement("TagName1");
             writer.writeAttribute("AAA", "BBB");
             writer.writeEndElement();
             writer.writeEndDocument();             
             writer.flush();
             writer.close();
     } 
     catch (XMLStreamException e) 
     {
         e.printStackTrace();
     } 
     catch (IOException e) 
     {      
        e.printStackTrace();
     } 
</code></pre>

<p>But an xml file is not what I want, I need to create my XML in a <code>String</code>. 
Unfortunately I can't figure out which <code>OutputStream</code> object I need instead of the <code>FileWriter</code> </p>