Java tutorial
//package com.java2s; //License from project: Open Source License import java.io.BufferedOutputStream; import java.io.ByteArrayOutputStream; import javax.xml.transform.Transformer; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import org.w3c.dom.Document; public class Main { private static Transformer transformer; public static byte[] getContent(Document doc) throws Exception { ByteArrayOutputStream writer = new ByteArrayOutputStream(); transformer.transform(new DOMSource(doc), new StreamResult(new BufferedOutputStream(writer, 65536))); writer.flush(); return writer.toByteArray(); } }