Here you can find the source of createXml(Document document)
Parameter | Description |
---|---|
document | the xml that needs to be converted. |
Parameter | Description |
---|---|
Exception | is there is some error during operation. |
public static String createXml(Document document) throws Exception
//package com.java2s; /*//from w w w .ja v a 2 s.c o m * Jitsi, the OpenSource Java VoIP and Instant Messaging client. * * Distributable under LGPL license. * See terms of license at gnu.org. */ import java.io.*; import javax.xml.transform.*; import javax.xml.transform.dom.*; import javax.xml.transform.stream.*; import org.w3c.dom.*; public class Main { /** * Creates XML from W3C Document from the xml. * * @param document the xml that needs to be converted. * @return the XML. * @throws Exception is there is some error during operation. */ public static String createXml(Document document) throws Exception { TransformerFactory transformerFactory = TransformerFactory .newInstance(); Transformer transformer = transformerFactory.newTransformer(); StringWriter stringWriter = new StringWriter(); StreamResult result = new StreamResult(stringWriter); DOMSource source = new DOMSource(document); transformer.transform(source, result); return stringWriter.toString(); } }