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

DOMResulttransform(SOAPPart part)
transform
Transformer trans = TransformerFactory.newInstance().newTransformer();
DOMResult rs = new DOMResult();
trans.transform(part.getContent(), rs);
return rs;
voidtransform(Source source, Result res)
transform
TransformerFactory.newInstance().newTransformer().transform(source, res);
voidtransform(Source source, Result result)
transform
transform(source, result, false);
Stringtransform(Source source, Source stylesheet, Map params, Properties outputProperties)
This method performs XSL Transformation.
try {
    TransformerFactory factory = TransformerFactory.newInstance();
    Transformer transformer = factory.newTransformer(stylesheet);
    if (outputProperties != null) {
        transformer.setOutputProperties(outputProperties);
    if (params != null) {
        transformer.clearParameters();
...
Documenttransform(Source source, Templates cachedXSLT)
Transforms the given XML input stream using the specified cached XSLT stylesheet.
DocumentBuilder builder = DOC_FACT.newDocumentBuilder();
Document document = builder.newDocument();
Result result = new DOMResult(document);
Transformer trans = cachedXSLT.newTransformer();
trans.transform(source, result);
return document;
voidtransform(Source xmlSource, Result outputTarget)
transform
Transformer t = transformer();
try {
    t.transform(xmlSource, outputTarget);
} finally {
    t.reset();
voidtransform(Source xmlSource, Templates template, Result result, Map parameters)
Transform the XML to result.
Transformer transformer = template.newTransformer();
if (parameters != null) {
    for (String key : parameters.keySet()) {
        transformer.setParameter(key, parameters.get(key));
transformer.setOutputProperty(OutputKeys.INDENT, "no");
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
...
voidtransform(Source xsl, Source xml, Result result)
Perform an xsl transformation
TransformerFactory factory = TransformerFactory.newInstance();
Templates template = factory.newTemplates(xsl);
Transformer transformer = template.newTransformer();
transformer.transform(xml, result);
voidtransform(String xmlInputFile, String xsltInputFile, OutputStream outputStream)
Transform.
File xmlFile = new File(xmlInputFile);
File xsltFile = new File(xsltInputFile);
transform(xmlFile, xsltFile, outputStream);
Stringtransform(String xmlInURI, String xslInURI)
transform
String retValue = null;
try {
    TransformerFactory tFactory = TransformerFactory.newInstance();
    Templates translet = tFactory.newTemplates(new StreamSource(xslInURI));
    Transformer transformer = translet.newTransformer();
    DocumentBuilderFactory docFact = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuild = docFact.newDocumentBuilder();
    Document doc = docBuild.parse(xmlInURI);
...