XMLSerializer: XMLSerializer() constructor

The XMLSerializer() constructor creates a new XMLSerializer.

Syntax

js
new XMLSerializer()

Parameters

None.

Return value

A new XMLSerializer object.

Examples

Serializing XML into a string

This example serializes an entire document into a string containing XML.

js
const s = new XMLSerializer();
const d = document;
const str = s.serializeToString(d);
saveXML(str);

This involves creating a new XMLSerializer object, then passing the Document to be serialized into serializeToString(), which returns the XML equivalent of the document. saveXML() represents a function that would then save the serialized string.

Specifications

Specification
DOM Parsing and Serialization
# dom-xmlserializer-constructor

Browser compatibility

BCD tables only load in the browser