Skip to main content

Definition

Assembly: CloudNimble.XmlEssentials.dll Namespace: CloudNimble.Text.Xml.Nodes

Syntax

Summary

Represents the ordered list of child nodes of an XmlElementNode. 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.
The code produces the following output:
You don’t create a list. Every XmlElementNode has one. View the complete sample on GitHub

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, and null throws an 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

.ctor Inherited

Inherited from object

Syntax

Properties

Count

Syntax

Property Value

Type: int

IsReadOnly

Syntax

Property Value

Type: bool

this[]

Syntax

Property Value

Type: CloudNimble.Text.Xml.Nodes.XmlNode

Methods

Add

Syntax

Parameters

Clear

Syntax

Contains

Syntax

Parameters

Returns

Type: bool

CopyTo

Syntax

Parameters

Equals Inherited Virtual

Inherited from object

Syntax

Parameters

Returns

Type: bool

Equals Inherited

Inherited from object

Syntax

Parameters

Returns

Type: bool

GetEnumerator

Returns an enumerator that iterates through the nodes in order.

Syntax

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 throws an InvalidOperationException. To change the list in a loop, enumerate a copy of it.

GetHashCode Inherited Virtual

Inherited from object

Syntax

Returns

Type: int

GetType Inherited

Inherited from object

Syntax

Returns

Type: System.Type

IndexOf

Syntax

Parameters

Returns

Type: int

Insert

Syntax

Parameters

MemberwiseClone Inherited

Inherited from object

Syntax

Returns

Type: object

ReferenceEquals Inherited

Inherited from object

Syntax

Parameters

Returns

Type: bool

Remove

Syntax

Parameters

Returns

Type: bool

RemoveAt

Syntax

Parameters

ToString Inherited Virtual

Inherited from object

Syntax

Returns

Type: string?
  • CloudNimble.Text.Xml.Nodes.XmlElementNode
  • CloudNimble.Text.Xml.Nodes.XmlNode
  • CloudNimble.Text.Xml.Nodes.XmlAttributeNodeList