List of utility methods to do XML Transform
TransformerFactory | newTransformerFactory() new Transformer Factory factoryLock.lock(); try { return TransformerFactory.newInstance(); } finally { factoryLock.unlock(); |
TransformerFactory | newTransformerFactory() new Transformer Factory TransformerFactory factory = TransformerFactory.newInstance();
factory.setFeature(javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING, true);
return factory;
|
TransformerFactory | newTransformerFactory() Instantiate a new TransformerFactory. return AccessController.doPrivileged(new PrivilegedExceptionAction<TransformerFactory>() { public TransformerFactory run() throws Exception { try { return TransformerFactory.newInstance(); } catch (TransformerFactoryConfigurationError error) { throw error.getException(); }); |
TransformerHandler | newTransformerHandler() Return a TransformerHandler. TransformerHandler hd = tf.newTransformerHandler();
Transformer serializer = hd.getTransformer();
serializer.setOutputProperty(OutputKeys.ENCODING, UTF8);
serializer.setOutputProperty(OutputKeys.INDENT, YES);
serializer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, YES);
return hd;
|
TransformerHandler | newTransformerHandler() new Transformer Handler if (transformerFactory == null) { transformerFactory = (SAXTransformerFactory) SAXTransformerFactory.newInstance(); return transformerFactory.newTransformerHandler(); |
TransformerHandler | newTransformerHandler(final SAXTransformerFactory tf) Set up transformer to output full XML doc. final TransformerHandler resultHandler = tf.newTransformerHandler(); final Transformer transformer = resultHandler.getTransformer(); setUtfEncoding(transformer); setIndentFlag(transformer); setTransformerIndent(transformer); return resultHandler; |
byte[] | serializeXML(Transformer transformer, Source input) serialize XML StringWriter stringWriter = new StringWriter(); Result result = new StreamResult(stringWriter); transformer.transform(input, result); String streamString = stringWriter.getBuffer().toString(); byte[] byteArray = streamString.getBytes("UTF-8"); return byteArray; |
void | transform(byte[] doc, URL xsltUrl, OutputStream out) transform ByteArrayInputStream inputStream = new ByteArrayInputStream(doc);
transform(inputStream, xsltUrl, out);
|
void | transform(byte[] source, InputStream xslInputStream, File output) Executes the XSLT defined in xslInputStream to transform the source byte array into a file that is written to the descriptor provided by output try { ByteArrayInputStream input = new ByteArrayInputStream(source); StreamSource xslStream = new StreamSource(xslInputStream); FileWriter outputXml = new FileWriter(output); StreamSource in = new StreamSource(input); StreamResult out = new StreamResult(outputXml); TransformerFactory factory = TransformerFactory.newInstance(); Templates template = factory.newTemplates(xslStream); ... |
void | transform(File inputFile, Transformer transformer, Writer out) Transform XML according to the supplied transformer transform(new StreamSource(inputFile), transformer, out);
|