Here you can find the source of getDocumentAsString(Document doc)
public static String getDocumentAsString(Document doc) throws TransformerException
//package com.java2s; /**/*ww w.ja v a 2 s . c o m*/ * Copyright (C) 2013 Inera AB (http://www.inera.se) * * This file is part of Inera MessageService (http://code.google.com/p/inera-message). * * Inera MessageService is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Inera MessageService is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import java.io.StringWriter; import javax.xml.transform.*; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import org.w3c.dom.Document; public class Main { private static TransformerFactory tf; public static String getDocumentAsString(Document doc) throws TransformerException { StringWriter sw = new StringWriter(); tf.newTransformer().transform(new DOMSource(doc), new StreamResult(sw)); return sw.toString(); } }