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

# XmlAttributes

> Provides the local names of the XML Schema instance attributes that XmlEssentials reads and writes. This class cannot be inherited.

## Definition

**Assembly:** CloudNimble.XmlEssentials.dll

**Namespace:** CloudNimble.Text.Xml

## Syntax

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

## Summary

Provides the local names of the XML Schema instance attributes that XmlEssentials reads and writes.
This class cannot be inherited.

## Usage

`XmlAttributes` holds the local names of the two XML Schema instance attributes that XmlEssentials reads and writes: `Nil` (`"nil"`, for `xsi:nil`) and `Type` (`"type"`, for `xsi:type`). The constants are local names only. Pair them with the `XmlNamespaces.Xsi` namespace URI so that a lookup matches the attribute whatever prefix the document uses.

```csharp theme={"dark"}
const string xml = """
    <Order xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <ShippedOn xsi:nil="true"/>
      <Total>129.90</Total>
    </Order>
    """;

using XmlDocument document = XmlDocument.Parse(xml);
XmlElement shippedOn = document.RootElement.GetChild("ShippedOn");

output.WriteLine($"ValueKind: {shippedOn.ValueKind}");
output.WriteLine($"IsNil: {shippedOn.IsNil}");
output.WriteLine($"GetString returns null: {shippedOn.GetString() is null}");
output.WriteLine($"GetInnerText returns an empty string: {shippedOn.GetInnerText().Length == 0}");

try
{
    shippedOn.GetDateTimeOffset();
}
catch (XmlException ex)
{
    output.WriteLine(ex.Message);
}

XmlElement nil = shippedOn.GetAttribute(XmlAttributes.Nil, XmlNamespaces.Xsi);
output.WriteLine($"{nil.Prefix}:{nil.LocalName} = {nil.GetBoolean()}");
```

The code produces the following output:

```text theme={"dark"}
ValueKind: Nil
IsNil: True
GetString returns null: True
GetInnerText returns an empty string: True
The element is nil and has no value.
xsi:nil = True
```

To find out whether an element is nil, read `XmlElement.IsNil` instead of looking for the attribute yourself. For how the serializer uses these attributes, see [Handle null and nil](https://easyaf.nimbleapps.cloud/xmlessentials/guides/null-and-nil.md) and [Polymorphism](https://easyaf.nimbleapps.cloud/xmlessentials/guides/polymorphism.md).

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

## Remarks

The constants are local names only. Bind them to the [XmlNamespaces.Xsi](https://easyaf.nimbleapps.cloud/xmlessentials/api-reference/CloudNimble/Text/Xml/XmlNamespaces.md#xsi) namespace
when you write `xsi:nil` or `xsi:type`.

## Related APIs

* CloudNimble.Text.Xml.XmlNamespaces
* CloudNimble.Text.Xml.XmlElement
* CloudNimble.Text.Xml.Utf8XmlWriter


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