List of usage examples for org.w3c.dom.ls LSOutput toString
public String toString()
From source file:de.mpg.mpdl.inge.xmltransforming.TestBase.java
/** * Serialize the given Dom Object to a String. * /*from w ww. jav a2s. c o m*/ * @param xml The Xml Node to serialize. * @param omitXMLDeclaration Indicates if XML declaration will be omitted. * @return The String representation of the Xml Node. * @throws Exception If anything fails. */ protected static String toString(final Node xml, final boolean omitXMLDeclaration) throws Exception { if (xml == null) { throw new IllegalArgumentException(TestBase.class.getSimpleName() + ":toString:xml is null"); } String result = null; ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); // serialize DOMImplementation implementation = DOMImplementationRegistry.newInstance().getDOMImplementation("XML 3.0"); DOMImplementationLS feature = (DOMImplementationLS) implementation.getFeature("LS", "3.0"); LSSerializer serial = feature.createLSSerializer(); LSOutput output = feature.createLSOutput(); output.setByteStream(outputStream); serial.write(xml, output); result = output.toString(); return result; }