Here you can find the source of dumpToByteArray(Document document)
public static byte[] dumpToByteArray(Document document) throws TransformerConfigurationException, TransformerException
//package com.java2s; /* Copyright (c) 2013 Intecs - www.intecs.it. All rights reserved. * This code is licensed under the GPL 3.0 license, available at the root * application directory./* w w w .ja v a 2s .c om*/ */ import java.io.*; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerConfigurationException; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import org.w3c.dom.Document; public class Main { public static byte[] dumpToByteArray(Document document) throws TransformerConfigurationException, TransformerException { TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); StreamResult result = new StreamResult(bos); transformer.transform(new DOMSource(document), result); byte[] array = bos.toByteArray(); return array; } }