Definition
Assembly: CloudNimble.XmlEssentials.dll Namespace: CloudNimble.Text.Xml.NodesSyntax
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.
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, andnull 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.
Insertand the index setter let you control that order. Add,Insert, and the index setter throw anXmlExceptionwhen 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.SetAttributeupdates an existing attribute instead of adding a second one. - The list of a parsed element includes its namespace declarations (
xmlnsandxmlns:prefix), soCountcan 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
foreachloop enumerates it. After a change, the loop’s next step throws anInvalidOperationException(“Collection was modified; enumeration operation may not execute.”), as aList<T>or aJsonArraydoes. Loop over a copy (list.ToArray()), or loop by index from the end. Setting an attribute’sValuechanges the attribute, not the list.
Constructors
.ctor Inherited
Inherited from
objectSyntax
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
objectSyntax
Parameters
Returns
Type:bool
Equals Inherited
Inherited from
objectSyntax
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
objectSyntax
Returns
Type:int
GetType Inherited
Inherited from
objectSyntax
Returns
Type:System.Type
IndexOf
Syntax
Parameters
Returns
Type:int
Insert
Syntax
Parameters
MemberwiseClone Inherited
Inherited from
objectSyntax
Returns
Type:object
ReferenceEquals Inherited
Inherited from
objectSyntax
Parameters
Returns
Type:bool
Remove
Syntax
Parameters
Returns
Type:bool
RemoveAt
Syntax
Parameters
ToString Inherited Virtual
Inherited from
objectSyntax
Returns
Type:string?
Related APIs
- CloudNimble.Text.Xml.Nodes.XmlAttributeNode
- CloudNimble.Text.Xml.Nodes.XmlElementNode
- CloudNimble.Text.Xml.Nodes.XmlNodeList