XMLSerializer

  • Revision slug: XMLSerializer
  • Revision title: XMLSerializer
  • Revision id: 343907
  • Created:
  • Creator: vyv03354
  • Is current revision? No
  • Comment

Revision Content

XMLSerializer can be used to convert 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

serializeToString
Returns the serialized subtree of a string.
serializeToStream {{ non-standard_inline() }}{{ obsolete_inline("20") }}
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);

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

Browser compatibility

{{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}}

See also

{{ languages( { "fr": "fr/XMLSerializer", "ja": "ja/XMLSerializer" } ) }}

Revision Source

<div dir="ltr" id="result_box" style="text-align: left;">
  XMLSerializer can be used to convert DOM subtree or DOM document into text. XMLSerializer is available to unprivileged scripts.</div>
<p>&nbsp;</p>
<p>For more information about using <code>XMLSerializer</code> in Firefox extensions, please see the documentation for <a href="/en-US/docs/nsIDOMSerializer" title="nsIDOMSerializer"><code>nsIDOMSerializer</code></a>.</p>
<h2 id="Methods" name="Methods">Methods</h2>
<dl>
  <dt id="serializeToString">
    serializeToString</dt>
  <dd>
    Returns the serialized subtree of a string.</dd>
  <dt id="serializeToStream">
    serializeToStream {{ non-standard_inline() }}{{ obsolete_inline("20") }}</dt>
  <dd>
    The subtree rooted by the specified element is serialized to a byte stream using the character set specified.</dd>
</dl>
<h2 id="Examples" name="Examples">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&nbsp;: function()
   {
     alert("Stream closed");
   },
   flush&nbsp;: function()
   {
   },
   write&nbsp;: function(string, count)
   {
     alert("'" + string + "'\n bytes count: " + count + "");
   }
 };
 s.serializeToStream(document, stream, "UTF-8");
</pre>
<h2 id="Browser_compatibility" name="Browser_compatibility">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="See_also" name="See_also">See also</h2>
<ul>
  <li><a href="/en/Parsing_and_serializing_XML" title="en/Parsing_and_serializing_XML">Parsing and serializing XML</a></li>
  <li><a href="/en/XMLHttpRequest" title="en/XMLHttpRequest">XMLHttpRequest</a></li>
  <li><a href="/en/DOMParser" title="en/DOMParser">DOMParser</a></li>
</ul>
<p>{{ languages( { "fr": "fr/XMLSerializer", "ja": "ja/XMLSerializer" } ) }}</p>
Revert to this revision