List of utility methods to do XML Node Transform
String | buildXml(Node node) build Xml StringWriter writer = new StringWriter(); buildXml(node, writer); return writer.toString(); |
boolean | copyTreeToResult(Node tree, Result result) Copy DOM tree to a SOAP tree. try { TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer = tFactory.newTransformer(); DOMSource source = new DOMSource(tree); transformer.transform(source, result); return true; } catch (TransformerConfigurationException tce) { tce.printStackTrace(); ... |
InputStream | createInputStream(Node node) create Input Stream ByteArrayOutputStream stream = new ByteArrayOutputStream(); TransformerFactory.newInstance().newTransformer().transform(new DOMSource(node), new StreamResult(stream)); return new ByteArrayInputStream(stream.toByteArray()); |
String | createXML(Node doc) create XML TransformerFactory xff = TransformerFactory.newInstance(); Transformer serializer = null; try { serializer = xff.newTransformer(); } catch (TransformerConfigurationException te) { throw new RuntimeException("Could not create transformer. " + te.getMessage()); serializer.setOutputProperty(OutputKeys.INDENT, "yes"); ... |
String | getAsText(Node n) get As Text try { Transformer t = TransformerFactory.newInstance().newTransformer(); StringWriter out = new StringWriter(); t.transform(new javax.xml.transform.dom.DOMSource(n), new javax.xml.transform.stream.StreamResult(out)); return out.toString(); } catch (Throwable t) { t.printStackTrace(); return null; ... |
String | getHumanReadableXml(final Node node) Converts the provided DOM Node to a pretty-printed XML-formatted string. StringWriter toReturn = new StringWriter(); try { Transformer transformer = getFactory().newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.STANDALONE, "yes"); transformer.transform(new DOMSource(node), new StreamResult(toReturn)); } catch (TransformerException e) { throw new IllegalStateException("Could not transform node [" + node.getNodeName() + "] to XML", e); ... |
String | getNodeValue(NodeList nodeList) get Node Value final Transformer serializer = TransformerFactory.newInstance().newTransformer(); serializer.setURIResolver(null); final StringBuilder buf = new StringBuilder(); for (int i = 0; i < nodeList.getLength(); i++) { final StringWriter sw = new StringWriter(); serializer.transform(new DOMSource(nodeList.item(i)), new StreamResult(sw)); String xml = sw.toString(); final Matcher matcher = HEADER_PATTERN.matcher(xml); ... |
String | getValueOfValueNode(Node n, boolean unescape) Method to get the value of "Value" node If return getValueOfValueNodeNoTrim(n, unescape).trim();
|
String | getXML(NodeList childNodes) get XML try { StringBuilder builder = new StringBuilder(); Transformer t = TransformerFactory.newInstance().newTransformer(); t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); for (int i = 0; i < childNodes.getLength(); i++) { StringWriter sw = new StringWriter(); t.transform(new DOMSource(childNodes.item(i)), new StreamResult(sw)); builder.append(sw.toString()); ... |
byte[] | nodeToByteArray(Node node) Returns a byte array from given node. Source source = new DOMSource(node); ByteArrayOutputStream out = new ByteArrayOutputStream(); Result result = new StreamResult(out); TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(); transformer.transform(source, result); return out.toByteArray(); |