1 | |
package org.apache.ws.scout.util; |
2 | |
|
3 | |
import java.io.StringWriter; |
4 | |
|
5 | |
import javax.xml.transform.Source; |
6 | |
import javax.xml.transform.Transformer; |
7 | |
import javax.xml.transform.TransformerConfigurationException; |
8 | |
import javax.xml.transform.TransformerException; |
9 | |
import javax.xml.transform.TransformerFactory; |
10 | |
import javax.xml.transform.dom.DOMSource; |
11 | |
import javax.xml.transform.stream.StreamResult; |
12 | |
|
13 | |
import org.apache.commons.logging.Log; |
14 | |
import org.apache.commons.logging.LogFactory; |
15 | |
import org.w3c.dom.Node; |
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | 0 | public class XMLUtils { |
22 | 0 | private static Log log = LogFactory.getLog(XMLUtils.class); |
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
public static String convertNodeToXMLString(Node node) |
30 | |
{ |
31 | 0 | String xml=null; |
32 | |
try { |
33 | 0 | Source source = new DOMSource(node); |
34 | 0 | StringWriter stringWriter = new StringWriter(); |
35 | 0 | javax.xml.transform.Result result = new StreamResult(stringWriter); |
36 | 0 | TransformerFactory factory = TransformerFactory.newInstance(); |
37 | 0 | Transformer transformer = factory.newTransformer(); |
38 | 0 | transformer.transform(source, result); |
39 | 0 | xml=stringWriter.getBuffer().toString(); |
40 | 0 | } catch (TransformerConfigurationException e) { |
41 | 0 | log.error("Could not obtain the XML. ", e); |
42 | 0 | } catch (TransformerException e) { |
43 | 0 | log.error("Could not obtain the XML. ",e); |
44 | 0 | } |
45 | 0 | return xml; |
46 | |
} |
47 | |
} |