Table of Contents

Class XmlSerializerOptions

Namespace
Cuemon.Xml.Serialization
Assembly
Cuemon.Xml.dll

Configuration options for XmlSerializer.

public class XmlSerializerOptions
Inheritance
XmlSerializerOptions

Examples

The following example demonstrates how to configure for custom root names and XML reader/writer settings.

using System;
using System.Xml;
using Cuemon.Xml.Serialization;

namespace MyApp.Examples;

public static class XmlSerializerOptionsExample
{
    public static void Demonstrate()
    {
        var options = new XmlSerializerOptions
        {
            RootName = new XmlQualifiedEntity("Invoice"),
            FlattenCollectionItems = true,
            Reader = new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore },
            Writer = new XmlWriterSettings { Indent = true }
        };

        Console.WriteLine(options.RootName.LocalName);
        Console.WriteLine(options.FlattenCollectionItems);
        Console.WriteLine(options.Writer.Indent);
        Console.WriteLine(options.Converters.Count);
    }
}

Constructors

XmlSerializerOptions()

Initializes a new instance of the XmlSerializerOptions class.

public XmlSerializerOptions()

Remarks

The following table shows the initial property values for an instance of DefaultXmlConverter.

PropertyInitial Value
Readernew XmlWriterSettings() { IndentChars = Alphanumeric.Tab };
Writernew XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore };
ConvertersList<T>
RootNamenull

Properties

Converters

Gets a XmlConverter collection that will be used during serialization.

public IList<XmlConverter> Converters { get; }

Property Value

IList<XmlConverter>

The converters that will be used during serialization.

FlattenCollectionItems

Gets or sets a value indicating whether collection items should be serialized as repeated elements using the property name instead of being wrapped in a generic Item element.

public bool FlattenCollectionItems { get; set; }

Property Value

bool

true to emit one repeated element per item named after the enclosing property; false to use the default Item wrapper. The default is false.

Reader

Gets or sets the XmlReaderSettings to support the XmlSerializer.

public XmlReaderSettings Reader { get; set; }

Property Value

XmlReaderSettings

A XmlReaderSettings instance that specifies a set of features to support the XmlSerializer object.

RootName

Gets or sets the name of the XML root element.

public XmlQualifiedEntity RootName { get; set; }

Property Value

XmlQualifiedEntity

The name of the XML root element.

Writer

Gets or sets the XmlWriterSettings to support the XmlSerializer.

public XmlWriterSettings Writer { get; set; }

Property Value

XmlWriterSettings

A XmlWriterSettings instance that specifies a set of features to support the XmlSerializer object.