Skip to content
Create a gist now

Instantly share code, notes, and snippets.

DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
Document doc = docBuilder.newDocument();
Element rootElement = doc.createElement("root");
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
DOMSource source = new DOMSource(doc);
final ByteArrayOutputStream os = new ByteArrayOutputStream();
StreamResult result = new StreamResult(os);
transformer.transform(source, result);
System.out.println(new String(os.toByteArray(), StandardCharsets.UTF_8));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.