Java tutorial
//package com.java2s; //License from project: Open Source License import org.w3c.dom.Document; import java.io.StringWriter; import javax.xml.transform.Templates; import javax.xml.transform.Result; import javax.xml.transform.Transformer; import javax.xml.transform.dom.DOMSource; import java.io.InputStream; import javax.xml.transform.stream.StreamSource; import java.io.Reader; public class Main { protected static Result internalTransform(Document doc, Templates templates, Result r, boolean trace) { StringWriter sw = new StringWriter(); try { Transformer transformer = templates.newTransformer(); transformer.transform(new DOMSource(doc), r); sw.close(); return r; } catch (Throwable th) { th.printStackTrace(); return r; } } protected static Result internalTransform(InputStream doc, Templates templates, Result r, boolean trace) { StringWriter sw = new StringWriter(); try { Transformer transformer = templates.newTransformer(); transformer.transform(new StreamSource(doc), r); sw.close(); return r; } catch (Throwable th) { th.printStackTrace(); return r; } } protected static Result internalTransform(Reader doc, Templates templates, Result r, boolean trace) { StringWriter sw = new StringWriter(); try { Transformer transformer = templates.newTransformer(); transformer.transform(new StreamSource(doc), r); sw.close(); return r; } catch (Throwable th) { th.printStackTrace(); return r; } } }