Home > Element Reference : XMLSerializer

Contents

### XMLSerializer

This object is used to convert a document or a part of a document into a string. It is the reverse of the DOMParser object. The functions take a document node and return a string or write the string form to a stream.

This object needs to be instantiated in order to be used. The following example demostrates how to convert a portion of a document into a stream.

Example:

        <script>
          function doSerialize(){
            var theBox=document.getElementById('theBox');
            var serializer=new XMLSerializer();
            alert(serializer.serializeToString(theBox));
          }
        </script>
        <box id="theBox" orient="vertical">
          <button label="Look at Me" oncommand="doSerialize();"/>
        </box>

#### Properties and Methods:

serializeToStream ( node , stream , charset )

Given a node in a document, this function writes a string form of the node and its descendants to the output stream. The node may be a node within a document or the document itself. You may specify null for the charset argument to use a default value.

serializeToString ( node )

Given a node in a document, this function returns a string form of the node and its descendants. The node may be a node within a document or the document itself.

Copyright (C) 1999 - 2002 XULPlanet.com