Serialization is the process of taking an in-memory DOM data structure such as a Document object and writing it out onto a stream as bytes or characters . DOM2 and earlier does not include any standard classes or interfaces for performing serialization. Consequently, every implementation of DOM must provide its own unique API for performing this necessary task. In Xerces, that need is filled by the XMLSerializer class. The OutputFormat class stores the various configuration options for an XMLSerializer , including encoding, white space added for "pretty printing," line separator, maximum line width, which elements to output using CDATA sections, and more.
DOM3 finally adds a standard set of serialization interfaces. The DOMWriter interface provides basic methods for serializing a Document object onto a stream or into a string. You can control the insignificant format of the output by setting various features, such as format-canonical and discard-default-content to either true or false. A DOMWriterFilter can control which nodes are output.