Skip to main content

Definition

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

Syntax

Summary

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

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

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

this[]

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

Syntax

Property Value

Type: CloudNimble.Text.Xml.Nodes.XmlAttributeNode? The first attribute that has the specified local name, or null if there is none.

Exceptions

this[]

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

Syntax

Property Value

Type: CloudNimble.Text.Xml.Nodes.XmlAttributeNode? The first attribute that has the specified local name and namespace URI, or null if there is none.

Exceptions

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 attributes in order.

Syntax

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 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.XmlAttributeNode
  • CloudNimble.Text.Xml.Nodes.XmlElementNode
  • CloudNimble.Text.Xml.Nodes.XmlNodeList