List of utility methods to do XML Document to String
String | documentToString(Document document) Uses a TransformerFactory with an identity transformation to convert a Document into a String representation of the XML. String xml = null; try { DOMSource dom = new DOMSource(document); StringWriter writer = new StringWriter(); StreamResult output = new StreamResult(writer); TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, INDENT_XML); ... |
String | documentToString(Document document) document To String TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer; try { transformer = tf.newTransformer(); } catch (TransformerConfigurationException e) { throw new RuntimeException(e); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); ... |
String | documentToString(Document document) document To String try { Transformer trans = tf.newTransformer(); StringWriter sw = new StringWriter(); trans.transform(new DOMSource(document), new StreamResult(sw)); return sw.toString(); } catch (TransformerException tEx) { tEx.printStackTrace(); return null; |
String | documentToString(Document document) document To String try { TransformerFactory tf = TransformerFactory.newInstance(); Transformer trans = tf.newTransformer(); StringWriter sw = new StringWriter(); trans.transform(new DOMSource(document), new StreamResult(sw)); return sw.toString(); } catch (TransformerException tEx) { tEx.printStackTrace(); ... |
String | documentToString(Document document) document To String return documentToString(document, true);
|
String | documentToString(Document document, boolean pretty) Convert the given Document to an XML String. if (document == null) { return ""; return nodeToString(document.getFirstChild(), pretty); |
String | documentToString(Document document, boolean standalone) document To String String prol = "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"" + (standalone ? "yes" : "no") + "\"?>"; return prol + nodeToString(document.getDocumentElement(), new HashSet(), document.getDocumentElement().getNamespaceURI()); |
String | documentToString(Document document, Transformer documentTransformer) Converts a document object to an xml string StringWriter sw = new StringWriter(); StreamResult result = new StreamResult(sw); DOMSource source = new DOMSource(document); documentTransformer.transform(source, result); return sw.toString(); |
String | DocumentToString(Document dom) Parses org.w3c.dom.Document and returns its xml serialization as String String xmlString = null; try { Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); StreamResult result = new StreamResult(new StringWriter()); DOMSource source = new DOMSource(dom); transformer.transform(source, result); xmlString = result.getWriter().toString(); ... |
String | documentToString(final Node node) Converts the given document to string format by passing it through a transformer. final TransformerFactory transformerFactory; final Transformer transformer; final DOMSource source; final StreamResult result; final StringWriter writer; writer = new StringWriter(BUFFER_CAPACITY); transformerFactory = TransformerFactory.newInstance(); transformer = transformerFactory.newTransformer(); ... |