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

# XmlName

> Represents a namespace-qualified XML name: a local name, a namespace URI, and an optional prefix.

## Definition

**Assembly:** CloudNimble.XmlEssentials.dll

**Namespace:** CloudNimble.Text.Xml

**Inheritance:** System.ValueType

## Syntax

```csharp theme={"dark"}
CloudNimble.Text.Xml.XmlName
```

## Summary

Represents a namespace-qualified XML name: a local name, a namespace URI, and an optional prefix.

## Usage

An `XmlName` is a qualified XML name: a local name, a namespace URI, and an optional prefix. The library uses it wherever a name has to carry its namespace, for example `XmlTypeInfo.RootName`, `XmlPropertyInfo.Name`, and the keys of `XmlExtensionData.Attributes`.

Create a name with the local name alone, or add the namespace URI and the prefix:

```csharp theme={"dark"}
var written = new XmlName("Invoice", "urn:example:billing", "b");
var expected = new XmlName("Invoice", "urn:example:billing");
var unqualified = new XmlName("Invoice");
```

Two names are equal when their local names and namespace URIs are equal. The prefix is kept so that a name can be written the way it was read, and it plays no part in equality or in hash codes.

## Remarks

Two names are equal when [XmlName.LocalName](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlName.md#localname) and [XmlName.NamespaceUri](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlName.md#namespaceuri) are equal by ordinal comparison.
[XmlName.Prefix](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlName.md#prefix) only affects how the name is written. It is not used for equality or for mapping.

## Examples

### Compare and print names

`ToString` returns `prefix:local` when the name has a prefix, `{uri}local` when it has a namespace and no prefix, and the local name otherwise.

```csharp theme={"dark"}
var written = new XmlName("Invoice", "urn:example:billing", "b");
var expected = new XmlName("Invoice", "urn:example:billing");
var unqualified = new XmlName("Invoice");

output.WriteLine(written);
output.WriteLine(expected);
output.WriteLine(unqualified);
output.WriteLine(written == expected);
output.WriteLine(written == unqualified);
```

The code produces the following output:

```text theme={"dark"}
b:Invoice
{urn:example:billing}Invoice
Invoice
True
False
```

[View the complete sample on GitHub](https://github.com/CloudNimble/XmlEssentials/blob/main/src/CloudNimble.XmlEssentials.Samples/14_Namespaces.cs)

## Considerations

* `XmlName` is a `readonly struct` that holds three string references. Copying it is cheap, and creating one allocates nothing beyond the strings you pass in.
* The constructor checks only that the local name isn't `null`, empty, or white space. It doesn't check that the parts are valid XML names.
* A `null` namespace URI or prefix passed to the constructor becomes an empty string, so `NamespaceUri` and `Prefix` are never `null` in a name you create.
* Comparison is ordinal. Namespace URIs are compared character by character, as the Namespaces in XML recommendation requires, so `urn:Example` and `urn:example` are different namespaces.
* The output of `ToString` is for display. The `{uri}local` form is not XML syntax.
* `default(XmlName)` doesn't go through the constructor, so its `LocalName`, `NamespaceUri`, and `Prefix` are all `null`. Don't use it as a name.

## Constructors

### &#x20;.ctor

Initializes a new instance of the [XmlName](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlName.md) struct with the specified local name, namespace URI, and prefix.

#### Syntax

```csharp theme={"dark"}
public XmlName(string localName, string namespaceUri = null, string prefix = null)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `localName` | `string` | The local name. It cannot be [`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null), empty, or white space. |
| `namespaceUri` | `string?` | The namespace URI, or [`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null) for no namespace. The default is [`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null). |
| `prefix` | `string?` | The prefix, or [`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null) for none. The default is [`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null). The prefix is not used for equality. |

#### Exceptions

| Exception | Description |
| - | - |
| `ArgumentNullException` | *localName* is [`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null). |
| `ArgumentException` | *localName* is empty or consists only of white-space characters. |

#### Examples

```csharp theme={"dark"}
var name = new XmlName("Person", "https://example.com", "e");
Console.WriteLine(name); // e:Person
```

#### Remarks

Pass a namespace URI without a prefix when the name is only compared with other names.
[XmlName.ToString](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlName.md#tostring) writes the prefix only when it is not empty.

### &#x20;.ctor Inherited

> [!NOTE]
>
> Inherited from `System.ValueType`

#### Syntax

```csharp theme={"dark"}
protected ValueType()
```

### &#x20;.ctor Inherited

> [!NOTE]
>
> Inherited from `object`

#### Syntax

```csharp theme={"dark"}
public Object()
```

## Properties

### &#x20;LocalName

Gets the local part of the name.

#### Syntax

```csharp theme={"dark"}
public string LocalName { get; }
```

#### Property Value

Type: `string`
The local name.

### &#x20;NamespaceUri

Gets the namespace URI of the name.

#### Syntax

```csharp theme={"dark"}
public string NamespaceUri { get; }
```

#### Property Value

Type: `string`
The namespace URI, or an empty string if the name is in no namespace.

### &#x20;Prefix

Gets the prefix of the name.

#### Syntax

```csharp theme={"dark"}
public string Prefix { get; }
```

#### Property Value

Type: `string`
The prefix, or an empty string if the name has no prefix.

## Methods

### &#x20;Equals

Determines whether this name and a specified [XmlName](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlName.md) have the same local name and namespace URI.

#### Syntax

```csharp theme={"dark"}
public bool Equals(CloudNimble.Text.Xml.XmlName other)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `other` | `CloudNimble.Text.Xml.XmlName` | The name to compare with this name. |

#### Returns

Type: `bool`
[`true`](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool) if *other* has the same local name and namespace URI as this name,
by ordinal comparison; otherwise, [`false`](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool).

### &#x20;Equals Override

Determines whether this name and a specified object are equal.

#### Syntax

```csharp theme={"dark"}
public override bool Equals(object obj)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `obj` | `object?` | The object to compare with this name. |

#### Returns

Type: `bool`
[`true`](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool) if *obj* is an [XmlName](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlName.md) with the same local name and
namespace URI as this name; otherwise, [`false`](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool).

### &#x20;Equals Override

> [!NOTE]
>
> Inherited from `System.ValueType`

#### Syntax

```csharp theme={"dark"}
public override bool Equals(object obj)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `obj` | `object?` | - |

#### Returns

Type: `bool`

### &#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;GetHashCode Override

Returns the hash code for this name, computed from [XmlName.LocalName](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlName.md#localname) and [XmlName.NamespaceUri](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlName.md#namespaceuri).

#### Syntax

```csharp theme={"dark"}
public override int GetHashCode()
```

#### Returns

Type: `int`
A 32-bit signed integer hash code.

### &#x20;GetHashCode Override

> [!NOTE]
>
> Inherited from `System.ValueType`

#### Syntax

```csharp theme={"dark"}
public override int GetHashCode()
```

#### Returns

Type: `int`

### &#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;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;ToString Override

Returns a string that represents this name.

#### Syntax

```csharp theme={"dark"}
public override string ToString()
```

#### Returns

Type: `string`
`prefix:local` if the name has a prefix; otherwise, `{uri}local` if the name has a namespace URI;
otherwise, the local name.

### &#x20;ToString Override

> [!NOTE]
>
> Inherited from `System.ValueType`

#### Syntax

```csharp theme={"dark"}
public override string ToString()
```

#### Returns

Type: `string?`

### &#x20;ToString Inherited Virtual

> [!NOTE]
>
> Inherited from `object`

#### Syntax

```csharp theme={"dark"}
public virtual string ToString()
```

#### Returns

Type: `string?`

## Related APIs

* CloudNimble.Text.Xml.XmlNamespaces
* CloudNimble.Text.Xml.Serialization.XmlExtensionData
* CloudNimble.Text.Xml.Serialization.XmlPropertyInfo
* CloudNimble.Text.Xml.Serialization.XmlTypeInfo
* CloudNimble.Text.Xml.Nodes.XmlElementNode


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