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

voidwriteXML(final Document doc, final OutputStream out)
write XML
final TransformerFactory factory = TransformerFactory.newInstance();
factory.setFeature(javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING, true);
final Transformer transformer = factory.newTransformer();
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
...
voidwriteXML(OutputStream os, Document doc)
Writes the specified DOM to the given output stream.
Transformer idTransform = TRANS_FACT.newTransformer();
Source input = new DOMSource(doc);
Result output = new StreamResult(os);
idTransform.transform(input, output);
voidwriteXml(OutputStream outputEntry, Document document)
write Xml
writeXml(createIndentingTransformer(), outputEntry, document);
voidwriteXmlDocumentToStream(Document document, OutputStream stream)
Write a DOM document to an OutputStream
Source source = new DOMSource(document);
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer();
StreamResult result = new StreamResult(stream);
transformer.transform(source, result);
stream.flush();