XmlArrayItemAttribute.IsNullable プロパティ
アセンブリ: System.Xml (system.xml.dll 内)

Dim instance As XmlArrayItemAttribute Dim value As Boolean value = instance.IsNullable instance.IsNullable = value
/** @property */ public boolean get_IsNullable () /** @property */ public void set_IsNullable (boolean value)
XmlSerializer が xsi:nil 属性を生成する場合は true。それ以外の場合は false で、インスタンスは作成されません。既定値は true です。

XML スキーマで構造を指定することにより、XML ドキュメントで、要素の内容が欠落していることを明示的に知らせることができます。このような要素には、true に設定された属性 xsi:nil が含まれます。詳細については、W3C (World Wide Web Consortium) のサイト (www.w3.org) で『XML Schema Part 1: Structures』という仕様を参照してください。
IsNullable プロパティが true の場合は、null 参照 (Visual Basic では Nothing) に設定されているクラス メンバのために xsi:nil 属性が生成されます。たとえば、MyStringArray というフィールドを null 参照 (Visual Basic では Nothing) に設定すると、XmlSerializer は次の XML コードを生成します。
IsNullable プロパティが false に設定されている場合は、XML 要素が生成されません。
![]() |
---|
値型には null 参照 (Visual Basic では Nothing) を指定できないため、IsNullable プロパティは、値型として指定されたメンバには適用できません。 |

Group というクラスをシリアル化する例を次に示します。このクラスには、Employee オブジェクトの配列を返す Employees というフィールドが含まれています。Manager という 2 番目のクラスは、Employee クラスから派生します。XmlArrayItemAttribute は、XmlSerializer が Employee オブジェクトと Manager オブジェクトの両方を配列に挿入できるように指定します。この例では IsNullable プロパティを設定し、その結果、null 参照 (Visual Basic では Nothing) に設定されている配列では xsi:nil 属性オブジェクトを生成しないように XmlSerializer に指示します。
Option Explicit Option Strict Imports System Imports System.IO Imports System.Xml.Serialization Public Class Group <XmlArray(IsNullable := True), _ XmlArrayItem(GetType(Manager), IsNullable := False), _ XmlArrayItem(GetType(Employee), IsNullable := False)> _ Public Employees() As Employee End Class Public Class Employee Public Name As String End Class Public Class Manager Inherits Employee Public Level As Integer End Class Public Class Run Public Shared Sub Main() Dim test As New Run() test.SerializeObject("TypeDoc.xml") End Sub Public Sub SerializeObject(filename As String) Dim s As New XmlSerializer(GetType(Group)) ' To write the file, a TextWriter is required. Dim writer As New StreamWriter(filename) ' Creates the object to serialize. Dim group As New Group() ' Creates a null Manager object. Dim mgr As Manager = Nothing ' Creates a null Employee object. Dim y As Employee = Nothing group.Employees = New Employee() {mgr, y} ' Serializes the object and closes the TextWriter. s.Serialize(writer, group) writer.Close() End Sub End Class
using System; using System.IO; using System.Xml.Serialization; public class Group { [XmlArray(IsNullable = true)] [XmlArrayItem(typeof(Manager), IsNullable = false), XmlArrayItem(typeof(Employee), IsNullable = false)] public Employee[] Employees; } public class Employee { public string Name; } public class Manager:Employee { public int Level; } public class Run { public static void Main() { Run test = new Run(); test.SerializeObject("TypeDoc.xml"); } public void SerializeObject(string filename) { XmlSerializer s = new XmlSerializer(typeof(Group)); // To write the file, a TextWriter is required. TextWriter writer = new StreamWriter(filename); // Creates the object to serialize. Group group = new Group(); // Creates a null Manager object. Manager mgr = null; // Creates a null Employee object. Employee y = null; group.Employees = new Employee[2] {mgr, y}; // Serializes the object and closes the TextWriter. s.Serialize(writer, group); writer.Close(); } }
#using <System.Xml.dll> #using <System.dll> using namespace System; using namespace System::IO; using namespace System::Xml::Serialization; public ref class Employee { public: String^ Name; }; public ref class Manager: public Employee { public: int Level; }; public ref class Group { public: [XmlArray(IsNullable=true)] [XmlArrayItem(Manager::typeid,IsNullable=false), XmlArrayItem(Employee::typeid,IsNullable=false)] array<Employee^>^Employees; }; void SerializeObject( String^ filename ) { XmlSerializer^ s = gcnew XmlSerializer( Group::typeid ); // To write the file, a TextWriter is required. TextWriter^ writer = gcnew StreamWriter( filename ); // Creates the object to serialize. Group^ group = gcnew Group; // Creates a null Manager object. Manager^ mgr = nullptr; // Creates a null Employee object. Employee^ y = nullptr; array<Employee^>^temp = {mgr,y}; group->Employees = temp; // Serializes the object and closes the TextWriter. s->Serialize( writer, group ); writer->Close(); } int main() { SerializeObject( "TypeDoc.xml" ); }
import System.*; import System.IO.*; import System.Xml.Serialization.*; public class Group { /** @attribute XmlArray(IsNullable = true) */ /** @attribute XmlArrayItem(Manager.class, IsNullable = false) @attribute XmlArrayItem(Employee.class, IsNullable = false) */ public Employee employees[]; } //Group public class Employee { public String name; } //Employee public class Manager extends Employee { public int level; } //Manager public class Run { public static void main(String[] args) { Run test = new Run(); test.SerializeObject("TypeDoc.xml"); } //main public void SerializeObject(String filename) { XmlSerializer s = new XmlSerializer(Group.class.ToType()); // To write the file, a TextWriter is required. TextWriter writer = new StreamWriter(filename); // Creates the object to serialize. Group group = new Group(); // Creates a null Manager object. Manager mgr = null; // Creates a null Employee object. Employee y = null; group.employees = new Employee[] { mgr, y }; // Serializes the object and closes the TextWriter. s.Serialize(writer, group); writer.Close(); } //SerializeObject } //Run

Windows 98, Windows 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
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からXmlArrayItemAttribute.IsNullable プロパティを検索する場合は、下記のリンクをクリックしてください。

- XmlArrayItemAttribute.IsNullable プロパティのページへのリンク