Skip to content

Instantly share code, notes, and snippets.

@abdennebi
Created March 11, 2014 09:35
Show Gist options
  • Save abdennebi/9482421 to your computer and use it in GitHub Desktop.
Save abdennebi/9482421 to your computer and use it in GitHub Desktop.
Transform XML InputStream to String
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