Here you can find the source of serializeXmlObject(org.w3c.dom.Document docToSerialize)
Parameter | Description |
---|---|
docToSerialize | a parameter |
Parameter | Description |
---|---|
Exception | an exception |
public static String serializeXmlObject(org.w3c.dom.Document docToSerialize) throws Exception
//package com.java2s; public class Main { /**//from w w w .j av a 2 s.c o m * Serialize w3c dom document. * * @param docToSerialize * @return * @throws Exception */ public static String serializeXmlObject(org.w3c.dom.Document docToSerialize) throws Exception { // Get a factory (DOMImplementationLS) for creating a Load and Save object. org.w3c.dom.ls.DOMImplementationLS impl = (org.w3c.dom.ls.DOMImplementationLS) org.w3c.dom.bootstrap.DOMImplementationRegistry .newInstance().getDOMImplementation("LS"); // Use the factory to create an object (LSSerializer) used to // write out or save the document. org.w3c.dom.ls.LSSerializer writer = impl.createLSSerializer(); org.w3c.dom.DOMConfiguration config = writer.getDomConfig(); config.setParameter("xml-declaration", false); config.setParameter("format-pretty-print", Boolean.TRUE); // Use the LSSerializer to write out or serialize the document to a String. String serializedXML = writer.writeToString(docToSerialize); return serializedXML; } }