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

# XmlNodeList

> Represents the ordered list of child nodes 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.XmlNodeList
```

## Summary

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

## Usage

`XmlNodeList` is the type of `XmlElementNode.Children`. It's an `IList<XmlNode>` that holds an element's child nodes in document order: elements, text, CDATA sections, comments, and processing instructions. Use it to count, index, insert at a position, remove, and replace.

```csharp theme={"dark"}
var order = (XmlElementNode)XmlNode.Parse("""<Order><Item>Keyboard</Item><Item>Mouse</Item><Item>Monitor</Item><Note>Gift</Note></Order>""")!;

order.Children.RemoveAt(0);

XmlElementNode note = order["Note"]!;
order.Children.Remove(note);
output.WriteLine($"The removed node has a parent: {note.Parent is not null}");

var replacement = new XmlElementNode("Item");
replacement.InnerText = "Trackball";
order.Children[0] = replacement;

var archive = new XmlElementNode("Archive");
archive.Add(note);

order["Item"]!.InnerText = "Trackball (wireless)";

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

The code produces the following output:

```text theme={"dark"}
The removed node has a parent: False
<Order><Item>Trackball (wireless)</Item><Item>Monitor</Item></Order>
<Archive><Note>Gift</Note></Archive>
```

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

A node can belong to one list at a time. Adding, inserting, or assigning a node 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). A node that is removed or replaced has no parent afterward.

## Considerations

* A node belongs to one list at a time. `Add`, `Insert`, and the index setter throw an `XmlException` ("The node already has a parent.") for a node that has a parent. Remove it first to move it, or add a `DeepClone` to copy it.
* `Remove`, `RemoveAt`, `Clear`, and replacing through the index setter set the `Parent` of the node that leaves the list to `null`. `Remove` returns `false` when the node isn't in the list.
* In a tree parsed from an indented document, the list holds a text node for each run of white space between elements. Don't assume that an index holds an element.
* 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.
* The list accepts the kinds of node that can be content: elements, text, CDATA sections, comments, and processing instructions. Adding an `XmlAttributeNode` or an `XmlDeclarationNode` throws an `XmlException`. When an assignment to an index is refused, the node that was there stays.

## 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.XmlNode this { get; set; }
```

#### Property Value

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

## Methods

### &#x20;Add

#### Syntax

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

#### Parameters

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

### &#x20;Clear

#### Syntax

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

### &#x20;Contains

#### Syntax

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

#### Parameters

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

#### Returns

Type: `bool`

### &#x20;CopyTo

#### Syntax

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

#### Parameters

| Name | Type | Description |
| - | - | - |
| `array` | `CloudNimble.Text.Xml.Nodes.XmlNode[]` | - |
| `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 nodes in order.

#### Syntax

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

#### Returns

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

#### Remarks

The list must not change while it is enumerated. After a node 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.XmlNode item)
```

#### Parameters

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

#### Returns

Type: `int`

### &#x20;Insert

#### Syntax

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

#### Parameters

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

### &#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.XmlNode node)
```

#### Parameters

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

#### 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.XmlElementNode
* CloudNimble.Text.Xml.Nodes.XmlNode
* CloudNimble.Text.Xml.Nodes.XmlAttributeNodeList


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