Trying to execute Simple parsing from dom.Document to String using javax.xml.transform.Transformer , it results an empty string.
Code :
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
DOMSource source = new DOMSource(doc);
StreamResult console = new StreamResult(sw);
transformer.transform(source, console);
Debug Results:
System.out.println(source.getNode().getFirstChild().getNodeName());
<root element is displayed>
System.out.println("DONE :"+ console.getWriter().toString());
<Empty string is displayed>
Please me know why I get empty string , whereas I need to get the transformed xml string
Blockquote