System.setProperty(DOMImplementationRegistry.PROPERTY,
"com.sun.org.apache.xerces.internal.dom.DOMImplementationSourceImpl");
DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
impl = (DOMImplementationLS)registry.getDOMImplementation("LS");
}
LSOutput output = impl.createLSOutput();
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
output.setByteStream(byteArrayOutputStream);
LSSerializer writer = impl.createLSSerializer();
writer.write(doc, output);
byte[] buf = byteArrayOutputStream.toByteArray();