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

voidapplyXSLTTransform(final String xslt, final Reader input, final Writer output)
apply XSLT Transform
applyXSLTTransform(new StringReader(xslt), input, output);
TransformerbuildXmlTransformer()
build Xml Transformer
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
return transformer;
TransformercreateIndentingTransformer()
create Indenting Transformer
Transformer transformer;
try {
    TRANSFORMER_FACTORY.setAttribute("indent-number", 4);
    transformer = TRANSFORMER_FACTORY.newTransformer();
} catch (final Exception e) {
    throw new IllegalStateException(e);
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
...
TransformercreateOutputTransformer(String encoding, boolean omitXmlDeclaration, boolean indent, int indentAmount)
Creates a JAXP TrAX Transformer suitable for pretty-printing an XML document.
StringBuilder sb = new StringBuilder();
sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
sb.append(
        "<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" xmlns:xalan=\"http://xml.apache.org/xslt\" version=\"1.0\">\n");
sb.append("<xsl:output method=\"xml\" encoding=\"");
sb.append(encoding == null ? "UTF-8" : encoding);
sb.append("\"");
if (omitXmlDeclaration) {
...
TransformercreatePrettyTransformer(int indent)
Creates a Transformer with a configuration that affects the output of the transformed xml.
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", String.valueOf(indent));
return transformer;
TransformercreateTransformer()
Create a Transformer just the way we like it.
final Transformer xform;
try {
    xform = m_xformFactory.newTransformer();
} catch (TransformerConfigurationException e) {
    throw new IllegalStateException(e);
xform.setOutputProperty(OutputKeys.INDENT, "yes");
xform.setOutputProperty("{http://xml.apache.org/xalan}indent-amount", "2");
...
TransformercreateTransformer()
Create and returns a new Transformer.
initFactories();
final Transformer result;
try {
    result = transformerFactory.newTransformer();
} catch (TransformerConfigurationException e) {
    return null;
result.setOutputProperty(OutputKeys.METHOD, "xml");
...
TransformercreateTransformer()
Creates a Transformer instance.
Transformer xmlTransformer = TransformerFactory.newInstance().newTransformer();
xmlTransformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
xmlTransformer.setOutputProperty(OutputKeys.INDENT, "yes");
return xmlTransformer;
TransformercreateTransformer()
Creates and configures Transformer object
if (s_transformerFactory == null) {
    synchronized (TransformerFactory.class) {
        if (s_transformerFactory == null) {
            s_transformerFactory = TransformerFactory.newInstance();
Transformer transformer = s_transformerFactory.newTransformer();
...
TransformercreateTransformer(final File xsltFile)
create Transformer
return createTransformer(xsltFile, Collections.<String, String>emptyMap());