Java XML DOM to String domToString(Node domNode)

Here you can find the source of domToString(Node domNode)

Description

dom To String

License

Open Source License

Declaration

public static String domToString(Node domNode) throws TransformerException 

Method Source Code


//package com.java2s;
/*//from w  w w  . ja  va2s.  c o m
 * SafeOnline project.
 *
 * Copyright 2006 Lin.k N.V. All rights reserved.
 * Lin.k N.V. proprietary/confidential. Use is subject to license terms.
 */

import java.io.*;

import javax.xml.transform.*;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.w3c.dom.Node;

public class Main {
    public static String domToString(Node domNode) throws TransformerException {

        Source source = new DOMSource(domNode);
        StringWriter stringWriter = new StringWriter();
        Result result = new StreamResult(stringWriter);
        TransformerFactory transformerFactory = TransformerFactory.newInstance();
        Transformer transformer = transformerFactory.newTransformer();
        transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
        transformer.transform(source, result);
        return stringWriter.toString();
    }
}

Related

  1. domNode2String(Node node, boolean indent)
  2. domNodeListToString(NodeList nodeList)
  3. domNodeToString(Node node)
  4. domToString(Node domNode)
  5. domToString(Node domNode, boolean indent)
  6. domToString(Node node)
  7. domToString(Node node, int estSize)