Java Utililty Methods XML Document to Stream

List of utility methods to do XML Document to Stream

Description

The list of methods to do XML Document to Stream are organized into topic(s).

Method

voidwriteDocument(Document doc, Transformer transformer, OutputStream out)
write xml document to output stream
Source src = new DOMSource(doc);
Result dest = new StreamResult(out);
transformer.transform(src, dest);
voidwriteDocument(Document document, OutputStream documentOutputStream)
Write the DOM Document to specified OutputStream
Result result = new StreamResult(documentOutputStream);
Transformer xformer = TransformerFactory.newInstance().newTransformer();
Source source = new DOMSource(document);
xformer.transform(source, result);
voidwriteDocument(Document document, OutputStream os)
writeDocument streams out given document to given output stream
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
DOMSource source = new DOMSource(document);
StreamResult result = new StreamResult(os);
transformer.transform(source, result);
voidwriteDocument(Document document, OutputStream outputStream)
write Document
defaultTransformer.transform(new DOMSource(document), new StreamResult(outputStream));
voidwriteDocument(OutputStream iStream, Element iElement)
write Document
TransformerFactory lTransformFactory = TransformerFactory.newInstance();
Transformer lTransformer = lTransformFactory.newTransformer();
DOMSource lSource = new DOMSource(iElement);
StreamResult lStreamResult = new StreamResult(iStream);
lTransformer.transform(lSource, lStreamResult);
voidwriteDocument(OutputStream os, Document document)
Writes the given document to the given output stream.
getImplementation();
DOMImplementationLS implLS = (DOMImplementationLS) impl;
LSOutput output = implLS.createLSOutput();
output.setByteStream(os);
LSSerializer serializer = implLS.createLSSerializer();
serializer.getDomConfig().setParameter("format-pretty-print", true);
serializer.write(document, output);
voidwriteDocument(OutputStream os, Node node)
Writes the given node to the given output stream.
getImplementation();
DOMImplementationLS implLS = (DOMImplementationLS) impl;
LSOutput output = implLS.createLSOutput();
output.setByteStream(os);
LSSerializer serializer = implLS.createLSSerializer();
serializer.getDomConfig().setParameter("format-pretty-print", true);
serializer.write(node, output);
voidwriteDocument(OutputStream stream, Document document)
write Document
Source input = new DOMSource(document);
StreamResult output = new StreamResult(stream);
TransformerFactory xFormFactory = TransformerFactory.newInstance();
Transformer idTransform = xFormFactory.newTransformer();
idTransform.transform(input, output);
voidwriteDOMDocumentToStream(Document doc, OutputStream stream)
Serialises a DOM document to a stream.
DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(stream);
getXMLTransformer().transform(source, result);
voidwriteOutDocument(OutputStream os, Document doc)
write Out Document
DOMSource source = new DOMSource(doc);
StreamResult sResult = new StreamResult(os);
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer t = tFactory.newTransformer();
t.setOutputProperty(OutputKeys.ENCODING, "utf-8");
t.setOutputProperty(OutputKeys.METHOD, "xml");
t.setOutputProperty(OutputKeys.INDENT, "yes");
t.transform(source, sResult);
...