Gets or sets a value that indicates whether the XmlSerializer must serialize a member that is set to nullNothingnullptra 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)
Visual Basic (Declaration)
Public Property IsNullable As Boolean
Dim instance As XmlElementAttribute
Dim value As Boolean
value = instance.IsNullable
instance.IsNullable = value
public bool IsNullable { get; set; }
public:
property bool IsNullable {
bool get ();
void set (bool value);
}
public function get IsNullable () : boolean
public function set IsNullable (value : boolean)
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 (www.w3.org) 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 nullNothingnullptra null reference (Nothing in Visual Basic). For example if you set a field named MyStringArray to nullNothingnullptra 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 nullNothingnullptra null reference (Nothing in Visual Basic).
Note: |
|---|
You cannot apply the IsNullable property to a member typed as a value type because a value type cannot contain nullNothingnullptra null reference (Nothing in Visual Basic). Additionally, you cannot set this property to false for nullable value types. When such types are nullNothingnullptra 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 MyClass1
<XmlElement(IsNullable := False)> Public Group As String
End Class
public class MyClass
{
[XmlElement(IsNullable = false)]
public string Group;
}
public ref class MyClass
{
public:
[XmlElement(IsNullable=false)]
String^ Group;
};
public __gc class MyClass
{
public:
[XmlElement(IsNullable = false)]
String* Group;
};
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
.NET Framework
Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
.NET Compact Framework
Supported in: 3.5, 2.0, 1.0
XNA Framework
Supported in: 3.0, 2.0, 1.0
Reference