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

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

XmlRootAttribute.IsNullable プロパティ

XmlSerializer が、null 参照 (Visual Basic では Nothing) に設定されているメンバを、true設定されている xsi:nil 属性シリアル化するかどうかを示す値を取得または設定します

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

Dim instance As XmlRootAttribute
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

解説解説

XML スキーマ構造指定することにより、XML ドキュメントで、要素内容欠落していることを明示的に知らせることができますこのような要素には、true設定され属性 xsi:nil含まれます。詳細については、W3CWeb サイト (http://www.w3.org/TR/xmlschema-1/) で仕様XML Schema Part 1: Structures』を参照してください

IsNullable プロパティtrue設定されている場合は、次の XML の例で示すように、xsi:nil 属性生成されます。

 <?xml version="1.0" encoding="utf-8"?>
 <Group xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 xmlns:xsd="http://www.w3.org/2001/XMLSchema" xsi:nil="true" />

IsNullable プロパティfalse場合は、次のコードに示すように、空の要素作成されます。

 <?xml version="1.0" encoding="utf-8"?>
 <Group xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
使用例使用例

Group というクラスシリアル化する例を次に示します。この例では、XmlRootAttribute をクラス適用しIsNullable プロパティfalse設定します

Imports System
Imports System.IO
Imports System.Xml.Serialization
Imports System.Xml


' Apply the XmlRootAttribute and set the IsNullable property to false.
<XmlRoot(IsNullable := False)> _
Public Class Group
    Public Name As String
End Class


Public Class Run
    
    Public Shared Sub Main()
        Console.WriteLine("Running")
        Dim test As New
 Run()
        test.SerializeObject("NullDoc.xml")
    End Sub     
    
    Public Sub SerializeObject(ByVal
 filename As String)
        Dim s As New XmlSerializer(GetType(Group))
        
        ' Writing the file requires a TextWriter.
        Dim writer As New
 StreamWriter(filename)
        
        ' Create the object to serialize.
        Dim mygroup As Group = Nothing
        
        ' Serialize the object, and close the TextWriter.
        s.Serialize(writer, mygroup)
        writer.Close()
    End Sub
End Class

using System;
using System.IO;
using System.Xml.Serialization;
using System.Xml;

// Apply the XmlRootAttribute and set the IsNullable property to false.
[XmlRoot(IsNullable = false)]
public class Group
{   
   public string Name;
}   


public class Run
{
   public static void Main()
   {
   Console.WriteLine("Running");
      Run test = new Run();
      test.SerializeObject("NullDoc.xml");

   }

   public void SerializeObject(string
 filename)
   {
      XmlSerializer s = new XmlSerializer(typeof(Group));

      // Writing the file requires a TextWriter.
      TextWriter writer = new StreamWriter(filename);

      // Create the object to serialize.
      Group mygroup = null;
      
      // Serialize the object, and close the TextWriter.
      s.Serialize(writer, mygroup);
      writer.Close();
   }
}
   
#using <System.Xml.dll>
#using <System.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml::Serialization;
using namespace System::Xml;

// Apply the XmlRootAttribute and set the IsNullable property to false.

[XmlRoot(IsNullable=false)]
public ref class Group
{
public:
   String^ Name;
};

void SerializeObject( String^ filename )
{
   XmlSerializer^ s = gcnew XmlSerializer( Group::typeid );

   // Writing the file requires a TextWriter.
   TextWriter^ writer = gcnew StreamWriter( filename );

   // Create the object to serialize.
   Group^ mygroup = nullptr;

   // Serialize the object, and close the TextWriter.
   s->Serialize( writer, mygroup );
   writer->Close();
}

int main()
{
   Console::WriteLine( "Running" );
   SerializeObject( "NullDoc.xml" );
}
import System.*;
import System.IO.*;
import System.Xml.Serialization.*;
import System.Xml.*;

// Apply the XmlRootAttribute and set the IsNullable property to false.
/** @attribute XmlRoot(IsNullable = false)
 */
public class Group
{
    public String name;
} //Group

public class Run
{
    public static void main(String[]
 args)
    {
        Console.WriteLine("Running");
        Run test = new Run();
        test.SerializeObject("NullDoc.xml");
    } //main

    public void SerializeObject(String fileName)
    {
        XmlSerializer s = new XmlSerializer(Group.class.ToType());
        // Writing the file requires a TextWriter.
        TextWriter writer = new StreamWriter(fileName);

        // Create the object to serialize.
        Group myGroup = null;

        // Serialize the object, and close the TextWriter.
        s.Serialize(writer, myGroup);
        writer.Close();
    } //SerializeObject
} //Run
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
XmlRootAttribute クラス
XmlRootAttribute メンバ
System.Xml.Serialization 名前空間



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

辞書ショートカット

すべての辞書の索引

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

   

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



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

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

©2024 GRAS Group, Inc.RSS