> ## 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.

# XmlRootAttribute

> Specifies the name and namespace of the document element that a type is serialized as. This class cannot be inherited.

## Definition

**Assembly:** CloudNimble.XmlEssentials.dll

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

**Inheritance:** System.Attribute

## Syntax

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

## Summary

Specifies the name and namespace of the document element that a type is serialized as. This class cannot be inherited.

## Usage

Apply `[XmlRoot]` to a class, struct, or interface to name the document element that is written when a value of that type is the root of the document. Without it, the document element is the type name, converted by the element naming policy.

```csharp theme={"dark"}
[XmlRoot("product")]
public sealed class CatalogItem
{
    [XmlAttribute("sku")]
    public string? Sku { get; set; }

    [XmlPropertyName("title")]
    public string? Name { get; set; }

    [XmlElement("unit-price")]
    public decimal UnitPrice { get; set; }
}
```

```csharp theme={"dark"}
var item = new CatalogItem { Sku = "KB-101", Name = "Keyboard", UnitPrice = 49.95m };
var options = new XmlSerializerOptions { OmitXmlDeclaration = true };

string xml = XmlSerializer.Serialize(item, options);
output.WriteLine(xml);

CatalogItem? copy = XmlSerializer.Deserialize<CatalogItem>(xml, options);
output.WriteLine($"{copy!.Sku}: {copy.Name}");
```

The code produces the following output:

```text theme={"dark"}
<product sku="KB-101"><title>Keyboard</title><unit-price>49.95</unit-price></product>
KB-101: Keyboard
```

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

Set `Namespace` to put the document element in an XML namespace. See [Namespaces](https://easyaf.nimbleapps.cloud/xmlessentials/guides/namespaces.md).

## Considerations

* The name is used exactly as written. A naming policy doesn't convert it.
* When reading, the document element must have this name, or the serializer throws an `XmlException`. The name is matched with case unless `PropertyNameCaseInsensitive` is set, which ignores the case of ASCII letters for the document element as it does for members.
* The attribute names the type as a document element. When the type is the type of a member of another object, the element is named after that member.
* When `Namespace` is `null`, `XmlSerializerOptions.DefaultNamespace` is used.
* A `null` reference at the root is always written as the document element marked `xsi:nil="true"`.

## Constructors

### &#x20;.ctor

Initializes a new instance of the [XmlRootAttribute](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Serialization/XmlRootAttribute.md) class that uses the name of the type as the document element name.

#### Syntax

```csharp theme={"dark"}
public XmlRootAttribute()
```

### &#x20;.ctor

Initializes a new instance of the [XmlRootAttribute](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Serialization/XmlRootAttribute.md) class with the specified document element name.

#### Syntax

```csharp theme={"dark"}
public XmlRootAttribute(string elementName)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `elementName` | `string` | The local name of the document element. |

#### Exceptions

| Exception | Description |
| - | - |
| `ArgumentNullException` | *elementName* is [`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null). |
| `ArgumentException` | *elementName* is empty or consists only of white-space characters. |

### &#x20;.ctor Inherited

> [!NOTE]
>
> Inherited from `System.Attribute`

#### Syntax

```csharp theme={"dark"}
protected Attribute()
```

### &#x20;.ctor Inherited

> [!NOTE]
>
> Inherited from `object`

#### Syntax

```csharp theme={"dark"}
public Object()
```

## Properties

### &#x20;ElementName

Gets or sets the local name of the document element.

#### Syntax

```csharp theme={"dark"}
public string ElementName { get; set; }
```

#### Property Value

Type: `string?`
The local name of the document element. If the value is [`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null) or empty, the name of the type is used,
converted by the element naming policy. The default is [`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null).

### &#x20;Namespace

Gets or sets the namespace URI of the document element.

#### Syntax

```csharp theme={"dark"}
public string Namespace { get; set; }
```

#### Property Value

Type: `string?`
The namespace URI of the document element. If the value is [`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null), [XmlSerializerOptions.DefaultNamespace](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlSerializerOptions.md#defaultnamespace) is used.
The default is [`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null).

### &#x20;TypeId Inherited Virtual

> [!NOTE]
>
> Inherited from `System.Attribute`

