XMLSerializer can be used to convert a DOM subtree or DOM document into text. XMLSerializer is available to unprivileged scripts.
For more information about using XMLSerializer
in Firefox extensions, please see the documentation for nsIDOMSerializer
.
Methods
XMLSerializer.serializeToString
()- Returns the serialized subtree of a string.
XMLSerializer.serializeToStream()
- The subtree rooted by the specified element is serialized to a byte stream using the character set specified.
Examples
var s = new XMLSerializer(); var d = document; var str = s.serializeToString(d); alert(str);
The next example uses XMLSerializer with insertAdjacentHTML() to insert a newly created DOM Node into the Document's body. Because insertAdjacentHTML() accepts a string and not a Node for its second parameter, XMLSerializer is used to first convert the node into a string.
var inp = document.createElement('input'); var XMLS = new XMLSerializer(); var inp_xmls = XMLS.serializeToString(inp); // First convert DOM node into a string // Insert a newly created node into the document's body document.body.insertAdjacentHTML('afterbegin', inp_xmls);
Browser compatibility
See also
Document Tags and Contributors
Contributors to this page:
erikadoyle,
istocode,
teoli,
ziyunfei,
vyv03354,
Brettz9,
Konno.Software,
Imphil,
leandro_pintor,
Mgjbot,
The Hunter,
Chbok,
Nickolay,
Mw22
Last updated by:
erikadoyle,