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

# XmlAttributeNodeList

> Represents the ordered list of attributes of an [XmlElementNode](/xmlessentials/api-reference/CloudNimble/Text/Xml/Nodes/XmlElementNode). This class cannot be inherited.

## Definition

**Assembly:** CloudNimble.XmlEssentials.dll

**Namespace:** CloudNimble.Text.Xml.Nodes

## Syntax

```csharp theme={"dark"}
CloudNimble.Text.Xml.Nodes.XmlAttributeNodeList
```

## Summary

Represents the ordered list of attributes of an [XmlElementNode](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Nodes/XmlElementNode.md). This class cannot be inherited.

## Usage

`XmlAttributeNodeList` is the type of `XmlElementNode.Attributes`. It's an `IList<XmlAttributeNode>` in document order, with two indexers that find an attribute by name: `Attributes["id"]` matches a local name in any namespace, and `Attributes["language", namespaceUri]` matches one namespace. Both return `null` when there is no such attribute.

```csharp theme={"dark"}
var order = (XmlElementNode)XmlNode.Parse("""<Order id="1042" status="open" draft="true"/>""")!;

order.SetAttribute("status", "shipped");
order.SetAttribute("carrier", "Contoso Freight");
order.Attributes["id"]!.Value = "1043";

XmlAttributeNode draft = order.Attributes["draft"]!;
order.Attributes.Remove(draft);

output.WriteLine(order.ToString());
```

The code produces the following output:

```xml theme={"dark"}
<Order id="1043" status="shipped" carrier="Contoso Freight"/>
```

You don't create a list. Every `XmlElementNode` has one.

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

## Remarks

An attribute can belong to one list at a time. Adding, inserting, or assigning an attribute that
already has a parent throws an [XmlException](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlException.md), and [`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null) throws an
[ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception). An attribute that is removed or replaced has no parent afterward.
The list does not check for duplicate names.

## Considerations

* Attributes are written in list order. `Insert` and the index setter let you control that order.
* `Add`, `Insert`, and the index setter throw an `XmlException` when the attribute already belongs to an element. `Remove`, `RemoveAt`, `Clear`, and replacing through the index setter clear the parent of the attribute that leaves the list.
* The list doesn't check for duplicate names. Two attributes with the same name throw "Duplicate attribute." when the element is written. `XmlElementNode.SetAttribute` updates an existing attribute instead of adding a second one.
* The list of a parsed element includes its namespace declarations (`xmlns` and `xmlns:prefix`), so `Count` can be larger than the number of attributes you think of as data.
* The name indexers search the list from the start each time. That's the right trade for the handful of attributes a typical element has.
* Don't change the list while a `foreach` loop enumerates it. After a change, the loop's next step throws an `InvalidOperationException` ("Collection was modified; enumeration operation may not execute."), as a `List<T>` or a `JsonArray` does. Loop over a copy (`list.ToArray()`), or loop by index from the end. Setting an attribute's `Value` changes the attribute, not the list.

## Constructors

### &#x20;.ctor Inherited

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

#### Syntax

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

## Properties

### &#x20;Count

#### Syntax

```csharp theme={"dark"}
public int Count { get; }
```

#### Property Value

Type: `int`

### &#x20;IsReadOnly

#### Syntax

```csharp theme={"dark"}
public bool IsReadOnly { get; }
```

#### Property Value

Type: `bool`

### &#x20;this\[]

#### Syntax

```csharp theme={"dark"}
public CloudNimble.Text.Xml.Nodes.XmlAttributeNode this { get; set; }
```

#### Property Value

Type: `CloudNimble.Text.Xml.Nodes.XmlAttributeNode`

### &#x20;this\[]

Gets the first attribute that has the specified local name, in any namespace.

#### Syntax

```csharp theme={"dark"}
public CloudNimble.Text.Xml.Nodes.XmlAttributeNode this { get; }
```

#### Property Value

Type: `CloudNimble.Text.Xml.Nodes.XmlAttributeNode?`
The first attribute that has the specified local name, or [`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null) if there is none.