#### Syntax

```csharp theme={"dark"}
public virtual object TypeId { get; }
```

#### Property Value

Type: `object`

## Methods

### &#x20;Equals Override

> [!NOTE]
>
> Inherited from `System.Attribute`

#### Syntax

```csharp theme={"dark"}
public override bool Equals(object obj)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `obj` | `object?` | - |

#### Returns

Type: `bool`

### &#x20;Equals Inherited Virtual

> [!NOTE]
>
> Inherited from `object`

#### Syntax

```csharp theme={"dark"}
public virtual bool Equals(object obj)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `obj` | `object?` | - |

#### Returns

Type: `bool`

### &#x20;Equals Inherited

> [!NOTE]
>
> Inherited from `object`

#### Syntax

```csharp theme={"dark"}
public static bool Equals(object objA, object objB)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `objA` | `object?` | - |
| `objB` | `object?` | - |

#### Returns

Type: `bool`

### &#x20;GetCustomAttribute Inherited

> [!NOTE]
>
> Inherited from `System.Attribute`

#### Syntax

```csharp theme={"dark"}
public static System.Attribute GetCustomAttribute(System.Reflection.MemberInfo element, System.Type attributeType)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `element` | `System.Reflection.MemberInfo` | - |
| `attributeType` | `System.Type` | - |

#### Returns

Type: `System.Attribute?`

### &#x20;GetCustomAttribute Inherited

> [!NOTE]
>
> Inherited from `System.Attribute`

#### Syntax

```csharp theme={"dark"}
public static System.Attribute GetCustomAttribute(System.Reflection.MemberInfo element, System.Type attributeType, bool inherit)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `element` | `System.Reflection.MemberInfo` | - |
| `attributeType` | `System.Type` | - |
| `inherit` | `bool` | - |

#### Returns

Type: `System.Attribute?`

### &#x20;GetCustomAttribute Inherited

> [!NOTE]
>
> Inherited from `System.Attribute`

#### Syntax

```csharp theme={"dark"}
public static System.Attribute GetCustomAttribute(System.Reflection.ParameterInfo element, System.Type attributeType)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `element` | `System.Reflection.ParameterInfo` | - |
| `attributeType` | `System.Type` | - |

#### Returns

Type: `System.Attribute?`

### &#x20;GetCustomAttribute Inherited

> [!NOTE]
>
> Inherited from `System.Attribute`

#### Syntax

```csharp theme={"dark"}
public static System.Attribute GetCustomAttribute(System.Reflection.ParameterInfo element, System.Type attributeType, bool inherit)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `element` | `System.Reflection.ParameterInfo` | - |
| `attributeType` | `System.Type` | - |
| `inherit` | `bool` | - |

#### Returns

Type: `System.Attribute?`

### &#x20;GetCustomAttribute Inherited

> [!NOTE]
>
> Inherited from `System.Attribute`

#### Syntax

```csharp theme={"dark"}
public static System.Attribute GetCustomAttribute(System.Reflection.Module element, System.Type attributeType)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `element` | `System.Reflection.Module` | - |
| `attributeType` | `System.Type` | - |

#### Returns

Type: `System.Attribute?`

### &#x20;GetCustomAttribute Inherited

> [!NOTE]
>
> Inherited from `System.Attribute`

#### Syntax

```csharp theme={"dark"}
public static System.Attribute GetCustomAttribute(System.Reflection.Module element, System.Type attributeType, bool inherit)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `element` | `System.Reflection.Module` | - |
| `attributeType` | `System.Type` | - |
| `inherit` | `bool` | - |

#### Returns

Type: `System.Attribute?`

### &#x20;GetCustomAttribute Inherited

> [!NOTE]
>
> Inherited from `System.Attribute`

#### Syntax

```csharp theme={"dark"}
public static System.Attribute GetCustomAttribute(System.Reflection.Assembly element, System.Type attributeType)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `element` | `System.Reflection.Assembly` | - |
| `attributeType` | `System.Type` | - |

#### Returns

Type: `System.Attribute?`

### &#x20;GetCustomAttribute Inherited

> [!NOTE]
>
> Inherited from `System.Attribute`

#### Syntax

