The method is used to convert an input xml node like element , attribute, etc to a string value.
It can be used in xml parsing applications
/* Method to convert the given xml node to string */ private String nodeToString(Node node) { /* create an object of string writer */ StringWriter sw = new StringWriter(); try { TransformerFactory tranFactory = TransformerFactory.newInstance(); tranFactory.setAttribute("TransactionType", 3); /* create an object of transformer */ Transformer t = tranFactory.newTransformer(); /* used to omit the xml declaration */ t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); /* specifies the transformation input type like xml, html etc */ t.setOutputProperty(OutputKeys.METHOD, "xml"); /* specifes whether transformer can add additional required spaces */ t.setOutputProperty(OutputKeys.INDENT, "no"); /* The actual transform */ t.transform(new DOMSource(node), new StreamResult(sw)); } catch (TransformerException te) { System.out.println("nodeToString Transformer Exception"); } return sw.toString(); }