#### Exceptions

| Exception | Description |
| - | - |
| `ArgumentNullException` | *localName* is [`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null). |

### &#x20;this\[]

Gets the first attribute that has the specified local name and namespace URI.

#### Syntax

```csharp theme={"dark"}
public CloudNimble.Text.Xml.Nodes.XmlAttributeNode this { get; }
```

#### Property Value

Type: `CloudNimble.Text.Xml.Nodes.XmlAttributeNode?`
The first attribute that has the specified local name and namespace URI, or
[`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null) if there is none.

#### Exceptions

| Exception | Description |
| - | - |
| `ArgumentNullException` | *localName* or *namespaceUri* is [`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null). |

## Methods

### &#x20;Add

#### Syntax

```csharp theme={"dark"}
public void Add(CloudNimble.Text.Xml.Nodes.XmlAttributeNode node)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `node` | `CloudNimble.Text.Xml.Nodes.XmlAttributeNode` | - |

### &#x20;Clear

#### Syntax

```csharp theme={"dark"}
public void Clear()
```

### &#x20;Contains

#### Syntax

```csharp theme={"dark"}
public bool Contains(CloudNimble.Text.Xml.Nodes.XmlAttributeNode item)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `item` | `CloudNimble.Text.Xml.Nodes.XmlAttributeNode` | - |

#### Returns

Type: `bool`

### &#x20;CopyTo

#### Syntax

```csharp theme={"dark"}
public void CopyTo(CloudNimble.Text.Xml.Nodes.XmlAttributeNode[] array, int arrayIndex)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `array` | `CloudNimble.Text.Xml.Nodes.XmlAttributeNode[]` | - |
| `arrayIndex` | `int` | - |

### &#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;GetEnumerator

Returns an enumerator that iterates through the attributes in order.

#### Syntax

```csharp theme={"dark"}
public System.Collections.Generic.IEnumerator<CloudNimble.Text.Xml.Nodes.XmlAttributeNode> GetEnumerator()
```

#### Returns

Type: `System.Collections.Generic.IEnumerator<CloudNimble.Text.Xml.Nodes.XmlAttributeNode>`
An enumerator for the list.

#### Remarks

The list must not change while it is enumerated. After an attribute is added, inserted, removed, or
replaced, or the list is cleared, the next call to [MoveNext](https://learn.microsoft.com/dotnet/api/system.collections.ienumerator.movenext) throws an
[InvalidOperationException](https://learn.microsoft.com/dotnet/api/system.invalidoperationexception). To change the list in a loop, enumerate a copy of it.

### &#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;IndexOf

#### Syntax

```csharp theme={"dark"}
public int IndexOf(CloudNimble.Text.Xml.Nodes.XmlAttributeNode item)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `item` | `CloudNimble.Text.Xml.Nodes.XmlAttributeNode` | - |

#### Returns

Type: `int`

### &#x20;Insert

#### Syntax

```csharp theme={"dark"}
public void Insert(int index, CloudNimble.Text.Xml.Nodes.XmlAttributeNode node)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `index` | `int` | - |
| `node` | `CloudNimble.Text.Xml.Nodes.XmlAttributeNode` | - |

### &#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;Remove

#### Syntax

```csharp theme={"dark"}
public bool Remove(CloudNimble.Text.Xml.Nodes.XmlAttributeNode node)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `node` | `CloudNimble.Text.Xml.Nodes.XmlAttributeNode` | - |

#### Returns

Type: `bool`

### &#x20;RemoveAt

#### Syntax

```csharp theme={"dark"}
public void RemoveAt(int index)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `index` | `int` | - |

### &#x20;ToString Inherited Virtual

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

#### Syntax

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

#### Returns

Type: `string?`

## Related APIs

* CloudNimble.Text.Xml.Nodes.XmlAttributeNode
* CloudNimble.Text.Xml.Nodes.XmlElementNode
* CloudNimble.Text.Xml.Nodes.XmlNodeList


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