```csharp theme={"dark"}
public static System.Attribute GetCustomAttribute(System.Reflection.Assembly element, System.Type attributeType, bool inherit)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `element` | `System.Reflection.Assembly` | - |
| `attributeType` | `System.Type` | - |
| `inherit` | `bool` | - |

#### Returns

Type: `System.Attribute?`

### &#x20;GetCustomAttributes Inherited

> [!NOTE]
>
> Inherited from `System.Attribute`

#### Syntax

```csharp theme={"dark"}
public static System.Attribute[] GetCustomAttributes(System.Reflection.MemberInfo element, System.Type attributeType)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `element` | `System.Reflection.MemberInfo` | - |
| `attributeType` | `System.Type` | - |

#### Returns

Type: `System.Attribute[]`

### &#x20;GetCustomAttributes Inherited

> [!NOTE]
>
> Inherited from `System.Attribute`

#### Syntax

```csharp theme={"dark"}
public static System.Attribute[] GetCustomAttributes(System.Reflection.MemberInfo element, System.Type attributeType, bool inherit)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `element` | `System.Reflection.MemberInfo` | - |
| `attributeType` | `System.Type` | - |
| `inherit` | `bool` | - |

#### Returns

Type: `System.Attribute[]`

### &#x20;GetCustomAttributes Inherited

> [!NOTE]
>
> Inherited from `System.Attribute`

#### Syntax

```csharp theme={"dark"}
public static System.Attribute[] GetCustomAttributes(System.Reflection.MemberInfo element)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `element` | `System.Reflection.MemberInfo` | - |

#### Returns

Type: `System.Attribute[]`

### &#x20;GetCustomAttributes Inherited

> [!NOTE]
>
> Inherited from `System.Attribute`

#### Syntax

```csharp theme={"dark"}
public static System.Attribute[] GetCustomAttributes(System.Reflection.MemberInfo element, bool inherit)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `element` | `System.Reflection.MemberInfo` | - |
| `inherit` | `bool` | - |

#### Returns

Type: `System.Attribute[]`

### &#x20;GetCustomAttributes Inherited

> [!NOTE]
>
> Inherited from `System.Attribute`

#### Syntax

```csharp theme={"dark"}
public static System.Attribute[] GetCustomAttributes(System.Reflection.ParameterInfo element)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `element` | `System.Reflection.ParameterInfo` | - |

#### Returns

Type: `System.Attribute[]`

### &#x20;GetCustomAttributes Inherited

> [!NOTE]
>
> Inherited from `System.Attribute`

#### Syntax

```csharp theme={"dark"}
public static System.Attribute[] GetCustomAttributes(System.Reflection.ParameterInfo element, System.Type attributeType)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `element` | `System.Reflection.ParameterInfo` | - |
| `attributeType` | `System.Type` | - |

#### Returns

Type: `System.Attribute[]`

### &#x20;GetCustomAttributes Inherited

> [!NOTE]
>
> Inherited from `System.Attribute`

#### Syntax

```csharp theme={"dark"}
public static System.Attribute[] GetCustomAttributes(System.Reflection.ParameterInfo element, System.Type attributeType, bool inherit)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `element` | `System.Reflection.ParameterInfo` | - |
| `attributeType` | `System.Type` | - |
| `inherit` | `bool` | - |

#### Returns

Type: `System.Attribute[]`

### &#x20;GetCustomAttributes Inherited

> [!NOTE]
>
> Inherited from `System.Attribute`

#### Syntax

```csharp theme={"dark"}
public static System.Attribute[] GetCustomAttributes(System.Reflection.ParameterInfo element, bool inherit)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `element` | `System.Reflection.ParameterInfo` | - |
| `inherit` | `bool` | - |

#### Returns

Type: `System.Attribute[]`

### &#x20;GetCustomAttributes Inherited

> [!NOTE]
>
> Inherited from `System.Attribute`

#### Syntax

```csharp theme={"dark"}
public static System.Attribute[] GetCustomAttributes(System.Reflection.Module element, System.Type attributeType)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `element` | `System.Reflection.Module` | - |
| `attributeType` | `System.Type` | - |

#### Returns

Type: `System.Attribute[]`

### &#x20;GetCustomAttributes Inherited

