XmlArrayItemAttribute.IsNullable プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > XmlArrayItemAttribute.IsNullable プロパティの意味・解説 

XmlArrayItemAttribute.IsNullable プロパティ

XmlSerializer で、xsi:nil 属性が true に設定された空の XML タグとしてメンバをシリアル化する必要があるかどうかを示す値を取得または設定します。

名前空間: System.Xml.Serialization
アセンブリ: System.Xml (system.xml.dll 内)
構文構文

Dim instance As XmlArrayItemAttribute
Dim value As Boolean

value = instance.IsNullable

instance.IsNullable = value
public bool IsNullable { get;
 set; }
/** @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 コードを生成します。

 <MyStringArray xsi:nil = "true" />

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
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
XmlArrayItemAttribute クラス
XmlArrayItemAttribute メンバ
System.Xml.Serialization 名前空間



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

XmlArrayItemAttribute.IsNullable プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



XmlArrayItemAttribute.IsNullable プロパティのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS