List of utility methods to do XML Transform
TransformerFactory | getXmlSecureTransformerFactory() get Xml Secure Transformer Factory TransformerFactory transFactory = TransformerFactory.newInstance();
transFactory.setFeature(javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
return transFactory;
|
Transformer | getXmlTransformer() get Xml Transformer initTransformer(); Transformer transformer = transformerFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); try { transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); } catch (IllegalArgumentException e) { ... |
Transformer | getXMLTransformer() get XML Transformer if (_xmlTransformer == null) { _xmlTransformer = TransformerFactory.newInstance().newTransformer(); _xmlTransformer.setOutputProperty(OutputKeys.INDENT, "yes"); return _xmlTransformer; |
Transformer | getXsltTransformer(File xsltFile) get Xslt Transformer try { return transformerFactory.newTransformer(new StreamSource(xsltFile)); } catch (TransformerConfigurationException e) { throw new RuntimeException(e); |
Result | internalTransformWithParams(Reader doc, Templates templates, Result r, boolean trace, String[] params) internal Transform With Params StringWriter sw = new StringWriter(); try { Transformer transformer = templates.newTransformer(); if (params != null && params.length > 0) { for (int i = 0; i < params.length; i++) transformer.setParameter("param_" + i, params[i]); transformer.transform(new StreamSource(doc), r); ... |
Transformer | newTransformer() new Transformer Transformer t = null; if (transformerFactory == null) transformerFactory = TransformerFactory.newInstance(); try { t = transformerFactory.newTransformer(); } catch (TransformerConfigurationException tex) { throw new IllegalStateException("Unable to create a JAXP transformer"); return t; |
Transformer | newTransformer() new Transformer TransformerFactory factory = TransformerFactory.newInstance(); try { factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, ""); } catch (IllegalArgumentException e) { try { factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, "all"); } catch (IllegalArgumentException e) { ... |
Transformer | newTransformer() new Transformer try { Transformer transformer = TransformerFactory.newInstance().newTransformer(); Properties properties = transformer.getOutputProperties(); properties.setProperty(OutputKeys.ENCODING, "gb2312"); properties.setProperty(OutputKeys.METHOD, "xml"); properties.setProperty(OutputKeys.VERSION, "1.0"); properties.setProperty(OutputKeys.INDENT, "no"); transformer.setOutputProperties(properties); ... |
Transformer | newTransformer(boolean indented) new Transformer String indentFlag = (indented) ? "yes" : "no"; try { TransformerFactory factory = TransformerFactory.newInstance(); factory.setAttribute("indent-number", DEFAULT_INDENT); Transformer transformer; transformer = factory.newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); transformer.setOutputProperty(OutputKeys.INDENT, indentFlag); ... |
Transformer | newTransformer(int indent) new Transformer TransformerFactory factory = newTransformerFactory(); factory.setAttribute("indent-number", Integer.valueOf(indent)); Transformer transformer = factory.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); return transformer; |