> [!NOTE]
>
> Inherited from `System.Attribute`

#### Syntax

```csharp theme={"dark"}
public static System.Attribute[] GetCustomAttributes(System.Reflection.Module element)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `element` | `System.Reflection.Module` | - |

#### Returns

Type: `System.Attribute[]`

### &#x20;GetCustomAttributes Inherited

> [!NOTE]
>
> Inherited from `System.Attribute`

#### Syntax

```csharp theme={"dark"}
public static System.Attribute[] GetCustomAttributes(System.Reflection.Module element, bool inherit)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `element` | `System.Reflection.Module` | - |
| `inherit` | `bool` | - |

#### Returns

Type: `System.Attribute[]`

### &#x20;GetCustomAttributes Inherited

> [!NOTE]
>
> Inherited from `System.Attribute`

#### Syntax

```csharp theme={"dark"}
public static System.Attribute[] GetCustomAttributes(System.Reflection.Module element, System.Type attributeType, bool inherit)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `element` | `System.Reflection.Module` | - |
| `attributeType` | `System.Type` | - |
| `inherit` | `bool` | - |

#### Returns

Type: `System.Attribute[]`

### &#x20;GetCustomAttributes Inherited

> [!NOTE]
>
> Inherited from `System.Attribute`

#### Syntax

```csharp theme={"dark"}
public static System.Attribute[] GetCustomAttributes(System.Reflection.Assembly element, System.Type attributeType)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `element` | `System.Reflection.Assembly` | - |
| `attributeType` | `System.Type` | - |

#### Returns

Type: `System.Attribute[]`

### &#x20;GetCustomAttributes Inherited

> [!NOTE]
>
> Inherited from `System.Attribute`

#### Syntax

```csharp theme={"dark"}
public static System.Attribute[] GetCustomAttributes(System.Reflection.Assembly element, System.Type attributeType, bool inherit)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `element` | `System.Reflection.Assembly` | - |
| `attributeType` | `System.Type` | - |
| `inherit` | `bool` | - |

#### Returns

Type: `System.Attribute[]`

### &#x20;GetCustomAttributes Inherited

> [!NOTE]
>
> Inherited from `System.Attribute`

#### Syntax

```csharp theme={"dark"}
public static System.Attribute[] GetCustomAttributes(System.Reflection.Assembly element)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `element` | `System.Reflection.Assembly` | - |

#### Returns

Type: `System.Attribute[]`

### &#x20;GetCustomAttributes Inherited

> [!NOTE]
>
> Inherited from `System.Attribute`

#### Syntax

```csharp theme={"dark"}
public static System.Attribute[] GetCustomAttributes(System.Reflection.Assembly element, bool inherit)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `element` | `System.Reflection.Assembly` | - |
| `inherit` | `bool` | - |

#### Returns

Type: `System.Attribute[]`

### &#x20;GetHashCode Override

> [!NOTE]
>
> Inherited from `System.Attribute`

#### Syntax

```csharp theme={"dark"}
public override int GetHashCode()
```

#### Returns

Type: `int`

### &#x20;GetHashCode Inherited Virtual

> [!NOTE]
>
> Inherited from `object`

#### Syntax

```csharp theme={"dark"}
public virtual int GetHashCode()
```

#### Returns

Type: `int`

### &#x20;GetType Inherited

> [!NOTE]
>
> Inherited from `object`

#### Syntax

```csharp theme={"dark"}
public System.Type GetType()
```

#### Returns

Type: `System.Type`

### &#x20;IsDefaultAttribute Inherited Virtual

> [!NOTE]
>
> Inherited from `System.Attribute`

#### Syntax

```csharp theme={"dark"}
public virtual bool IsDefaultAttribute()
```

#### Returns

Type: `bool`

### &#x20;IsDefined Inherited

> [!NOTE]
>
> Inherited from `System.Attribute`

#### Syntax

```csharp theme={"dark"}
public static bool IsDefined(System.Reflection.MemberInfo element, System.Type attributeType)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `element` | `System.Reflection.MemberInfo` | - |
| `attributeType` | `System.Type` | - |

#### Returns

Type: `bool`

### &#x20;IsDefined Inherited

