Created
March 11, 2014 09:35
-
-
Save abdennebi/9482421 to your computer and use it in GitHub Desktop.
Transform XML InputStream to String
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private String xmlToString(InputStream inputStream) { | |
try { | |
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); | |
org.w3c.dom.Document doc = documentBuilderFactory.newDocumentBuilder().parse(inputStream); | |
StringWriter stw = new StringWriter(); | |
Transformer serializer = TransformerFactory.newInstance().newTransformer(); | |
serializer.transform(new DOMSource(doc), new StreamResult(stw)); | |
return stw.toString(); | |
} catch (Exception e) { | |
throw new RuntimeException(e); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment