Here you can find the source of transform(Document document, Properties outputProperties, StreamResult streamResult)
Parameter | Description |
---|---|
document | the input XML Document object |
outputProperties | the properties to use for output |
streamResult | the object to be stored the transformation result |
public static void transform(Document document, Properties outputProperties, StreamResult streamResult) throws Exception
//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); } }