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

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

XmlAttributes.XmlIgnore プロパティ

XmlSerializer がパブリック フィールドまたは読み書き可能パブリック プロパティシリアル化するかどうか指定する値を取得または設定します

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

Dim instance As XmlAttributes
Dim value As Boolean

value = instance.XmlIgnore

instance.XmlIgnore = value
public bool XmlIgnore { get;
 set; }
/** @property */
public boolean get_XmlIgnore ()

/** @property */
public void set_XmlIgnore (boolean value)

プロパティ
XmlSerializer でそのフィールドまたはプロパティシリアル化ない場合trueそれ以外場合false

解説解説
使用例使用例

XmlIgnoreAttribute適用されている Group という名前のメンバを含む Comment という名前のクラスシリアル化する例を次に示します。この例では、XmlAttributes オブジェクト作成しXmlIgnore プロパティfalse設定してXmlIgnoreAttributeオーバーライドます。

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


' This is the class that will be serialized. 
Public Class Group
    ' The GroupName value will be serialized--unless it's overridden.
    Public GroupName As String
    
    ' This field will be ignored when serialized--
    '  unless it's overridden.
    <XmlIgnoreAttribute()> Public Comment As
 String
End Class


Public Class Test
    
    Public Shared Sub Main()
        Dim t As New Test()
        t.SerializeObject("IgnoreXml.xml")
    End Sub
    
    
    ' Return an XmlSerializer used for overriding.
    Public Function CreateOverrider() As
 XmlSerializer
        ' Create the XmlAttributeOverrides and XmlAttributes objects.
        Dim xOver As New
 XmlAttributeOverrides()
        Dim attrs As New
 XmlAttributes()
        
        ' Setting XmlIgnore to false overrides the XmlIgnoreAttribute
        ' applied to the Comment field. Thus it will be serialized.
        attrs.XmlIgnore = False
        xOver.Add(GetType(Group), "Comment",
 attrs)
        
        ' Use the XmlIgnore to instruct the XmlSerializer to ignore
        ' the GroupName instead. 
        attrs = New XmlAttributes()
        attrs.XmlIgnore = True
        xOver.Add(GetType(Group), "GroupName",
 attrs)
        
        Dim xSer As New
 XmlSerializer(GetType(Group), xOver)
        Return xSer
    End Function
    
    
    Public Sub SerializeObject(ByVal
 filename As String)
        ' Create an XmlSerializer instance.
        Dim xSer As XmlSerializer = CreateOverrider()
        
        ' Create the object to serialize and set its properties.
        Dim myGroup As New
 Group()
        myGroup.GroupName = ".NET"
        myGroup.Comment = "My Comment..."
        
        ' Writing the file requires a TextWriter.
        Dim writer As New
 StreamWriter(filename)
        
        ' Serialize the object and close the TextWriter.
        xSer.Serialize(writer, myGroup)
        writer.Close()
    End Sub
End Class

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

// This is the class that will be serialized. 
public class Group
{
   // The GroupName value will be serialized--unless it's overridden.
   public string GroupName;

   /* This field will be ignored when serialized--
      unless it's overridden. */
   [XmlIgnoreAttribute]
   public string Comment;
}

public class Test
{
   public static void Main()
   {
      Test t = new Test();
      t.SerializeObject("IgnoreXml.xml");
   }

   // Return an XmlSerializer used for overriding.
   public XmlSerializer CreateOverrider()
   {
      // Create the XmlAttributeOverrides and XmlAttributes objects.
      XmlAttributeOverrides xOver = new XmlAttributeOverrides();
      XmlAttributes attrs = new XmlAttributes();

      /* Setting XmlIgnore to false overrides the XmlIgnoreAttribute
         applied to the Comment field. Thus it will be serialized.*/
      attrs.XmlIgnore = false;
      xOver.Add(typeof(Group), "Comment", attrs);

      /* Use the XmlIgnore to instruct the XmlSerializer to ignore
         the GroupName instead. */
      attrs = new XmlAttributes();
      attrs.XmlIgnore = true;
      xOver.Add(typeof(Group), "GroupName", attrs);
      
      XmlSerializer xSer = new XmlSerializer(typeof(Group), xOver);
      return xSer;
   }

