XMLSerializer

  • 版本网址缩略名: XMLSerializer
  • 版本标题: XMLSerializer
  • 版本 id: 346519
  • 创建于:
  • 创建者: ziyunfei
  • 是否是当前版本?
  • 评论

修订内容

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

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

方法

serializeToString
返回DOM子树序列化后的字符串.
serializeToStream {{ non-standard_inline() }}{{ obsolete_inline("20") }}
将指定元素的每个子树按照特定的字符集序列化成字节流.

例子

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

{{ non-standard_header() }} {{ obsolete_header("20") }}

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

浏览器兼容性

{{CompatibilityTable}}
Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support {{CompatVersionUnknown}} {{CompatVersionUnknown}} 9.0 {{CompatVersionUnknown}} {{CompatUnknown}}
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support {{CompatUnknown}} {{CompatVersionUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}

相关链接

修订版来源

<div dir="ltr" id="result_box" style="text-align: left;">
  XMLSerializer可以用来将一个DOM子树或者一个DOM文档转换成文本.XMLSerializer的HTML5规范在 <a class="external" href="http://html5.org/specs/dom-parsing.html" title="http://html5.org/specs/dom-parsing.html">DOM解析和序列化</a>.</div>
<p>如果想要在Firefox扩展使用<code>XMLSerializer</code>,请使用更加强大的<a href="/zh-CN/docs/nsIDOMSerializer" title="nsIDOMSerializer"><code>nsIDOMSerializer</code></a>.</p>
<h2 id="Methods" name="Methods">方法</h2>
<dl>
  <dt id="serializeToString">
    serializeToString</dt>
  <dd>
    返回DOM子树序列化后的字符串.</dd>
  <dt id="serializeToStream">
    serializeToStream {{ non-standard_inline() }}{{ obsolete_inline("20") }}</dt>
  <dd>
    将指定元素的每个子树按照特定的字符集序列化成字节流.</dd>
</dl>
<h2 id="Examples" name="Examples">例子</h2>
<pre class="brush: js">
 var s = new XMLSerializer();
 var d = document;
 var str = s.serializeToString(d);
 alert(str);
</pre>
<p>{{ non-standard_header() }} {{ obsolete_header("20") }}</p>
<pre class="brush: js">
 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");
</pre>
<h2 id="Browser_compatibility" name="Browser_compatibility">浏览器兼容性</h2>
<div>
  {{CompatibilityTable}}</div>
<div id="compat-desktop">
  <table class="compat-table">
    <tbody>
      <tr>
        <th>Feature</th>
        <th>Chrome</th>
        <th>Firefox (Gecko)</th>
        <th>Internet Explorer</th>
        <th>Opera</th>
        <th>Safari (WebKit)</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td>{{CompatVersionUnknown}}</td>
        <td>{{CompatVersionUnknown}}</td>
        <td>9.0</td>
        <td>{{CompatVersionUnknown}}</td>
        <td>{{CompatUnknown}}</td>
      </tr>
    </tbody>
  </table>
</div>
<div id="compat-mobile">
  <table class="compat-table">
    <tbody>
      <tr>
        <th>Feature</th>
        <th>Android</th>
        <th>Firefox Mobile (Gecko)</th>
        <th>IE Mobile</th>
        <th>Opera Mobile</th>
        <th>Safari Mobile</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td>{{CompatUnknown}}</td>
        <td>{{CompatVersionUnknown}}</td>
        <td>{{CompatUnknown}}</td>
        <td>{{CompatUnknown}}</td>
        <td>{{CompatUnknown}}</td>
      </tr>
    </tbody>
  </table>
</div>
<h2 id=".E7.9B.B8.E5.85.B3.E9.93.BE.E6.8E.A5">相关链接</h2>
<ul>
  <li><a href="/zh-CN/Parsing_and_serializing_XML" title="zh-CN/Parsing_and_serializing_XML">Parsing and serializing XML</a></li>
  <li><a href="/zh-CN/XMLHttpRequest" title="zh-CN/XMLHttpRequest">XMLHttpRequest</a></li>
  <li><a href="/zh-CN/DOMParser" title="zh-CN/DOMParser">DOMParser</a></li>
</ul>
恢复到这个版本