Java XML String Transform getSourceAsString(Source source)

Here you can find the source of getSourceAsString(Source source)

Description

get Source As String

License

Open Source License

Declaration

public static String getSourceAsString(Source source) throws Exception 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
import javax.xml.soap.SOAPMessage;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;

public class Main {

    public static String getSourceAsString(Source source) throws Exception {

        Transformer transformer = TransformerFactory.newInstance()
                .newTransformer();/*ww w  . ja  v  a  2 s .  co  m*/

        OutputStream outputStream = new ByteArrayOutputStream();
        StreamResult streamResult = new StreamResult();
        streamResult.setOutputStream(outputStream);
        transformer.transform(source, streamResult);

        return streamResult.getOutputStream().toString();
    }

    public static String getSourceAsString(SOAPMessage sm) throws Exception {
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        sm.writeTo(stream);
        return stream.toString();

    }
}

Related

  1. getOutputMimeType(String xslName)
  2. getOutputSQLPageXML(String inStatement, Map map)
  3. getPropertyAsString(final Properties prop, final String comment)
  4. getSchema(String schemaString)
  5. getSchemaFromResource(String... files)
  6. getStreamResultForFile(String filename)
  7. getString(Node node, boolean indent)
  8. getStringFromStreamSource(StreamSource src)
  9. getTemplates(String name)