   public void SerializeObject(string
 filename)
   {
      // Create an XmlSerializer instance.
      XmlSerializer xSer = CreateOverrider();

      // Create the object to serialize and set its properties.
      Group myGroup = new Group();
      myGroup.GroupName = ".NET";
      myGroup.Comment = "My Comment...";
   
      // Writing the file requires a TextWriter.
      TextWriter writer = new StreamWriter(filename);

      // Serialize the object and close the TextWriter.
      xSer.Serialize(writer, myGroup);
      writer.Close();
   }
}

#using <System.Xml.dll>
#using <System.dll>

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

// This is the class that will be serialized. 
public ref class Group
{
public:

   // The GroupName value will be serialized--unless it's overridden.
   String^ GroupName;

   /* This field will be ignored when serialized--
      unless it's overridden. */

   [XmlIgnoreAttribute]
   String^ Comment;
};


// Return an XmlSerializer used for overriding.
XmlSerializer^ CreateOverrider()
{
   // Create the XmlAttributeOverrides and XmlAttributes objects.
   XmlAttributeOverrides^ xOver = gcnew XmlAttributeOverrides;
   XmlAttributes^ attrs = gcnew XmlAttributes;

   /* Setting XmlIgnore to false overrides the XmlIgnoreAttribute
      applied to the Comment field. Thus it will be serialized.*/
   attrs->XmlIgnore = false;
   xOver->Add( Group::typeid, "Comment", attrs );

   /* Use the XmlIgnore to instruct the XmlSerializer to ignore
      the GroupName instead. */
   attrs = gcnew XmlAttributes;
   attrs->XmlIgnore = true;
   xOver->Add( Group::typeid, "GroupName", attrs );
   XmlSerializer^ xSer = gcnew XmlSerializer( Group::typeid,xOver );
   return xSer;
}

void SerializeObject( String^ filename )
{
   // Create an XmlSerializer instance.
   XmlSerializer^ xSer = CreateOverrider();

   // Create the object to serialize and set its properties.
   Group^ myGroup = gcnew Group;
   myGroup->GroupName = ".NET";
   myGroup->Comment = "My Comment...";

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

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

int main()
{
   SerializeObject( "IgnoreXml.xml" );
}
import System.*;
import System.IO.*;
import System.Xml.Serialization.*;

// This is the class that will be serialized. 
public class Group
{
    // The GroupName value will be serialized--unless it's overridden.
    public String groupName;
    /* This field will be ignored when serialized--
       unless it's overridden. */
    /** @attribute XmlIgnoreAttribute()
     */
    public String comment;
} //Group

public class Test
{
    public static void main(String[]
 args)
    {
        Test t = new Test();
        t.SerializeObject("IgnoreXml.xml");
    } //main

    // Return an XmlSerializer used for overriding.
    public XmlSerializer CreateOverrider()
    {
        // Create the XmlAttributeOverrides and XmlAttributes objects.
        XmlAttributeOverrides xOver = new XmlAttributeOverrides();
        XmlAttributes attrs = new XmlAttributes();

        /* Setting XmlIgnore to false overrides the XmlIgnoreAttribute
           applied to the Comment field. Thus it will be serialized.*/
        attrs.set_XmlIgnore(false);
        xOver.Add(Group.class.ToType(), "Comment", attrs);

        /* Use the XmlIgnore to instruct the XmlSerializer to ignore
           the GroupName instead. */
        attrs = new XmlAttributes();
        attrs.set_XmlIgnore(true);
        xOver.Add(Group.class.ToType(), "GroupName",
 attrs);

        XmlSerializer xSer = new XmlSerializer(Group.class.ToType(),
 xOver);
        return xSer;
    } //CreateOverrider

    public void SerializeObject(String fileName)
    {
        // Create an XmlSerializer instance.
        XmlSerializer xSer = CreateOverrider();

        // Create the object to serialize and set its properties.
        Group myGroup = new Group();
        myGroup.groupName = ".NET";
        myGroup.comment = "My Comment...";

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

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


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

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

辞書ショートカット

すべての辞書の索引

「XmlAttributes.XmlIgnore プロパティ」の関連用語

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

   

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



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

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

©2025 GRAS Group, Inc.RSS