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

# XmlDeclarationInfo

> Represents the XML declaration captured when an [XmlDocument](/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlDocument) is parsed.

## Definition

**Assembly:** CloudNimble.XmlEssentials.dll

**Namespace:** CloudNimble.Text.Xml

**Inheritance:** System.ValueType

## Syntax

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

## Summary

Represents the XML declaration captured when an [XmlDocument](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlDocument.md) is parsed.

## Usage

`XmlDeclarationInfo` is what `XmlDocument` keeps of a document's XML declaration: the version, the encoding, and the `standalone` flag. Read it from `XmlDocument.Declaration`, which is `null` when the document has no declaration.

```csharp theme={"dark"}
using var document = XmlDocument.Parse("<?xml version=\"1.1\" encoding=\"UTF-8\" standalone=\"yes\"?><Order/>"u8);

if (document.Declaration is XmlDeclarationInfo declaration)
{
    output.WriteLine($"Version: {declaration.Version}");
    output.WriteLine($"Encoding: {declaration.Encoding}");
    output.WriteLine($"Standalone: {declaration.Standalone}");
}

using var bare = XmlDocument.Parse("<Order/>"u8);
output.WriteLine($"A document without a declaration has one: {bare.Declaration.HasValue}");
```

```text theme={"dark"}
Version: 1.1
Encoding: utf-8
Standalone: True
A document without a declaration has one: False
```

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

See [How to use XmlDocument](https://easyaf.nimbleapps.cloud/xmlessentials/guides/use-xmldocument.md) for the rest of the document API.

## Remarks

The value is immutable. Mutable trees use `CloudNimble.Text.Xml.Nodes.XmlDeclarationNode` instead.

## Considerations

* **The values are normalized, not copied from the source.** For a parsed document, `Version` is `1.0` or `1.1`, and `Encoding` is always `utf-8`, however the document spelled it. In the example, the source says `UTF-8`.
* **`Standalone` has three states:** `true` for `standalone="yes"`, `false` for `standalone="no"`, and `null` when the declaration doesn't say.
* **A missing declaration isn't an error.** `XmlDocument.Declaration` is `null`, and the document is XML 1.0.
* **`XmlDocument` produces this type; `Utf8XmlReader` reports a token.** The reader reports the declaration as an `XmlTokenType.XmlDeclaration` token, with the version in `Utf8XmlReader.Version` and the pseudo-attributes, as written, in `ValueSpan`.
* **It's an immutable value.** In the tree that you can change, the declaration is a `CloudNimble.Text.Xml.Nodes.XmlDeclarationNode`.

## Constructors

### &#x20;.ctor

Initializes a new instance of the [XmlDeclarationInfo](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlDeclarationInfo.md) struct.

#### Syntax

```csharp theme={"dark"}
public XmlDeclarationInfo(string version, string encoding, bool? standalone)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `version` | `string` | The XML version named in the declaration, such as `1.0`. |
| `encoding` | `string` | The name of the encoding named in the declaration, such as `utf-8`. |
| `standalone` | `bool?` | The value of the `standalone` pseudo-attribute, or [`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null) if it is omitted. |

### &#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;Encoding

Gets the encoding named in the declaration.

#### Syntax

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

#### Property Value

Type: `string`
The name of the encoding. This is always `utf-8` for a document that
[XmlDocument](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlDocument.md) parsed, because no other encoding is accepted.

### &#x20;Standalone

Gets the value of the `standalone` pseudo-attribute of the declaration.

#### Syntax

```csharp theme={"dark"}
public bool? Standalone { get; }
```

#### Property Value

Type: `bool?`
[`true`](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool) if the declaration says `standalone="yes"`; [`false`](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool) if
it says `standalone="no"`; [`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null) if the pseudo-attribute is omitted.

### &#x20;Version

Gets the XML version named in the declaration.

#### Syntax

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

#### Property Value

Type: `string`
The version string, which is `1.0` or `1.1` for a document that
[XmlDocument](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlDocument.md) parsed.

## Methods

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

> [!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

> [!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.XmlDocument
* CloudNimble.Text.Xml.XmlVersion
* CloudNimble.Text.Xml.Utf8XmlReader
* CloudNimble.Text.Xml.XmlWriterOptions
* CloudNimble.Text.Xml.Nodes.XmlDeclarationNode


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