Skip to main content

Definition

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

Syntax

Summary

Specifies that a member is serialized as a child element of type T. This class cannot be inherited.

Usage

Apply [XmlElement] to a property or field to say that it is a child element and, optionally, to set the element’s name, namespace, or order. A member is an element by default, so you need the attribute in three cases:
  • To name the element, as an alternative to [XmlPropertyName].
  • To keep one member as an element when XmlSerializerOptions.DefaultPropertyMapping is XmlPropertyMapping.Attribute.
  • To set Namespace or Order.
On a collection that has no [XmlArray], the name applies to each repeated item:
The code produces the following output:
View the complete sample on GitHub

Type Parameters

  • T - The type that is serialized with the element name.

Considerations

  • [XmlPropertyName] on the same member takes precedence over ElementName, and [XmlPropertyOrder] takes precedence over Order.
  • A name set here isn’t converted by a naming policy.
  • Order follows the rules of [XmlPropertyOrder]: values of zero or more are written first in ascending order, and a negative value, the default, means the order isn’t set.
  • A member can’t be both an element and something else. [XmlElement] together with [XmlAttribute], [XmlText], or [XmlCData] throws a NotSupportedException the first time the type is used.
  • Several [XmlElement<T>] on one member make a choice of elements: each element name stands for a type, a value is written under the element of its type, and an element is read as the type of its name. On a collection, each item is written under the element of its own type. A value of the member’s own type is written under the member’s name. When two elements hold the same type, declare the member as XmlNamedValue, or a collection of it, so each value carries the name of its element. See Polymorphism.
  • A member can have one [XmlElement] without a type argument. A second one, or one next to [XmlElement<T>], throws a NotSupportedException the first time the type is used.

Constructors

.ctor

Initializes a new instance of the XmlElementAttribute1` class that uses the default element name: the member name, or the element name of T when the member has more than one of these attributes.

Syntax

.ctor

Initializes a new instance of the XmlElementAttribute1` class with the specified element name.

Syntax

Parameters

Exceptions

.ctor

Initializes a new instance of the XmlElementAttribute1` class with the specified element name and namespace.

Syntax

Parameters

Exceptions

.ctor Inherited

Inherited from CloudNimble.Text.Xml.Serialization.XmlElementAttribute
Initializes a new instance of the XmlElementAttribute class that uses the member name as the element name.

Syntax

.ctor Inherited

Inherited from CloudNimble.Text.Xml.Serialization.XmlElementAttribute
Initializes a new instance of the XmlElementAttribute class with the specified element name.

Syntax

Parameters

Exceptions

.ctor Inherited

Inherited from CloudNimble.Text.Xml.Serialization.XmlElementAttribute
Initializes a new instance of the XmlElementAttribute class with the specified element name and namespace.

Syntax

Parameters

Exceptions

.ctor Inherited

Inherited from System.Attribute

Syntax

.ctor Inherited

Inherited from object

Syntax

Properties

ElementName Inherited

Inherited from CloudNimble.Text.Xml.Serialization.XmlElementAttribute
Gets or sets the local name of the element.

Syntax

Property Value

Type: string? The local name of the element. If the value is null or empty, the member name is used, converted by the element naming policy. The default is null.

Remarks

An XmlPropertyNameAttribute on the same member takes precedence over this property.

IsNullable Inherited

Inherited from CloudNimble.Text.Xml.Serialization.XmlElementAttribute
Gets or sets a value that indicates whether the member is nillable.

Syntax

Property Value

Type: bool true if the member is nillable; otherwise, false. The default is false.

Remarks

A member whose type is a reference type, a Nullable`1, or a collection is nillable whatever this value is.

Namespace Inherited

Inherited from CloudNimble.Text.Xml.Serialization.XmlElementAttribute
Gets or sets the namespace URI of the element.

Syntax

Property Value

Type: string? The namespace URI of the element. If the value is null, the element is written with an unqualified name, so it is in the default namespace that is in scope. An empty string puts the element in no namespace. The default is null.

Remarks

An element in no namespace is written with xmlns="" where a default namespace is in scope, and only an element in no namespace is read as the member.

Order Inherited

Inherited from CloudNimble.Text.Xml.Serialization.XmlElementAttribute
Gets or sets the order of the element among the child elements of the containing type.

Syntax

Property Value

Type: int The order of the element. Lower values are written first. A negative value means the order is not set. The default is -1.

Remarks

An XmlPropertyOrderAttribute on the same member takes precedence over this property.

Type Override

Syntax

Property Value

Type: System.Type

Type Inherited Virtual

Inherited from CloudNimble.Text.Xml.Serialization.XmlElementAttribute
Gets the type that is serialized with XmlElementAttribute.ElementName.

Syntax

Property Value

Type: System.Type? The type that the element name applies to, or null if the type of the member is used.

TypeId Inherited Virtual

Inherited from System.Attribute

Syntax

Property Value

Type: object

Methods

Equals Override

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: bool

Equals Inherited Virtual

Inherited from object

Syntax

Parameters

Returns

Type: bool

Equals Inherited

Inherited from object

Syntax

Parameters

Returns

Type: bool

GetCustomAttribute Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute?

GetCustomAttribute Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute?

GetCustomAttribute Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute?

GetCustomAttribute Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute?

GetCustomAttribute Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute?

GetCustomAttribute Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute?

GetCustomAttribute Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute?

GetCustomAttribute Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute?

GetCustomAttributes Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute[]

GetCustomAttributes Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute[]

GetCustomAttributes Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute[]

GetCustomAttributes Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute[]

GetCustomAttributes Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute[]

GetCustomAttributes Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute[]

GetCustomAttributes Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute[]

GetCustomAttributes Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute[]

GetCustomAttributes Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute[]

GetCustomAttributes Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute[]

GetCustomAttributes Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute[]

GetCustomAttributes Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute[]

GetCustomAttributes Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute[]

GetCustomAttributes Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute[]

GetCustomAttributes Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute[]

GetCustomAttributes Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: System.Attribute[]

GetHashCode Override

Inherited from System.Attribute

Syntax

Returns

Type: int

GetHashCode Inherited Virtual

Inherited from object

Syntax

Returns

Type: int

GetType Inherited

Inherited from object

Syntax

Returns

Type: System.Type

IsDefaultAttribute Inherited Virtual

Inherited from System.Attribute

Syntax

Returns

Type: bool

IsDefined Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: bool

IsDefined Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: bool

IsDefined Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: bool

IsDefined Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: bool

IsDefined Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: bool

IsDefined Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: bool

IsDefined Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: bool

IsDefined Inherited

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: bool

Match Inherited Virtual

Inherited from System.Attribute

Syntax

Parameters

Returns

Type: bool

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.XmlPropertyNameAttribute
  • CloudNimble.Text.Xml.Serialization.XmlPropertyOrderAttribute
  • CloudNimble.Text.Xml.Serialization.XmlAttributeAttribute
  • CloudNimble.Text.Xml.Serialization.XmlTextAttribute
  • CloudNimble.Text.Xml.Serialization.XmlArrayAttribute
  • CloudNimble.Text.Xml.XmlPropertyMapping