Skip to main content

Definition

Assembly: CloudNimble.XmlEssentials.dll Namespace: CloudNimble.Text.Xml Inheritance: System.Enum

Syntax

Summary

Specifies how a property or field without a mapping attribute is mapped: as a child element or as an XML attribute.

Usage

XmlPropertyMapping says what a member becomes in XML when it has no [XmlElement], [XmlAttribute], or [XmlText] attribute. Set it through XmlSerializerOptions.DefaultPropertyMapping. Use Attribute for formats that put most values in attributes, so you don’t have to annotate every property:
The code produces the following output:
View the complete sample on GitHub

Considerations

  • The setting applies to every type serialized with the options, so the simple members of nested objects become XML attributes too.
  • A mapping attribute on a member always wins. With Attribute as the default, mark a member with [XmlElement] to keep it as an element.
  • An XML attribute can’t be marked nil. A member that is null and mapped to an attribute is left out, so with Attribute a null value and a missing value look the same in the XML.
  • Attribute names come from AttributeNamingPolicy, or from PropertyNamingPolicy when that is null.
  • Use the same options to read the XML back. A member that is mapped to an attribute isn’t read from an element of the same name.

Values

  • CloudNimble.Text.Xml.XmlSerializerOptions
  • CloudNimble.Text.Xml.Serialization.XmlAttributeAttribute
  • CloudNimble.Text.Xml.Serialization.XmlElementAttribute
  • CloudNimble.Text.Xml.Serialization.XmlTextAttribute