/** * This method writes the {@link org.w3c.dom.Document} content to an * outputStream * * @param dom * the {@link org.w3c.dom.Document} to be writed * @param os * the OutputStream @ if any error occurred */ public static void writeDocumentTo(final Document dom, final OutputStream os) { try { final DOMSource xmlSource = new DOMSource(dom); final StreamResult outputTarget = new StreamResult(os); Transformer transformer = getSecureTransformer(); transformer.transform(xmlSource, outputTarget); } catch (Exception e) { throw new DSSException(e); } }
/** * This method allows to convert an XML {@code Node} to a {@code String}. * * @param node * {@code Node} to be converted * @return {@code String} representation of the node */ public static String xmlToString(final Node node) { try { final Source source = new DOMSource(node); final StringWriter stringWriter = new StringWriter(); final Result result = new StreamResult(stringWriter); final Transformer transformer = getSecureTransformer(); transformer.transform(source, result); return stringWriter.getBuffer().toString(); } catch (Exception e) { throw new DSSException(e); } }
@Test public void getSecureTransformer() { assertNotNull(DomUtils.getSecureTransformer()); }