Share via


XmlRootAttribute.IsNullable Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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

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

Syntax

'Declaration
Public Property IsNullable As Boolean
public bool IsNullable { get; set; }

Property Value

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

Remarks

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 http://www.w3.org/TR/xmlschema-1/ specification, XML Schema Part 1: Structures.

If the IsNullable property is set to true, the xsi:nil attribute is generated as shown in the following XML.

 <?xml version="1.0" encoding="utf-8"?>
 <Group xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 xmlns:xsd="http://www.w3.org/2001/XMLSchema" xsi:nil="true" />

If the IsNullable property is false, an empty element is created as shown in the following code.

 <?xml version="1.0" encoding="utf-8"?>
 <Group xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 xmlns:xsd="http://www.w3.org/2001/XMLSchema" />

Examples

The following example serializes a class named Group. The example applies the XmlRootAttribute to the class, and sets the IsNullable property to false.

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.