Skip to content

Instantly share code, notes, and snippets.

@fernandor777
Created February 18, 2019 00:39
Show Gist options
  • Save fernandor777/f97bf085e797284dcbc3224a5c42385a to your computer and use it in GitHub Desktop.
Save fernandor777/f97bf085e797284dcbc3224a5c42385a to your computer and use it in GitHub Desktop.
XML java

Document to String, to file.

Document doc = getResultDoc();
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
StringWriter writer = new StringWriter();
transformer.transform(new DOMSource(doc), new StreamResult(writer));
String output = writer.getBuffer().toString();

FileUtils.writeStringToFile(new File("/home/fernando/Documents/temporary/result.xsd"), output,
        StandardCharsets.UTF_8);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment