Skip to main content

Definition

Assembly: CloudNimble.XmlEssentials.dll Namespace: CloudNimble.Text.Xml.Serialization

Syntax

Summary

Represents the XML attributes and child elements that have no matching member and are captured by a member marked with XmlExtensionDataAttribute. This class cannot be inherited.

Usage

XmlExtensionData holds the attributes and child elements of an element that no member of your type maps. Add a member of this type, mark it with [XmlExtensionData], and the serializer fills it when it reads and writes its content back when it serializes. It is the XML counterpart of the dictionary that [JsonExtensionData] uses in System.Text.Json.
Both collections are created with the object and are never null. You can read them after deserializing, and add to them before serializing.

Examples

Round-trip content the type doesn’t declare

The Settings type maps only Theme. The document also has two attributes and two elements, one of each in a namespace. They are captured, and written back after the mapped member changes.
The code produces the following output:
View the complete sample on GitHub

Considerations

  • Position. When writing, unmapped attributes follow the mapped attributes and unmapped elements follow the mapped elements. Where an unmapped element stood among the mapped ones is not recorded.
  • Namespace declarations. xmlns attributes are not captured and are not written from Attributes. The writer declares the namespaces that the captured names need.
  • Prefixes. A captured attribute keeps the prefix it was read with, in the Prefix of its XmlName. An attribute that you add with a namespace and no prefix gets a generated prefix.
  • Serializer attributes. xsi:nil, xsi:type, and the id and ref attributes of reference handling are consumed by the serializer and are not captured.
  • Keys. XmlName equality ignores the prefix, so two attributes with the same local name and namespace are one entry.
  • Allocation. Each captured element is a mutable XmlElementNode tree. Capturing large unmapped subtrees costs one node for every element, attribute, and text run in them. If you don’t need the content, leave the member out and let the serializer skip it.
  • Thread safety. The object is an ordinary mutable class with a dictionary and a list. Don’t change it from several threads at once.

Constructors

.ctor

Syntax

.ctor Inherited

Inherited from object

Syntax

Properties

Attributes

Gets the XML attributes that have no matching member.

Syntax

Property Value

Type: System.Collections.Generic.Dictionary<CloudNimble.Text.Xml.XmlName, string> A dictionary that maps the name of each unmapped attribute to its value.

Elements

Gets the child elements that have no matching member.

Syntax

Property Value

Type: System.Collections.Generic.List<CloudNimble.Text.Xml.Nodes.XmlElementNode> A list of the unmapped child elements, in document order.

Methods

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

ReferenceEquals Inherited

Inherited from object

Syntax

Parameters

Returns

Type: bool

ToString Inherited Virtual

Inherited from object

Syntax

Returns

Type: string?
  • CloudNimble.Text.Xml.Serialization.XmlExtensionDataAttribute
  • CloudNimble.Text.Xml.Serialization.XmlUnmappedMemberHandling
  • CloudNimble.Text.Xml.XmlName
  • CloudNimble.Text.Xml.Nodes.XmlElementNode
  • CloudNimble.Text.Xml.XmlSerializerOptions