Windows apps
Collapse the table of content
Expand the table of content
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

XmlElementAttribute.IsNullable Property

Gets or sets a value that indicates whether the XmlSerializer must serialize a member that is set to a null reference (Nothing in Visual Basic) as an empty tag with the xsi:nil attribute set to true.

Namespace: System.Xml.Serialization
Assembly: System.Xml (in system.xml.dll)

public bool IsNullable { get; set; }
/** @property */
public boolean get_IsNullable ()

/** @property */
public void set_IsNullable (boolean value)

public function get IsNullable () : boolean

public function set IsNullable (value : boolean)

Not applicable.

Property Value

true if the XmlSerializer generates the xsi:nil attribute; otherwise, false.

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 a null reference (Nothing in Visual Basic). For example if you set a field named MyStringArray to a null reference (Nothing in Visual Basic), 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 a null reference (Nothing in Visual Basic).


You cannot apply the IsNullable property to a member typed as a value type because a value type cannot contain a null reference (Nothing in Visual Basic). Additionally, you cannot set this property to false for nullable value types. When such types are a null reference (Nothing in Visual Basic), they will be serialized by setting xsi:nil to true.

The following example shows a field with the XmlElementAttribute applied to it, and the IsNullable property set to false.

public class MyClass
   [XmlElement(IsNullable = false)]
   public string Group;

public class MyClass
    /** @attribute XmlElement(IsNullable = false)
    public String group;
} //MyClass

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0

Community Additions

© 2017 Microsoft