List of utility methods to do XML Node to String
String | toXMLString(Node node) Convert an XML node to a string. Transformer transformer = null; try { transformer = tFactory.newTransformer(); } catch (TransformerConfigurationException e) { e.printStackTrace(); DOMSource source = new DOMSource(node); StringWriter xmlWriter = new StringWriter(); ... |
String | toXMLString(Node node, boolean header) Returns a String representation of the DOM hierarchy rooted at the argument Node. try { Source source = new DOMSource(node); StringWriter stringWriter = new StringWriter(); Result result = new StreamResult(stringWriter); TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(); if (!header) transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); ... |
void | writeXml(Node n, OutputStream os) write Xml TransformerFactory tf = TransformerFactory.newInstance(); Transformer t = tf.newTransformer(); t.setOutputProperty(OutputKeys.INDENT, "yes"); t.transform(new DOMSource(n), new StreamResult(os)); |
String | xml(Node node) xml TransformerFactory factory = TransformerFactory.newInstance();
return xml(factory, node);
|
String | XML2String(Node node) XML String try { StringWriter writer = new StringWriter(); Transformer trans = TransformerFactory.newInstance().newTransformer(); trans.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); Source source = new DOMSource(node); Result result = new StreamResult(writer); trans.transform(source, result); return writer.toString(); ... |
byte[] | xmlToBytes(final Node body) xml To Bytes final Transformer transformer = FACTORY.newTransformer(); final Source source = new DOMSource(body); final ByteArrayOutputStream buffer = new ByteArrayOutputStream(); final Result result = new StreamResult(buffer); transformer.transform(source, result); return buffer.toByteArray(); |
Source | XmlToSource(Node node) Xml To Source Source source = new DOMSource(node); return source; |
void | xmlToStream(Node n, OutputStream os) xml To Stream Source source = new DOMSource(n); Result result = new StreamResult(os); Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.transform(source, result); |
void | xmlToStreamE(Node n, OutputStream os) xml To Stream E try { Source source = new DOMSource(n); Result result = new StreamResult(os); Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.transform(source, result); } catch (IllegalArgumentException | TransformerException e) { throw new Error(e); ... |
String | xmlToString(Node doc) xml To String try { DOMSource domSource = new DOMSource(doc); StringWriter writer = new StringWriter(); StreamResult result = new StreamResult(writer); TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer = tf.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.transform(domSource, result); ... |