Table of Contents

XmlStreamFactory Class

Definition

Namespace
Cuemon.Xml
Assemblies
Cuemon.Xml.dll
Source
src/Cuemon.Xml/XmlStreamFactory.cs

Provides access to factory methods for creating and configuring Stream instances.

public static class XmlStreamFactory
Inheritance
XmlStreamFactory

Examples

The following example builds an XML document inline using XmlStreamFactory.CreateStream with an XmlWriter delegate. The resulting stream is read back as a string, producing a well-formed XML document with a <Configuration> root element.

using System;
using System.IO;
using System.Xml;
using Cuemon.Xml;

namespace Cuemon.Xml;

public class XmlStreamFactoryExample
{
    public void Demonstrate()
    {
        using var stream = XmlStreamFactory.CreateStream(writer =>
        {
            writer.WriteStartDocument();
            writer.WriteStartElement("Configuration");
            writer.WriteElementString("AppName", "MyApp");
            writer.WriteElementString("Version", "1.0");
            writer.WriteEndElement();
            writer.WriteEndDocument();
        });

        using var reader = new StreamReader(stream);
        var xml = reader.ReadToEnd();
        Console.WriteLine(xml);
    }
}

Methods

Name Description
CreateStream(Action<XmlWriter>, Action<XmlWriterSettings>)

Creates and returns an XML stream by the specified delegate writer.