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 indicating whether the XmlSerializer should 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.

[Visual Basic]
Public Property IsNullable As Boolean
public bool IsNullable {get; set;}
public: __property bool get_IsNullable();
public: __property void set_IsNullable(bool);
public function get IsNullable() : Boolean;
public function set IsNullable(Boolean);

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), the XmlSerializer generates the following XML code.

<MyStringArray xsi:nil = "true" />

If the IsNullable property is false, no XML element is generated.

Note   You cannot apply the IsNullable property to a member typed as a value type because a value type cannot contain a null reference (Nothing).


[Visual Basic, C#, C++] The following example shows a field attributed with the XmlElementAttribute, and the IsNullable property set to false.

[Visual Basic] 
Public Class MyClass1
    <XmlElement(IsNullable := False)> Public Group As String
End Class

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

public __gc class MyClass
   [XmlElement(IsNullable = false)]
   String* Group;

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

XmlElementAttribute Class | XmlElementAttribute Members | System.Xml.Serialization Namespace

© 2017 Microsoft