We're looking for a user researcher to understand the needs of developers and designers. Is this you or someone you know? Check out the post: https://mzl.la/2IGzdXS

XMLSerializer可以用来将一个DOM子树或者一个DOM文档转换成文本.XMLSerializer的HTML5规范在 DOM解析和序列化.

如果想要在Firefox扩展使用XMLSerializer,请使用更加强大的nsIDOMSerializer.

方法

serializeToString
返回DOM子树序列化后的字符串.
serializeToStream 已废弃 Gecko 20
将指定元素的每个子树按照特定的字符集序列化成字节流.

例子

 var s = new XMLSerializer();
 var d = document;
 var str = s.serializeToString(d);
 alert(str);

非标准
该特性是非标准的,请尽量不要在生产环境中使用它!

已废弃 Gecko 20 (Firefox 20 / Thunderbird 20 / SeaMonkey 2.17)
This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.

 var s = new XMLSerializer();
 var stream = {
   close : function()
   {
     alert("Stream closed");
   },
   flush : function()
   {
   },
   write : function(string, count)
   {
     alert("'" + string + "'\n bytes count: " + count + "");
   }
 };
 s.serializeToStream(document, stream, "UTF-8");

浏览器兼容性

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support (Yes) (Yes) 9.0 (Yes) ?
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support ? (Yes) ? ? ?

相关链接

文档标签和贡献者

此页面的贡献者: ziyunfei, teoli, zchong1022
最后编辑者: ziyunfei,