Class XmlStreamFactory
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
CreateStream(Action<XmlWriter>, Action<XmlWriterSettings>)
Creates and returns an XML stream by the specified delegate writer.
public static Stream CreateStream(Action<XmlWriter> writer, Action<XmlWriterSettings> setup = null)
Parameters
writerAction<XmlWriter>The delegate that will create an in-memory XML stream.
setupAction<XmlWriterSettings>The XmlWriterSettings which may be configured.