List of utility methods to do XML Transform
String | transform(String xmlsource, File xsltfile) transform Source xmlSource = new StreamSource(new StringReader(xmlsource)); Source xsltSource = new StreamSource(xsltfile); StringWriter stringWriter = new StringWriter(); TransformerFactory transFact = TransformerFactory.newInstance(); Templates cachedXSLT = transFact.newTemplates(xsltSource); Transformer trans = cachedXSLT.newTransformer(); trans.transform(xmlSource, new StreamResult(stringWriter)); return stringWriter.toString(); ... |
Node | transform(String xslSource, Node original) transform StringReader sr = new StringReader(xslSource); DOMResult result = new DOMResult(); doTransform(new StreamSource(sr), new DOMSource(original), result); return result.getNode(); |
String | transform(Transformer transformer, Node element) transform StreamResult result = new StreamResult(new StringWriter()); DOMSource source = new DOMSource(element); transformer.transform(source, result); String xmlString = result.getWriter().toString(); return xmlString; |
String | transformar(String xmlOrigen, String xslOrigen) transformar InputStream is = new ByteArrayInputStream(xmlOrigen.getBytes("UTF-8")); Source xmlSource = new StreamSource(is); Source xsltSource = new StreamSource(new File(xslOrigen)); StringWriter cadenaSalida = new StringWriter(); Result bufferResultado = new StreamResult(cadenaSalida); TransformerFactory factoriaTrans = TransformerFactory.newInstance(); Transformer transformador = factoriaTrans.newTransformer(xsltSource); transformador.transform(xmlSource, bufferResultado); ... |
Transformer | transformer() transformer TransformerFactory tf = TRANSFORMER_FACTORY.get(); if (tf == null) { tf = TransformerFactory.newInstance(); TRANSFORMER_FACTORY.set(tf); return tf.newTransformer(); |
void | transformerExceptionMsg(TransformerException ex, Node contextNode, String str) transformer Exception Msg System.out.println("[XPathUtil] Transformer exception selecting " + "XObject for " + "XPath String " + str + " with context node " + nodeToString(contextNode) + ": " + ex); |
TransformerFactory | transformerFactory() a bit of boilerplate final TransformerFactory tf = TransformerFactory.newInstance(); return tf; |
void | transformFile(Source stylesheetFile, File input, File output) transform File TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(stylesheetFile); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.transform(new StreamSource(input), new StreamResult(output)); |
String | transformLogViaXSLT(String logFilePath, String xslFilePath) transform Log Via XSLT ByteArrayOutputStream baos = new ByteArrayOutputStream(); File logFile = new File(logFilePath); if (logFile.exists()) { File xslFile = new File(xslFilePath); if (xslFile.exists()) { TransformerFactory factory = TransformerFactory.newInstance(); Source xslt = new StreamSource(new File(xslFilePath)); Transformer transformer = factory.newTransformer(xslt); ... |
void | transformNonTextNodeToOutputStream(Node node, OutputStream os, boolean omitXmlDeclaration) transform Non Text Node To Output Stream TransformerFactory tf = TransformerFactory.newInstance(); Transformer trans = tf.newTransformer(); if (omitXmlDeclaration) { trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); trans.transform(new DOMSource(node), new StreamResult(os)); |