> ## Documentation Index
> Fetch the complete documentation index at: https://easyaf.nimbleapps.cloud/llms.txt
> Use this file to discover all available pages before exploring further.

# XmlUnmappedMemberHandling

> Specifies how [XmlSerializer](/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializer) handles XML elements and attributes that cannot be mapped to a specific .NET...

## Definition

**Assembly:** CloudNimble.XmlEssentials.dll

**Namespace:** CloudNimble.Text.Xml.Serialization

**Inheritance:** System.Enum

## Syntax

```csharp theme={"dark"}
CloudNimble.Text.Xml.Serialization.XmlUnmappedMemberHandling
```

## Summary

Specifies how [XmlSerializer](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializer.md) handles XML elements and attributes that cannot be mapped to a specific
.NET member when deserializing object types.

## Usage

`XmlUnmappedMemberHandling` says what the serializer does, when reading, with an element or attribute that no member of the target type maps to. Set it through `XmlSerializerOptions.UnmappedMemberHandling`. It is the counterpart of `JsonUnmappedMemberHandling`.

| Value | Behavior |
| - | - |
| `Skip` (default) | The element or attribute is ignored. |
| `Disallow` | The serializer throws an [`XmlException`](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlException). |

```csharp theme={"dark"}
string[] documents =
[
    "<Registration><Email>ada@contoso.example</Email><Plan>pro</Plan><Coupon>SPRING</Coupon></Registration>",
    "<Registration source=\"web\"><Email>ada@contoso.example</Email><Plan>pro</Plan></Registration>",
];

var options = new XmlSerializerOptions { UnmappedMemberHandling = XmlUnmappedMemberHandling.Disallow };

foreach (string xml in documents)
{
    Registration? registration = XmlSerializer.Deserialize<Registration>(xml);
    output.WriteLine($"Skip: {registration!.Email} chose {registration.Plan}");

    try
    {
        XmlSerializer.Deserialize<Registration>(xml, options);
    }
    catch (XmlException ex)
    {
        output.WriteLine($"Disallow: {ex.Message}");
    }
}
```

The code produces the following output:

```text theme={"dark"}
Skip: ada@contoso.example chose pro
Disallow: Unknown element 'Coupon'. Path: /Registration | LineNumber: 1 | BytePositionInLine: 73.
Skip: ada@contoso.example chose pro
Disallow: Unknown attribute 'source'. Path: /Registration | LineNumber: 1 | BytePositionInLine: 28.
```

[View the complete sample on GitHub](https://github.com/CloudNimble/XmlEssentials/blob/main/src/CloudNimble.XmlEssentials.Samples/10_RequiredProperties.cs)

## Remarks

When the type has a member marked with [XmlExtensionDataAttribute](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Serialization/XmlExtensionDataAttribute.md), or a member marked with
[XmlMixedAttribute](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Serialization/XmlMixedAttribute.md) for elements, that member captures the unmapped content and neither value applies.

## Considerations

* The setting is on the options and applies to every type in the object graph. There is no attribute that sets it for one type.
* Namespace declarations, `xsi:nil`, `xsi:type`, and the attributes the serializer itself writes for polymorphism and preserved references are never treated as unmapped.
* A member marked `[XmlIgnore]` isn't mapped, so with `Disallow` an element for it is an error.
* When the type has an `[XmlExtensionData]` member, unmapped elements and attributes are collected there, and `Disallow` doesn't reject them.
* Names are matched with case unless `PropertyNameCaseInsensitive` is `true`, so with `Disallow` an element that differs from a member only by case is an error.
* `XmlSerializerOptions.Strict` sets `Disallow`.

## Values

| Name | Value | Description |
| - | - | - |
| `Skip` | 0 | Silent skipping of any unmapped element or attribute. This is the default behavior. |
| `Disallow` | 1 | Rejection of any unmapped element or attribute with an [XmlException](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlException.md). |

## Related APIs

* CloudNimble.Text.Xml.XmlSerializerOptions
* CloudNimble.Text.Xml.XmlSerializerDefaults
* CloudNimble.Text.Xml.XmlException
* CloudNimble.Text.Xml.Serialization.XmlExtensionDataAttribute
* CloudNimble.Text.Xml.Serialization.XmlIgnoreAttribute
* CloudNimble.Text.Xml.Serialization.XmlRequiredAttribute


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.