Here you can find the source of toXML(Node node)
Parameter | Description |
---|---|
node | the node |
public static String toXML(Node node)
//package com.java2s; /*/*from w w w. jav a2 s .c om*/ Copyright (c) 2009-2011, AOL Inc. All rights reserved. This code is licensed under a BSD license. */ import java.io.StringWriter; import javax.xml.transform.Result; import javax.xml.transform.Source; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import org.w3c.dom.Node; public class Main { /** * Xml to string. * * @param node * the node * * @return the string */ public static String toXML(Node node) { try { Source source = new DOMSource(node); StringWriter stringWriter = new StringWriter(); Result result = new StreamResult(stringWriter); TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(); transformer.transform(source, result); return stringWriter.getBuffer().toString(); } catch (Exception e) { } return null; } }