Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

XMLSerializer

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)

 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");

浏览器兼容性

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,