Java XML Document Serialize serializeDOM(Document doc)

Here you can find the source of serializeDOM(Document doc)

Description

serialize DOM

License

Apache License

Declaration

public static String serializeDOM(Document doc) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.StringWriter;

import org.w3c.dom.Document;
import org.w3c.dom.ls.DOMImplementationLS;
import org.w3c.dom.ls.LSOutput;
import org.w3c.dom.ls.LSSerializer;

public class Main {
    public static String serializeDOM(Document doc) {
        DOMImplementationLS domImplementation = (DOMImplementationLS) doc.getImplementation();
        LSSerializer lsSerializer = domImplementation.createLSSerializer();

        LSOutput output = domImplementation.createLSOutput();
        output.setEncoding("UTF-8");
        StringWriter stringOut = new StringWriter();
        output.setCharacterStream(stringOut);
        lsSerializer.write(doc, output);

        return stringOut.toString();
    }/*  w  w  w.ja  v a 2s. com*/
}

Related

  1. serializeDocument(Document doc)
  2. serializeDocument(Document doc, String filePath)
  3. serializeDocument(Document document)
  4. serializeDocument(Document document, OutputStream os)
  5. serializeDocument(Document root)
  6. serializeToByteArray(Document doc)
  7. serializeToString(org.w3c.dom.Document doc)
  8. serializeToStringLS(Document doc, Node node, String encoding)
  9. serializeXML(Document doc, Writer writer, boolean addXmlDeclaration)