IsNullable Property
Collapse the table of content
Expand the table of content

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
[C#]
public bool IsNullable {get; set;}
[C++]
public: __property bool get_IsNullable();
public: __property void set_IsNullable(bool);
[JScript]
public function get IsNullable() : Boolean;
public function set IsNullable(Boolean);

Property Value

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 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 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).

Example

[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


[C#] 
public class MyClass
{
   [XmlElement(IsNullable = false)]
   public string Group;
}


[C++] 
public __gc class MyClass
{
public:
   [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.

Requirements

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

Show:
© 2016 Microsoft