XmlElementAttribute.IsNullable Property
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets or sets a value that indicates whether the XmlSerializer must serialize a member that is set to null
as an empty tag with the xsi:nil
attribute set to true
.
public:
property bool IsNullable { bool get(); void set(bool value); };
public bool IsNullable { get; set; }
member this.IsNullable : bool with get, set
Public Property IsNullable As Boolean
true
if the XmlSerializer generates the xsi:nil
attribute; otherwise, false
.
The following example shows a field with the XmlElementAttribute applied to it, and the IsNullable property set to false
.
public ref class MyClass
{
public:
[XmlElement(IsNullable=false)]
String^ Group;
};
public class MyClass
{
[XmlElement(IsNullable = false)]
public string Group;
}
Public Class MyClass1
<XmlElement(IsNullable := False)> Public Group As String
End Class
The XML schema specification for structures allows an XML document to explicitly signal that an element's content is missing. Such an element contains the attribute xsi:nil
set to true
. For more information, see the World Wide Web Consortium specification, XML Schema Part 1: Structures.
If the IsNullable property is set to true
, the xsi:nil
attribute is generated for class members that have been set to null
. For example if you set a field named MyStringArray
to null
, the XmlSerializer generates the following XML code.
<MyStringArray xsi:nil = "true" />
If the IsNullable property is false
, no XML element is generated for class members that have been set to null
.
Note
You cannot apply the IsNullable property to a member typed as a value type because a value type cannot contain null
. Additionally, you cannot set this property to false
for nullable value types. When such types are null
, they will be serialized by setting xsi:nil
to true
.
Product | Versions |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0, 2.1 |
UWP | 10.0 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: