Saves an XML document to a memory stream. - CSharp System.Xml

CSharp examples for System.Xml:XML Document

Description

Saves an XML document to a memory stream.

Demo Code

// License:         MIT License (http://www.opensource.org/licenses/mit-license.php)
using System.IO;/*  w  w w  . j  a v a  2 s.c  o m*/
using System.Text;
using System.Xml;
using System;

public class Main{
        /// <summary>
        /// Saves an XML document to a memory stream.
        /// </summary>
        /// <param name="document">Input document.</param>
        /// <returns>Memory stream.</returns>
        static public MemoryStream ToMemoryStream(XmlDocument document)
        {
            // Save to stream
            MemoryStream stream = new MemoryStream();
            document.Save(stream);

            // Seek back to start of stream
            stream.Seek(0, SeekOrigin.Begin);

            return stream;
        }
}

Related Tutorials