List of utility methods to do XML Document to String
String | toString(Document doc) Converts an XML document to a formatted XML string. if (doc == null) { return ""; try { DOMSource domSource = new DOMSource(doc); StringWriter writer = new StringWriter(); StreamResult result = new StreamResult(writer); TransformerFactory tf = TransformerFactory.newInstance(); ... |
String | toString(Document doc) This method is used to convert a Document object into an XML String. Transformer transformer = TransformerFactory.newInstance().newTransformer(); DOMSource source = new DOMSource(doc); try { ByteArrayOutputStream output = new ByteArrayOutputStream(); StreamResult result = new StreamResult(output); transformer.transform(source, result); return new String(output.toByteArray(), "UTF-8"); } catch (Exception e) { ... |
String | toString(Document doc, String encoding, boolean indent) to String Source source = new DOMSource(doc); StringWriter sw = new StringWriter(); Result result = new StreamResult(sw); Transformer xformer = TransformerFactory.newInstance().newTransformer(); xformer.setOutputProperty(OutputKeys.ENCODING, encoding); if (indent) { xformer.setOutputProperty(OutputKeys.INDENT, "yes"); xformer.transform(source, result); return sw.getBuffer().toString(); |
String | toString(Document document) to String ByteArrayOutputStream out = null; try { out = new ByteArrayOutputStream(); defaultTextTransformer.transform(new DOMSource(document), new StreamResult(out)); return new String(out.toByteArray(), "UTF-8"); } catch (TransformerConfigurationException e) { throw new RuntimeException(e); } catch (TransformerException e) { ... |
String | toString(Document document) to String PrintStream out = null; try { ByteArrayOutputStream baos = new ByteArrayOutputStream(2048); out = new PrintStream(baos); print(out, document); return new String(baos.toByteArray(), "UTF-8"); } catch (Exception ex) { } finally { ... |
String | toString(Document document) to String return toString((Node) document);
|
String | toString(Document document) to String StringWriter writer = new StringWriter(); TransformerFactory factory = TransformerFactory.newInstance(); 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.transform(new DOMSource(document), new StreamResult(writer)); ... |
String | toString(Document document) convert org.w3c.dom.Document to xml-String Source source = new DOMSource(document); StringWriter stringWriter = new StringWriter(); Result result = new StreamResult(stringWriter); TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(); transformer.transform(source, result); return stringWriter.getBuffer().toString(); |
String | toString(final Document document) Transform document to string representation. final StringWriter stringWriter = new StringWriter(); final StreamResult streamResult = new StreamResult(stringWriter); final Transformer transformer = TRANSFORMER_FACTORY.get().newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, TRANSFORMER_YES); transformer.setOutputProperty("{http://xml.apache.org/xalan}indent-amount", "2"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, TRANSFORMER_YES); ... |
String | toString(final Document document) to String try { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final TransformerFactory tf = TransformerFactory.newInstance(); final Transformer transformer = tf.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.STANDALONE, "yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); transformer.transform(new DOMSource(document), new StreamResult(baos)); ... |