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

# XmlCDataNode

> Represents a mutable XML CDATA section. This class cannot be inherited.

## Definition

**Assembly:** CloudNimble.XmlEssentials.dll

**Namespace:** CloudNimble.Text.Xml.Nodes

**Inheritance:** CloudNimble.Text.Xml.Nodes.XmlNode

## Syntax

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

## Summary

Represents a mutable XML CDATA section. This class cannot be inherited.

## Usage

`XmlCDataNode` is a CDATA section: text that is written between `<![CDATA[` and `]]>` without escaping. Use it for content that is full of markup characters, such as an HTML fragment or a script, when the reader of the file should see it unescaped. To a consumer, a CDATA section and the same text in an `XmlTextNode` mean the same thing; `XmlElementNode.InnerText` returns both.

```csharp theme={"dark"}
var note = new XmlElementNode("Note");
note.Add(new XmlCommentNode(" reviewed "));
note.Add(new XmlTextNode("Use ** & ** for bold. "));
note.Add(new XmlCDataNode("**Raw** & unescaped"));
note.Add(new XmlProcessingInstructionNode("print", "copies=\"2\""));
note.AddElement("Signature");

output.WriteLine(note.ToString());

foreach (XmlNode child in note.Children)
{
    output.WriteLine($"{child.GetType().Name}: {child.ValueKind}");
}

output.WriteLine($"InnerText: {note.InnerText}");
```

The code produces the following output:

```text theme={"dark"}
<Note><!-- reviewed -->Use &lt;b> &amp; &lt;/b> for bold. <![CDATA[**Raw** & unescaped]]><?print copies="2"?><Signature/></Note>
XmlCommentNode: Comment
XmlTextNode: Text
XmlCDataNode: CData
XmlProcessingInstructionNode: ProcessingInstruction
XmlElementNode: Element
InnerText: Use ** & ** for bold. **Raw** & unescaped
```

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

## Considerations

* The value can't contain `]]>`, which would end the section. The check happens when the node is written, and it throws an `XmlException` ("CDATA must not contain ']]>'."). The node doesn't split the value into two sections for you.
* A CDATA section in parsed XML stays a CDATA section in the tree and is written back as one.
* A `null` value is stored as an empty string.

## Constructors

### &#x20;.ctor

Initializes a new instance of the [XmlCDataNode](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Nodes/XmlCDataNode.md) class with the specified content.

#### Syntax

```csharp theme={"dark"}
public XmlCDataNode(string value = null)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `value` | `string?` | The content of the CDATA section. The default is [`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null), which is stored as an empty string. |

### &#x20;.ctor Inherited

> [!NOTE]
>
> Inherited from `CloudNimble.Text.Xml.Nodes.XmlNode`

#### Syntax

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

### &#x20;.ctor Inherited

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

#### Syntax

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

## Properties

### &#x20;NamespaceUri Inherited Virtual

> [!NOTE]
>
> Inherited from `CloudNimble.Text.Xml.Nodes.XmlNode`

Gets or sets the namespace URI of this node.

#### Syntax

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

#### 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`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null),
and setting it has no effect.

### &#x20;Parent Inherited

> [!NOTE]
>
> Inherited from `CloudNimble.Text.Xml.Nodes.XmlNode`

Gets the parent of this node.

#### Syntax

```csharp theme={"dark"}
public CloudNimble.Text.Xml.Nodes.XmlNode Parent { get; }
```

#### Property Value

