Table of Contents

XmlSerializerOptions Class

Definition

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

Name Description
XmlSerializerOptions()

Initializes a new instance of the XmlSerializerOptions class.

Properties

Name Description
Converters

Gets a XmlConverter collection 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.

Reader

Gets or sets the XmlReaderSettings to support the XmlSerializer.

RootName

Gets or sets the name of the XML root element.

Writer

Gets or sets the XmlWriterSettings to support the XmlSerializer.