List of utility methods to do XML Document to String
String | toString(final Document document, final boolean indent, final boolean omitXmlDeclaration) to String final Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, omitXmlDeclaration ? "yes" : "no"); transformer.setOutputProperty(OutputKeys.INDENT, indent ? "yes" : "no"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); final StringWriter stringWriter = new StringWriter(); final StreamResult streamResult = new StreamResult(stringWriter); transformer.transform(new DOMSource(document), streamResult); ... |
String | toString(Node document) to String Transformer transformer; String output = null; if (document != null) try { transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); StreamResult result = new StreamResult(new StringWriter()); DOMSource source = new DOMSource(document); ... |
String | toStringFromDoc(Document document) to String From Doc String result = null; if (document != null) { StringWriter strWtr = new StringWriter(); StreamResult strResult = new StreamResult(strWtr); TransformerFactory tfac = TransformerFactory.newInstance(); try { javax.xml.transform.Transformer t = tfac.newTransformer(); t.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); ... |
String | toStructureString(Document document) to Structure String StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw, true); NodeList childNodes = document.getChildNodes(); printNodes(pw, childNodes, 0); return sw.toString(); |
String | toXML(Document document) Serializes a DOM Document to XML DOMImplementationLS domLS = (DOMImplementationLS) implementation;
LSSerializer serializer = domLS.createLSSerializer();
String s = serializer.writeToString(document);
return s;
|
String | toXML(Document dom) Exports this DOM as a String return toXML(dom, null);
|
String | toXml(Document domDoc) to Xml DOMImplementation domImplementation = domDoc.getImplementation(); if (domImplementation.hasFeature("LS", "3.0") && domImplementation.hasFeature("Core", "2.0")) { DOMImplementationLS domImplementationLS = (DOMImplementationLS) domImplementation.getFeature("LS", "3.0"); LSSerializer lsSerializer = domImplementationLS.createLSSerializer(); DOMConfiguration domConfiguration = lsSerializer.getDomConfig(); if (domConfiguration.canSetParameter("xml-declaration", Boolean.TRUE)) lsSerializer.getDomConfig().setParameter("xml-declaration", Boolean.FALSE); ... |
String | toXmlString(Document doc) to Xml String DOMSource domSource = new DOMSource(doc); StringWriter writer = new StringWriter(); StreamResult result = new StreamResult(writer); TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer = tf.newTransformer(); transformer.transform(domSource, result); writer.flush(); return writer.toString(); ... |
String | toXmlString(Document doc) to Xml String String xmlString = null; TransformerFactory transfac = TransformerFactory.newInstance(); Transformer trans = transfac.newTransformer(); trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); trans.setOutputProperty(OutputKeys.INDENT, "yes"); StringWriter sw = new StringWriter(); StreamResult result = new StreamResult(sw); DOMSource source = new DOMSource(doc); ... |
String | toXMLString(Document doc, boolean includeXMLDecl, boolean indent) to XML String String xmlString = null; try { TransformerFactory transfac = TransformerFactory.newInstance(); Transformer trans = transfac.newTransformer(); trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, includeXMLDecl ? "yes" : "no"); trans.setOutputProperty(OutputKeys.INDENT, indent ? "yes" : "no"); StringWriter sw = new StringWriter(); StreamResult result = new StreamResult(sw); ... |