List of utility methods to do XML Document Transform
void | transfer(Document doc, String filepath) transfer try { Transformer tf = tff.newTransformer(); DOMSource source = new DOMSource(doc); StreamResult result = new StreamResult(filepath); tf.transform(source, result); } catch (TransformerConfigurationException e) { e.printStackTrace(); } catch (TransformerException e) { ... |
void | transform(Document doc, Result result) transform try { Source source = new DOMSource(doc); Transformer xformer = TransformerFactory.newInstance().newTransformer(); xformer.setOutputProperty(OutputKeys.INDENT, "yes"); xformer.transform(source, result); } catch (Exception e) { e.printStackTrace(); |
void | transform(Document doc, Result result) transform try { Source source = new DOMSource(doc); Transformer xformer = TransformerFactory.newInstance().newTransformer(); xformer.setOutputProperty(OutputKeys.INDENT, "yes"); xformer.transform(source, result); } catch (TransformerConfigurationException e) { e.printStackTrace(); throw e; ... |
Node | transform(Document doc, StreamSource xslInput, String systemid) Purpose: XML transformation using XSL TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer = tFactory.newTransformer(xslInput); DOMResult domResult = new DOMResult(); DOMSource xmlDomSource = null; xmlDomSource = new DOMSource(doc); xmlDomSource.setSystemId(systemid); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); ... |
void | transform(Document document, Properties outputProperties, StreamResult streamResult) Main transformation method. TransformerFactory transFactory = TransformerFactory.newInstance(); Transformer transformer = transFactory.newTransformer(); if (outputProperties != null) { Enumeration<?> propertyNames = outputProperties.propertyNames(); while (propertyNames.hasMoreElements()) { String propName = propertyNames.nextElement().toString(); String propValue = outputProperties.getProperty(propName); if (propValue == null) { ... |
Document | transform(Document dom, Document xslt) transform try { DOMSource xsltSource = new DOMSource(xslt); Transformer transformer = transFactory.newTransformer(xsltSource); DOMSource source = new DOMSource(dom); Document out = newDocument(); DOMResult result = new DOMResult(out); transformer.transform(source, result); return out; ... |
void | transform(final Document document, final StreamResult streamResult, final boolean xmlDeclaration) Transform. if (document == null) { throw new IllegalArgumentException("document cannot be NULL!"); if (streamResult == null) { throw new IllegalArgumentException("streamResult cannot be NULL!"); Transformer transformer; try { ... |
String | transform(Source xsl, Document doc) transform StringWriter writer = new StringWriter(); try { TransformerFactory.newInstance().newTransformer(xsl).transform(new DOMSource(doc), new StreamResult(writer)); } catch (Exception e) { return writer.toString(); |
String | transformDoc(Document doc) transform Doc Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); StreamResult result = new StreamResult(new StringWriter()); DOMSource source = new DOMSource(doc); transformer.transform(source, result); return result.getWriter().toString(); |
File | transformDocToFile(Document doc, File file) transform Doc To File final TransformerFactory tf = TransformerFactory.newInstance(); final Transformer transformer = tf.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); transformer.transform(new DOMSource(doc), new StreamResult(file)); return file; |