> [!NOTE]
>
> Inherited from `System.Attribute`

#### Syntax

```csharp theme={"dark"}
public static bool IsDefined(System.Reflection.MemberInfo element, System.Type attributeType, bool inherit)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `element` | `System.Reflection.MemberInfo` | - |
| `attributeType` | `System.Type` | - |
| `inherit` | `bool` | - |

#### Returns

Type: `bool`

### &#x20;IsDefined Inherited

> [!NOTE]
>
> Inherited from `System.Attribute`

#### Syntax

```csharp theme={"dark"}
public static bool IsDefined(System.Reflection.ParameterInfo element, System.Type attributeType)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `element` | `System.Reflection.ParameterInfo` | - |
| `attributeType` | `System.Type` | - |

#### Returns

Type: `bool`

### &#x20;IsDefined Inherited

> [!NOTE]
>
> Inherited from `System.Attribute`

#### Syntax

```csharp theme={"dark"}
public static bool IsDefined(System.Reflection.ParameterInfo element, System.Type attributeType, bool inherit)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `element` | `System.Reflection.ParameterInfo` | - |
| `attributeType` | `System.Type` | - |
| `inherit` | `bool` | - |

#### Returns

Type: `bool`

### &#x20;IsDefined Inherited

> [!NOTE]
>
> Inherited from `System.Attribute`

#### Syntax

```csharp theme={"dark"}
public static bool IsDefined(System.Reflection.Module element, System.Type attributeType)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `element` | `System.Reflection.Module` | - |
| `attributeType` | `System.Type` | - |

#### Returns

Type: `bool`

### &#x20;IsDefined Inherited

> [!NOTE]
>
> Inherited from `System.Attribute`

#### Syntax

```csharp theme={"dark"}
public static bool IsDefined(System.Reflection.Module element, System.Type attributeType, bool inherit)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `element` | `System.Reflection.Module` | - |
| `attributeType` | `System.Type` | - |
| `inherit` | `bool` | - |

#### Returns

Type: `bool`

### &#x20;IsDefined Inherited

> [!NOTE]
>
> Inherited from `System.Attribute`

#### Syntax

```csharp theme={"dark"}
public static bool IsDefined(System.Reflection.Assembly element, System.Type attributeType)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `element` | `System.Reflection.Assembly` | - |
| `attributeType` | `System.Type` | - |

#### Returns

Type: `bool`

### &#x20;IsDefined Inherited

> [!NOTE]
>
> Inherited from `System.Attribute`

#### Syntax

```csharp theme={"dark"}
public static bool IsDefined(System.Reflection.Assembly element, System.Type attributeType, bool inherit)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `element` | `System.Reflection.Assembly` | - |
| `attributeType` | `System.Type` | - |
| `inherit` | `bool` | - |

#### Returns

Type: `bool`

### &#x20;Match Inherited Virtual

> [!NOTE]
>
> Inherited from `System.Attribute`

#### Syntax

```csharp theme={"dark"}
public virtual bool Match(object obj)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `obj` | `object?` | - |

#### Returns

Type: `bool`

### &#x20;MemberwiseClone Inherited

> [!NOTE]
>
> Inherited from `object`

#### Syntax

```csharp theme={"dark"}
protected internal object MemberwiseClone()
```

#### Returns

Type: `object`

### &#x20;ReferenceEquals Inherited

> [!NOTE]
>
> Inherited from `object`

#### Syntax

```csharp theme={"dark"}
public static bool ReferenceEquals(object objA, object objB)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `objA` | `object?` | - |
| `objB` | `object?` | - |

#### Returns

Type: `bool`

### &#x20;ToString Inherited Virtual

> [!NOTE]
>
> Inherited from `object`

#### Syntax

```csharp theme={"dark"}
public virtual string ToString()
```

#### Returns

Type: `string?`

## Related APIs

* CloudNimble.Text.Xml.XmlSerializer
* CloudNimble.Text.Xml.XmlSerializerOptions
* CloudNimble.Text.Xml.XmlNamingPolicy
* CloudNimble.Text.Xml.Serialization.XmlPropertyNameAttribute
* CloudNimble.Text.Xml.Serialization.XmlElementAttribute


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