List of utility methods to do XML Node to String
String | GetOuterXml(Node node) Gets the outerXML from a Node Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty("omit-xml-declaration", "yes"); StringWriter writer = new StringWriter(); transformer.transform(new DOMSource(node), new StreamResult(writer)); return writer.toString(); |
String | getStringFromDocument(Node doc) get String From Document try { 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); return writer.toString(); ... |
String | getStringFromNode(Node node) get String From Node StringWriter writer = new StringWriter(); Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); transformer.transform(new DOMSource(node), new StreamResult(writer)); String xml = writer.toString(); return xml; |
String | getStringFromNode(Node node) Converts a node to a string. DOMSource domSource = new DOMSource(node); ByteArrayOutputStream baos = null; try { baos = new ByteArrayOutputStream(); StreamResult result = new StreamResult(baos); TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); transformer.transform(domSource, result); ... |
String | getStringFromXML(Node node) get String From XML return getStringFromXML(node, null);
|
String | getText(final Node node) get Text final StringBuilder result = new StringBuilder(); if (!node.hasChildNodes()) return ""; final NodeList list = node.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { Node subnode = list.item(i); if (subnode.getNodeType() == Node.TEXT_NODE) { result.append(subnode.getNodeValue()); ... |
String | getXml(Node node) Returns a string that represents the given node. try { Transformer tf = TransformerFactory.newInstance().newTransformer(); tf.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); tf.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); StreamResult dest = new StreamResult(new StringWriter()); tf.transform(new DOMSource(node), dest); return dest.getWriter().toString(); } catch (Exception e) { ... |
String | getXmlAsString(Node node) get Xml As String Transformer transformer = getTransformer(); DOMSource source = new DOMSource(node); StringWriter xmlString = new StringWriter(); StreamResult streamResult = new StreamResult(xmlString); transformer.transform(source, streamResult); return xmlString.toString(); |
String | getXMLString(Node doc) get 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); return writer.toString(); |
String | getXmlString(Node n) get Xml String Transformer serializer = null; try { serializer = TransformerFactory.newInstance().newTransformer(); serializer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); StringWriter sw = new StringWriter(); StreamResult out = new StreamResult(sw); serializer.transform(new DOMSource(n), out); String result = ((StringWriter) out.getWriter()).getBuffer().toString(); ... |