W3cubDocs

/Web APIs

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

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
XMLSerializer 1 12 1 9 ≤12.1 3 4.4 18 4 ≤12.1 1 1.0

© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/XMLSerializer/XMLSerializer