Java XML Document Transform transformDoc(Document doc)

Here you can find the source of transformDoc(Document doc)

Description

transform Doc

License

Open Source License

Declaration

public static String transformDoc(Document doc) throws Exception 

Method Source Code


//package com.java2s;
import org.w3c.dom.Document;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import java.io.*;

public class Main {
    public static String transformDoc(Document doc) throws Exception {
        Transformer transformer = TransformerFactory.newInstance().newTransformer();
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");

        //initialize StreamResult with File object to save to file
        StreamResult result = new StreamResult(new StringWriter());
        DOMSource source = new DOMSource(doc);
        transformer.transform(source, result);

        return result.getWriter().toString();
    }/*www  .j  a v a  2  s  . c  om*/
}

Related

  1. transform(Document doc, StreamSource xslInput, String systemid)
  2. transform(Document document, Properties outputProperties, StreamResult streamResult)
  3. transform(Document dom, Document xslt)
  4. transform(final Document document, final StreamResult streamResult, final boolean xmlDeclaration)
  5. transform(Source xsl, Document doc)
  6. transformDocToFile(Document doc, File file)
  7. transformDocument(Document doc, String xsl, String targetFile)
  8. transformDocument(Document xmlDocument, String xsltFilename)
  9. transformDocumentAsString(Document xmlDocument, Map parameters, String xsltFilename)