Java Utililty Methods XML Transform

List of utility methods to do XML Transform

Description

The list of methods to do XML Transform are organized into topic(s).

Method

TransformerFactorygetXmlSecureTransformerFactory()
get Xml Secure Transformer Factory
TransformerFactory transFactory = TransformerFactory.newInstance();
transFactory.setFeature(javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
return transFactory;
TransformergetXmlTransformer()
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) {
...
TransformergetXMLTransformer()
get XML Transformer
if (_xmlTransformer == null) {
    _xmlTransformer = TransformerFactory.newInstance().newTransformer();
    _xmlTransformer.setOutputProperty(OutputKeys.INDENT, "yes");
return _xmlTransformer;
TransformergetXsltTransformer(File xsltFile)
get Xslt Transformer
try {
    return transformerFactory.newTransformer(new StreamSource(xsltFile));
} catch (TransformerConfigurationException e) {
    throw new RuntimeException(e);
ResultinternalTransformWithParams(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);
...
TransformernewTransformer()
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;
TransformernewTransformer()
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) {
...
TransformernewTransformer()
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);
...
TransformernewTransformer(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);
...
TransformernewTransformer(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;