List of utility methods to do XML DOM to String
String | domNode2String(Node node, boolean indent) Returns the String-Representation of the given DOM-Node as well-formed DOM-Document. Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, indent ? "yes" : "no"); StreamResult result = new StreamResult(new StringWriter()); DOMSource source = new DOMSource(node); transformer.transform(source, result); String xmlString = result.getWriter().toString(); return xmlString; |
String | domNodeListToString(NodeList nodeList) dom Node List To String StringBuilder sb = new StringBuilder(); for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); sb.append(domNodeToString(node)); return sb.toString(); |
String | domNodeToString(Node node) dom Node To String StringWriter writer = new StringWriter(); Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); transformer.transform(new DOMSource(node), new StreamResult(writer)); return writer.toString(); |
String | domToString(Node domNode) Transforms a DOM node (e.g. return domToString(domNode, false);
|
String | domToString(Node domNode) dom To String Source source = new DOMSource(domNode); StringWriter stringWriter = new StringWriter(); Result result = new StreamResult(stringWriter); TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); transformer.transform(source, result); return stringWriter.toString(); ... |
String | domToString(Node domNode, boolean indent) Convert specified DOM Node to a string representation try { Source source = new DOMSource(domNode); StringWriter stringWriter = new StringWriter(); Result result = new StreamResult(stringWriter); TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); ... |
String | domToString(Node node) dom To String try { TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer = tf.newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); StringWriter writer = new StringWriter(); transformer.transform(new DOMSource(node), new StreamResult(writer)); return writer.toString(); } catch (TransformerException te) { ... |
String | domToString(Node node, int estSize) dom To String String retVal = null; if (node != null) { StringWriter sw = new StringWriter(estSize); xtrans.transform(new DOMSource(node), new StreamResult(sw)); retVal = sw.toString(); sw.close(); return retVal; ... |