Revision 343899 of XMLSerializer

  • Revision slug: XMLSerializer
  • Revision title: XMLSerializer
  • Revision id: 343899
  • 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
     The subtree rooted by the specified element is serialized to a byte stream using the character set specified.    
Example
 var s = new XMLSerializer();
 var d = document;
 var str = s.serializeToString(d);
 alert(str);
 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

<p>&nbsp;</p>
<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>
<h3 id="Methods" name="Methods">Methods</h3>
<div dir="ltr" id="serializeToString" style="text-align: left;">
  <strong>serializeToString </strong><br />
  &nbsp;&nbsp;&nbsp;&nbsp; Returns the serialized subtree of a string.
  <dl>
    <dt>
      &nbsp;</dt>
  </dl>
</div>
<div dir="ltr" id="serializeToStream" style="text-align: left;">
  <strong>serializeToStream </strong></div>
<div dir="ltr" style="text-align: left;">
  &nbsp;&nbsp;&nbsp;&nbsp; The subtree rooted by the specified element is serialized to a byte stream using the character set specified.&nbsp;&nbsp;&nbsp;&nbsp;</div>
<div dir="ltr" id="Example" style="text-align: left;">
  <span style="font-size: large;">Example</span></div>
<pre class="brush: js">
 var s = new XMLSerializer();
 var d = document;
 var str = s.serializeToString(d);
 alert(str);
</pre>
<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>
<h3 id="See_also" name="See_also">See also</h3>
<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