XmlWriterSettings.CloseOutput Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets or sets a value indicating whether the XmlWriter should also close the underlying stream or TextWriter when the Close method is called.

Namespace:  System.Xml
Assembly:  System.Xml (in System.Xml.dll)

Syntax

'Declaration
Public Property CloseOutput As Boolean
public bool CloseOutput { get; set; }

Property Value

Type: System.Boolean
true to also close the underlying stream or TextWriter; otherwise false. The default is false.

Remarks

This setting is useful when you wish to write XML to a stream, and then add extra information to the end of the stream after the XmlWriter has finished writing.

This property only applies to XmlWriter instances that output XML content to a stream or TextWriter; otherwise, this setting is ignored.

For more information and code examples, see XML Data.

Examples

            Dim settings As New XmlWriterSettings()
            settings.OmitXmlDeclaration = True
            settings.ConformanceLevel = ConformanceLevel.Fragment
            settings.CloseOutput = False

            ' Create the XmlWriter object and write some content.
            Dim strm As New MemoryStream()
            Using writer As XmlWriter = XmlWriter.Create(strm, settings)
                writer.WriteElementString("orderID", "1-456-ab")
                writer.WriteElementString("orderID", "2-36-00a")
                writer.Flush()
            End Using

XmlWriterSettings settings = new XmlWriterSettings();
settings.OmitXmlDeclaration = true;
settings.ConformanceLevel = ConformanceLevel.Fragment;
settings.CloseOutput = false;

// Create the XmlWriter object and write some content.
MemoryStream strm = new MemoryStream();
using (XmlWriter writer = XmlWriter.Create(strm, settings))
{
    writer.WriteElementString("orderID", "1-456-ab");
    writer.WriteElementString("orderID", "2-36-00a");
    writer.Flush();
}

// Do additonal processing on the stream.

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.