The XMLSerializer type converts a DOM document to a XML string. This type is used to perform a reverse operation of DOMParser. To serialize a DOM document, an instance of XMLSerializer is created and serializeToString() method is called. When a non-DOM object is passed to serialize, an error will be thrown. This feature is supported in IE 9+, Safari, Chrome, and Opera.

The example below converts a string to a DOM document. The string is retrieved from that DOM document back using the serializer.

Example of the XML Serializer type


›› go to examples ››