List of utility methods to do XML Document Serialize
void | serialise(Document doc, OutputStream out) serialise TransformerFactory fac = TransformerFactory.newInstance(); Transformer tf = fac.newTransformer(); tf.setOutputProperty(OutputKeys.INDENT, "yes"); Source input = new DOMSource(doc.getDocumentElement()); Result output = new StreamResult(out); tf.transform(input, output); |
void | serialiseDOM(Document doc, String filepath) serialise DOM Transformer transformer; try { transformer = TransformerFactory.newInstance().newTransformer(); Result output = new StreamResult(new File(filepath)); Source input = new DOMSource(doc); transformer.transform(input, output); } catch (TransformerConfigurationException e) { e.printStackTrace(); ... |
void | serialize(Document d, File f) serialize try { doSerialize(d, f); } catch (TransformerException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); |
void | serialize(Document d, OutputStream out, URL transformerLocation, Map serialize Source source = new DOMSource(d); Transformer transformer = null; if (transformerLocation != null) { Source stylesource = new StreamSource(transformerLocation.toString()); transformer = tFactory.newTransformer(stylesource); } else transformer = tFactory.newTransformer(); String documentEncoding = d.getXmlEncoding(); ... |
void | serialize(Document doc) serialize TransformerFactory tf = TransformerFactory.newInstance(); Transformer t = tf.newTransformer(); DOMSource src = new DOMSource(doc); StreamResult res = new StreamResult(System.out); t.transform(src, res); |
void | serialize(Document doc, Writer out) serialize TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer = tf.newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.STANDALONE, "no"); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); ... |
String | serialize(Document document, boolean prettyPrint) serialize Writer writer = new StringWriter(); serialize(document, prettyPrint, writer); return writer.toString(); |
String | serialize(Document document, boolean prettyPrint) serialize DOMImplementationLS impl = getDOMImpl(); LSSerializer serializer = impl.createLSSerializer(); DOMConfiguration config = serializer.getDomConfig(); if (prettyPrint && config.canSetParameter("format-pretty-print", Boolean.TRUE)) { config.setParameter("format-pretty-print", true); config.setParameter("xml-declaration", true); LSOutput output = impl.createLSOutput(); ... |
void | serialize(Document document, File targetFile) serialize try { Transformer t = TransformerFactory.newInstance().newTransformer(); t.transform(new DOMSource(document), new StreamResult(targetFile)); } catch (TransformerException e) { throw new IOException(e); |
void | serialize(Document document, OutputStream ostream) serialize Source domSource = new DOMSource(document); try { Transformer serializer = TransformerFactory.newInstance().newTransformer(); try { serializer.setOutputProperty(OutputKeys.INDENT, "yes"); serializer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); serializer.setOutputProperty(OutputKeys.ENCODING, "UTF-16"); } catch (IllegalArgumentException e) { ... |