Java XML Node Save writeByDom(Node node, Writer writer, int indent)

Here you can find the source of writeByDom(Node node, Writer writer, int indent)

Description

write By Dom

License

Open Source License

Declaration

private static void writeByDom(Node node, Writer writer, int indent) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import org.w3c.dom.Node;

import org.w3c.dom.ls.LSOutput;
import org.w3c.dom.ls.LSSerializer;
import org.w3c.dom.ls.DOMImplementationLS;
import org.w3c.dom.bootstrap.DOMImplementationRegistry;

import java.io.IOException;

import java.io.Writer;

public class Main {
    private static void writeByDom(Node node, Writer writer, int indent) throws IOException {
        try {/*  ww  w  . ja  va 2 s. c  o  m*/
            DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
            DOMImplementationLS domImpLS = (DOMImplementationLS) registry.getDOMImplementation("LS 3.0");

            LSOutput output = domImpLS.createLSOutput();
            output.setCharacterStream(writer);
            output.setEncoding("utf-8");

            LSSerializer serializer = domImpLS.createLSSerializer();
            serializer.setNewLine("\n");
            if (indent > 0) {
                serializer.getDomConfig().setParameter("format-pretty-print", Boolean.TRUE);
            }
            serializer.write(node, output);
        } catch (ClassNotFoundException e) {
            throw new IllegalStateException(e);
        } catch (InstantiationException e) {
            throw new IllegalStateException(e);
        } catch (IllegalAccessException e) {
            throw new IllegalStateException(e);
        }
    }
}

Related

  1. save(String filename, Node node)
  2. toResultSet(Node node, ResultSet rs)
  3. write(Node node, Writer out)
  4. writeDescription(PrintWriter out, Node node, String offSet)
  5. writeDOM(Node node, PrintWriter writer)
  6. writeNode(Node n, FileOutputStream o)
  7. writeNode(Node n, Writer w)