I am creating a custom XML document. But I do not want the XML to be available as a file but I want it to be available in the system clipboard as a string so that I can paste manually to an already existing file.
I am using the transformer to write the XML as :
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
DOMSource source = new DOMSource(doc);
StringWriter writer = new StringWriter();
transformer.transform(source, new StreamResult(writer));
String output = writer.toString();
but I am getting a null pointer exception here.
transformer.transform(source, new StreamResult(writer));
Can you please help me out.