Type: `CloudNimble.Text.Xml.Nodes.XmlNode?`
The element that holds this node as a child or as an attribute, or [`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null) if this
node has no parent.

### &#x20;Value

Gets or sets the content of this CDATA section.

#### Syntax

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

#### Property Value

Type: `string`
The text between `<![CDATA[` and `]]>`.

### &#x20;ValueKind Override

#### Syntax

```csharp theme={"dark"}
public override CloudNimble.Text.Xml.XmlValueKind ValueKind { get; }
```

#### Property Value

Type: `CloudNimble.Text.Xml.XmlValueKind`

### &#x20;ValueKind Inherited Abstract

> [!NOTE]
>
> Inherited from `CloudNimble.Text.Xml.Nodes.XmlNode`

When overridden in a derived class, gets the kind of this node.

#### Syntax

```csharp theme={"dark"}
public abstract CloudNimble.Text.Xml.XmlValueKind ValueKind { get; }
```

#### Property Value

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

## Methods

### &#x20;DeepClone Override

#### Syntax

```csharp theme={"dark"}
public override CloudNimble.Text.Xml.Nodes.XmlNode DeepClone()
```

#### Returns

Type: `CloudNimble.Text.Xml.Nodes.XmlNode`

### &#x20;DeepClone Inherited Abstract

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

```csharp theme={"dark"}
public abstract CloudNimble.Text.Xml.Nodes.XmlNode DeepClone()
```

#### Returns

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

### &#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 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;Parse Inherited

> [!NOTE]
>
> Inherited from `CloudNimble.Text.Xml.Nodes.XmlNode`

Parses a string that holds a single XML document into a mutable tree.

#### Syntax

```csharp theme={"dark"}
public static CloudNimble.Text.Xml.Nodes.XmlNode Parse(string xml)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `xml` | `string` | The XML text to parse. |

#### Returns

Type: `CloudNimble.Text.Xml.Nodes.XmlNode`
An [XmlNode](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Nodes/XmlNode.md) representation of the document element.

#### Exceptions

| Exception | Description |
| - | - |
| `ArgumentNullException` | *xml* is [`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null). |
| `XmlException` | *xml* is not a well-formed XML document. |
| -or- | |
| *xml* exceeds a default limit of [XmlDocumentOptions](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlDocumentOptions.md). | |

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

### &#x20;Parse Inherited

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

```csharp theme={"dark"}
public static CloudNimble.Text.Xml.Nodes.XmlNode Parse(System.ReadOnlySpan<byte> xml)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `xml` | `System.ReadOnlySpan<byte>` | The UTF-8 encoded XML text to parse. |

#### Returns

Type: `CloudNimble.Text.Xml.Nodes.XmlNode`
An [XmlNode](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Nodes/XmlNode.md) representation of the document element.

#### Exceptions

| Exception | Description |
| - | - |
| `XmlException` | *xml* is not a well-formed XML document. |
| -or- | |
| *xml* exceeds a default limit of [XmlDocumentOptions](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlDocumentOptions.md). | |

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

### &#x20;ParseValue Inherited

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

```csharp theme={"dark"}
public static CloudNimble.Text.Xml.Nodes.XmlNode ParseValue(ref CloudNimble.Text.Xml.Utf8XmlReader reader)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `reader` | `CloudNimble.Text.Xml.Utf8XmlReader` | The reader to read. It is positioned on or before the start tag of the element. |

#### Returns

Type: `CloudNimble.Text.Xml.Nodes.XmlNode`
An [XmlNode](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/Nodes/XmlNode.md) representation of the element (and nested nodes) read from the reader.

#### Exceptions

| Exception | Description |
| - | - |
| `XmlException` | *reader* reaches an end tag before it reaches a start tag. |
| -or- | |
| *reader* reaches the end of its input without reading an element. | |
| -or- | |
| The XML that *reader* reads is not well formed. | |

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

### &#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;SetParent Inherited

> [!NOTE]
>
> Inherited from `CloudNimble.Text.Xml.Nodes.XmlNode`

Sets the parent pointer.

#### Syntax

```csharp theme={"dark"}
internal void SetParent(CloudNimble.Text.Xml.Nodes.XmlNode parent)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `parent` | `CloudNimble.Text.Xml.Nodes.XmlNode?` | The parent, or [`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null). |

### &#x20;ToString Override

> [!NOTE]
>
> Inherited from `CloudNimble.Text.Xml.Nodes.XmlNode`

Converts the current instance to a string that holds its XML markup.

#### Syntax

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

#### Returns

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

#### Exceptions

| Exception | Description |
| - | - |
| `XmlException` | The tree cannot be written as XML, for example because a name has a prefix but no namespace. |

### &#x20;ToString Inherited Virtual

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

#### Syntax

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

#### Returns

Type: `string?`

### &#x20;WriteTo Override

#### Syntax

```csharp theme={"dark"}
public override void WriteTo(CloudNimble.Text.Xml.Utf8XmlWriter writer)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `writer` | `CloudNimble.Text.Xml.Utf8XmlWriter` | - |

### &#x20;WriteTo Inherited Abstract

> [!NOTE]
>
> Inherited from `CloudNimble.Text.Xml.Nodes.XmlNode`

When overridden in a derived class, writes this node to the provided writer as XML.

#### Syntax

```csharp theme={"dark"}
public abstract void WriteTo(CloudNimble.Text.Xml.Utf8XmlWriter writer)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `writer` | `CloudNimble.Text.Xml.Utf8XmlWriter` | The writer to which to write the node. |

#### Exceptions

| Exception | Description |
| - | - |
| `ArgumentNullException` | *writer* is [`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null). |

## Related APIs

* CloudNimble.Text.Xml.Nodes.XmlTextNode
* CloudNimble.Text.Xml.Nodes.XmlElementNode
* CloudNimble.Text.Xml.Nodes.XmlNode
* CloudNimble.Text.Xml.Utf8XmlWriter


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