Skip to main content

Definition

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

Syntax

Summary

Represents a mutable XML attribute. This class cannot be inherited.

Usage

XmlAttributeNode is an attribute in the mutable tree: a LocalName, a Value, and, for an attribute in a namespace, a NamespaceUri and a Prefix. Attributes live in the Attributes list of an XmlElementNode. Most code doesn’t create one directly. XmlElementNode.SetAttribute creates or updates an attribute, and Attributes["name"] returns the node so that you can read or change its Value. Construct an XmlAttributeNode yourself when you need to choose the prefix.
The code produces the following output:
View the complete sample on GitHub

Considerations

  • An attribute without a prefix is in no namespace, even when its element is in a default namespace. To put an attribute in a namespace, give it a NamespaceUri and a Prefix. With a namespace and no prefix, the writer generates one:
    The code produces the following output:
  • A namespace declaration is an attribute too. In a parsed tree, xmlns="..." has the local name xmlns, and xmlns:dc="..." has the prefix xmlns and the local name dc; both report XmlNamespaces.Xmlns as their namespace.
  • Value is the plain value. Escaping happens when the attribute is written. A null value, prefix, or namespace is stored as an empty string.
  • LocalName rejects null, an empty string, and white space.
  • ToString on an attribute throws an XmlException, because an attribute can’t be written outside a start tag. Read Value.
  • An attribute has one parent. Adding it to a second element throws; use DeepClone to copy it.

Constructors

.ctor

Initializes a new instance of the XmlAttributeNode class with the specified local name, value, namespace URI, and prefix.

Syntax

Parameters

Exceptions

.ctor Inherited

Inherited from CloudNimble.Text.Xml.Nodes.XmlNode

Syntax

.ctor Inherited

Inherited from object

Syntax

Properties

LocalName

Gets or sets the local name of this attribute.

Syntax

Property Value

Type: string The local name of the attribute, without a prefix.

Exceptions

NamespaceUri Override

Gets or sets the namespace URI of this attribute.

Syntax

Property Value

Type: string? The namespace URI of the attribute, or an empty string if the attribute is in no namespace. The value is never null. Setting null stores an empty string.

NamespaceUri Inherited Virtual

Inherited from CloudNimble.Text.Xml.Nodes.XmlNode
Gets or sets the namespace URI of this node.

Syntax

Property Value

Type: string? The namespace URI of the node. An element or an attribute in no namespace gives an empty string. For a node that is not an element or an attribute, the value is always null, and setting it has no effect.

Parent Inherited

Inherited from CloudNimble.Text.Xml.Nodes.XmlNode
Gets the parent of this node.

Syntax

Property Value

Type: CloudNimble.Text.Xml.Nodes.XmlNode? The element that holds this node as a child or as an attribute, or null if this node has no parent.

Prefix

Gets or sets the namespace prefix of this attribute.

Syntax

Property Value

Type: string The prefix of the attribute name, or an empty string if the name has no prefix. Setting null stores an empty string.

Value

Gets or sets the value of this attribute.

Syntax

Property Value

Type: string The value of the attribute, without escaping. Setting null stores an empty string.

ValueKind Override

Syntax

Property Value

Type: CloudNimble.Text.Xml.XmlValueKind

ValueKind Inherited Abstract

Inherited from CloudNimble.Text.Xml.Nodes.XmlNode
When overridden in a derived class, gets the kind of this node.

Syntax

Property Value

Type: CloudNimble.Text.Xml.XmlValueKind One of the enumeration values that indicates the kind of this node.

Methods

DeepClone Override

Syntax

Returns

Type: CloudNimble.Text.Xml.Nodes.XmlNode

DeepClone Inherited Abstract

Inherited from CloudNimble.Text.Xml.Nodes.XmlNode
When overridden in a derived class, creates a new instance of the node. All children and attributes are recursively cloned.

Syntax

Returns

Type: CloudNimble.Text.Xml.Nodes.XmlNode A new cloned instance of the current node. The clone has no parent.

Equals Inherited Virtual

Inherited from object

Syntax

Parameters

Returns

Type: bool

Equals Inherited

Inherited from object

Syntax

Parameters

Returns

Type: bool

GetHashCode Inherited Virtual

Inherited from object

Syntax

Returns

Type: int

GetType Inherited

Inherited from object

Syntax

Returns

Type: System.Type

MemberwiseClone Inherited

Inherited from object

Syntax

Returns

Type: object

Parse Inherited

Inherited from CloudNimble.Text.Xml.Nodes.XmlNode
Parses a string that holds a single XML document into a mutable tree.

Syntax

Parameters

Returns

Type: CloudNimble.Text.Xml.Nodes.XmlNode An XmlNode representation of the document element.

Exceptions

Remarks

Comments inside the document element are kept. The XML declaration and any comments or processing instructions outside the document element are not part of the returned tree.

Parse Inherited

Inherited from CloudNimble.Text.Xml.Nodes.XmlNode
Parses a span of UTF-8 bytes that holds a single XML document into a mutable tree.

Syntax

Parameters

Returns

Type: CloudNimble.Text.Xml.Nodes.XmlNode An XmlNode representation of the document element.

Exceptions

Remarks

Comments inside the document element are kept. The XML declaration and any comments or processing instructions outside the document element are not part of the returned tree.

ParseValue Inherited

Inherited from CloudNimble.Text.Xml.Nodes.XmlNode
Parses one XML element (including its attributes and descendants) from the provided reader into a mutable tree.

Syntax

Parameters

Returns

Type: CloudNimble.Text.Xml.Nodes.XmlNode An XmlNode representation of the element (and nested nodes) read from the reader.

Exceptions

Remarks

When this method returns, the reader is positioned on the end tag of the element, or on the element itself if it is an empty-element tag. Comments are kept only if the reader reports them.

ReferenceEquals Inherited

Inherited from object

Syntax

Parameters

Returns

Type: bool

SetParent Inherited

Inherited from CloudNimble.Text.Xml.Nodes.XmlNode
Sets the parent pointer.

Syntax

Parameters

ToString Override

Inherited from CloudNimble.Text.Xml.Nodes.XmlNode
Converts the current instance to a string that holds its XML markup.

Syntax

Returns

Type: string The XML markup of this node, including its attributes and descendants. No XML declaration is added.

Exceptions

ToString Inherited Virtual

Inherited from object

Syntax

Returns

Type: string?

WriteTo Override

Syntax

Parameters

WriteTo Inherited Abstract

Inherited from CloudNimble.Text.Xml.Nodes.XmlNode
When overridden in a derived class, writes this node to the provided writer as XML.

Syntax

Parameters

Exceptions

  • CloudNimble.Text.Xml.Nodes.XmlAttributeNodeList
  • CloudNimble.Text.Xml.Nodes.XmlElementNode
  • CloudNimble.Text.Xml.Nodes.XmlNode
  • CloudNimble.Text.Xml.XmlNamespaces
  • CloudNimble.Text.Xml.XmlAttributes