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)

プロパティ
XmlSerializerxsi: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 は、XmlSerializerEmployee オブジェクト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 名前空間


このページでは「.NET Framework クラス ライブラリ リファレンス」からXmlArrayItemAttribute.IsNullable プロパティを検索した結果を表示しています。
Weblioに収録されているすべての辞書からXmlArrayItemAttribute.IsNullable プロパティを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からXmlArrayItemAttribute.IsNullable プロパティ を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

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

   

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



XmlArrayItemAttribute.IsNullable プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS