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:
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();
}
But an xml file is not what I want, I need to create my XML in a String
.
Unfortunately I can't figure out which OutputStream
object I need instead of the FileWriter