Java XML Document Transform transform(Document document, Properties outputProperties, StreamResult streamResult)

Here you can find the source of transform(Document document, Properties outputProperties, StreamResult streamResult)

Description

Main transformation method.

License

Open Source License

Parameter

Parameter Description
document the input XML Document object
outputProperties the properties to use for output
streamResult the object to be stored the transformation result

Declaration

public static void transform(Document document, Properties outputProperties, StreamResult streamResult)
        throws Exception 

Method Source Code


//package com.java2s;
import org.w3c.dom.Document;

import java.util.Enumeration;

import java.util.Properties;

import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

public class Main {
    /**//from  ww w.j a  va2  s  . co  m
     * Main transformation method. It transform the input document using the input properties
     * and returns the result into the input streamResult
     *
     * @param document         the input XML Document object
     * @param outputProperties the properties to use for output
     * @param streamResult     the object to be stored the transformation result
     */
    public static void transform(Document document, Properties outputProperties, StreamResult streamResult)
            throws Exception {
        TransformerFactory transFactory = TransformerFactory.newInstance();
        Transformer transformer = transFactory.newTransformer();
        if (outputProperties != null) {
            Enumeration<?> propertyNames = outputProperties.propertyNames();
            while (propertyNames.hasMoreElements()) {
                String propName = propertyNames.nextElement().toString();
                String propValue = outputProperties.getProperty(propName);
                if (propValue == null) {
                    continue;
                }
                transformer.setOutputProperty(propName, propValue);
            }
        }
        transformer.transform(new DOMSource(document), streamResult);
    }
}

Related

  1. transfer(Document doc, String filepath)
  2. transform(Document doc, Result result)
  3. transform(Document doc, Result result)
  4. transform(Document doc, StreamSource xslInput, String systemid)
  5. transform(Document dom, Document xslt)
  6. transform(final Document document, final StreamResult streamResult, final boolean xmlDeclaration)
  7. transform(Source xsl, Document doc)
  8. transformDoc(Document doc)