XmlIgnoreAttributeとは? わかりやすく解説

XmlIgnoreAttribute クラス

XmlSerializer の Serialize メソッドに対して、パブリック フィールドまたはパブリックな読み書き可能プロパティの値をシリアル化しないように指示します。

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

<AttributeUsageAttribute(AttributeTargets.Property Or AttributeTargets.Field
 Or AttributeTargets.Parameter Or AttributeTargets.ReturnValue)>
 _
Public Class XmlIgnoreAttribute
    Inherits Attribute
Dim instance As XmlIgnoreAttribute
[AttributeUsageAttribute(AttributeTargets.Property|AttributeTargets.Field|AttributeTargets.Parameter|AttributeTargets.ReturnValue)]
 
public class XmlIgnoreAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Property|AttributeTargets::Field|AttributeTargets::Parameter|AttributeTargets::ReturnValue)]
 
public ref class XmlIgnoreAttribute : public
 Attribute
/** @attribute AttributeUsageAttribute(AttributeTargets.Property|AttributeTargets.Field|AttributeTargets.Parameter|AttributeTargets.ReturnValue)
 */ 
public class XmlIgnoreAttribute extends Attribute
AttributeUsageAttribute(AttributeTargets.Property|AttributeTargets.Field|AttributeTargets.Parameter|AttributeTargets.ReturnValue)
 
public class XmlIgnoreAttribute extends
 Attribute
解説解説

XmlIgnoreAttribute は、XmlSerializer がオブジェクトをシリアル化または逆シリアル化する方法を制御する一連の属性の 1 つです。XmlIgnoreAttribute をクラスのメンバに適用すると、XmlSerializer は、そのクラスのインスタンスをシリアル化または逆シリアル化するときに、このメンバを無視します。類似する属性の完全な一覧については、「XML シリアル化を制御する属性」を参照してください。

XmlIgnoreAttribute を適用したことによって生じる動作をオーバーライドするには、XmlAttributes オブジェクトを作成し、XmlIgnore プロパティを false に設定します。Add メソッドを使用して、この XmlAttributes オブジェクトを XmlAttributeOverrides クラスのインスタンスに追加する必要があります。最後に、XmlAttributeOverrides オブジェクトを使用して XmlSerializer クラスのインスタンスを構築してから Serialize メソッドまたは Deserialize メソッドを呼び出します。

XML スキーマ定義ツール (Xsd.exe) は、スキーマ ファイル (.xsd) からクラスを作成するときに XmlIgnoreAttribute を生成することがあります。この動作は、値型は null 参照 (Visual Basic では Nothing) に設定できないのに対して、すべての XML データ型は null に設定できるために発生します。したがって、このツールは、値型に割り当てられる XML 型を見つけた場合は 2 つのフィールドを作成します。1 つは値を保持するフィールドで、もう 1 つは fieldnameSpecified という名前の特別なフィールドです。fieldname は、フィールドまたはプロパティの名前になります。ただし、この特別なフィールドが作成されるのは、その要素には最小出現回数がなく (minOccurs = "0")、また、既定値もないことがスキーマに指定されている場合のみです。XmlSerializer は、この特別フィールドの設定およびチェックを行い、そのフィールドまたはプロパティに値が設定されているかどうかを判断します。特別フィールドはシリアル化できないため、特別フィールドには XmlIgnoreAttribute が適用されます。

属性の使用方法については、「属性を使用したメタデータの拡張」を参照してください。

メモメモ

コードでは、XmlIgnoreAttribute の代わりに XmlIgnore という短い語を使用できます。

使用例使用例

Comment という名前のフィールドを含む Group という名前のクラスの例を次に示します。この例では、XmlIgnoreAttribute をフィールドに割り当てることにより、このクラスのインスタンスをシリアル化または逆シリアル化するときに、そのフィールドを無視するように XmlSerializer に指示しています。

Public Class Group
    ' the XmlSerializer ignores this field.
    <XmlIgnore()> Public Comment As String
    
    ' The XmlSerializer serializes this field.
    Public GroupName As String
End Class

public class Group
{
   // The XmlSerializer ignores this field.
   [XmlIgnore]
   public string Comment;

   // The XmlSerializer serializes this field.
   public string GroupName;
}
   
public ref class Group
{
public:

   // The XmlSerializer ignores this field.

   [XmlIgnore]
   String^ Comment;

   // The XmlSerializer serializes this field.
   String^ GroupName;
};

public class Group
{
    // The XmlSerializer ignores this field.
    /** @attribute XmlIgnore()
     */
    public String comment;
    // The XmlSerializer serializes this field.
    public String groupName;
} //Group
継承階層継承階層
System.Object
   System.Attribute
    System.Xml.Serialization.XmlIgnoreAttribute
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
XmlIgnoreAttribute メンバ
System.Xml.Serialization 名前空間
XmlAttributeOverrides クラス
XmlAttributes クラス
XmlAttributes.XmlIgnore プロパティ
XmlSerializer
XmlAttributes クラス
その他の技術情報
XML シリアル化の概要
方法 : XML ストリームの代替要素名を指定する
属性を使用した XML シリアル化の制御
XML シリアル化の例
XML スキーマ定義ツール (Xsd.exe)

XmlIgnoreAttribute コンストラクタ

XmlIgnoreAttribute クラスの新しいインスタンスを初期化します。

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

Dim instance As New XmlIgnoreAttribute
public XmlIgnoreAttribute ()
public:
XmlIgnoreAttribute ()
public XmlIgnoreAttribute ()
public function XmlIgnoreAttribute ()
使用例使用例

Comment という名前のフィールドを含む Group という名前のクラスの例を次に示します。この例では、XmlIgnoreAttribute をフィールドに割り当てることにより、このクラスのインスタンスをシリアル化または逆シリアル化するときに、そのフィールドを無視するように XmlSerializer に指示しています。

Public Class Group
    ' the XmlSerializer ignores this field.
    <XmlIgnore()> Public Comment As String
    
    ' The XmlSerializer serializes this field.
    Public GroupName As String
End Class

public class Group
{
   // The XmlSerializer ignores this field.
   [XmlIgnore]
   public string Comment;

   // The XmlSerializer serializes this field.
   public string GroupName;
}
   
public ref class Group
{
public:

   // The XmlSerializer ignores this field.

   [XmlIgnore]
   String^ Comment;

   // The XmlSerializer serializes this field.
   String^ GroupName;
};

public class Group
{
    // The XmlSerializer ignores this field.
    /** @attribute XmlIgnore()
     */
    public String comment;
    // The XmlSerializer serializes this field.
    public String groupName;
} //Group
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
XmlIgnoreAttribute クラス
XmlIgnoreAttribute メンバ
System.Xml.Serialization 名前空間
XmlAttributes.XmlIgnore プロパティ
XmlAttributeOverrides クラス
XmlSerializer

XmlIgnoreAttribute プロパティ


パブリック プロパティパブリック プロパティ

  名前 説明
パブリック プロパティ TypeId  派生クラスに実装されている場合は、この Attribute の一意の識別子を取得します。 ( Attribute から継承されます。)
参照参照

関連項目

XmlIgnoreAttribute クラス
System.Xml.Serialization 名前空間
XmlAttributeOverrides クラス
XmlAttributes クラス
XmlAttributes.XmlIgnore プロパティ
XmlSerializer
XmlAttributes クラス

その他の技術情報

XML シリアル化の概要
方法 : XML ストリームの代替要素名を指定する
属性を使用した XML シリアル化の制御
XML シリアル化の例
XML スキーマ定義ツール (Xsd.exe)

XmlIgnoreAttribute メソッド


パブリック メソッドパブリック メソッド

( プロテクト メソッド も参照)
  名前 説明
パブリック メソッド Equals  オーバーロードされます。 ( Attribute から継承されます。)
パブリック メソッド GetCustomAttribute  オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用された指定した型のカスタム属性を取得します。 ( Attribute から継承されます。)
パブリック メソッド GetCustomAttributes  オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されたカスタム属性の配列を取得します。 ( Attribute から継承されます。)
パブリック メソッド GetHashCode  このインスタンスのハッシュ コードを返します。 ( Attribute から継承されます。)
パブリック メソッド GetType  現在のインスタンスの Type を取得します。 ( Object から継承されます。)
パブリック メソッド IsDefaultAttribute  派生クラス内でオーバーライドされたときに、このインスタンスの値が派生クラスの既定値かどうかを示します。 ( Attribute から継承されます。)
パブリック メソッド IsDefined  オーバーロードされます。 指定した型のカスタム属性が、アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されているかどうかを判断します。 ( Attribute から継承されます。)
パブリック メソッド Match  派生クラス内でオーバーライドされたときに、指定したオブジェクトとこのインスタンスが等しいかどうかを示す値を返します。 ( Attribute から継承されます。)
パブリック メソッド ReferenceEquals  指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。)
パブリック メソッド ToString  現在の Object を表す String を返します。 ( Object から継承されます。)
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

XmlIgnoreAttribute クラス
System.Xml.Serialization 名前空間
XmlAttributeOverrides クラス
XmlAttributes クラス
XmlAttributes.XmlIgnore プロパティ
XmlSerializer
XmlAttributes クラス

その他の技術情報

XML シリアル化の概要
方法 : XML ストリームの代替要素名を指定する
属性を使用した XML シリアル化の制御
XML シリアル化の例
XML スキーマ定義ツール (Xsd.exe)

XmlIgnoreAttribute メンバ

XmlSerializer の Serialize メソッドに対して、パブリック フィールドまたはパブリックな読み書き可能プロパティの値をシリアル化しないように指示します。

XmlIgnoreAttribute データ型で公開されるメンバを以下の表に示します。


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド XmlIgnoreAttribute XmlIgnoreAttribute クラスの新しいインスタンスを初期化します。
パブリック プロパティパブリック プロパティ
  名前 説明
パブリック プロパティ TypeId  派生クラスに実装されている場合は、この Attribute の一意の識別子を取得します。(Attribute から継承されます。)
パブリック メソッドパブリック メソッド
( プロテクト メソッド も参照)
  名前 説明
パブリック メソッド Equals  オーバーロードされます。 ( Attribute から継承されます。)
パブリック メソッド GetCustomAttribute  オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用された指定した型のカスタム属性を取得します。 (Attribute から継承されます。)
パブリック メソッド GetCustomAttributes  オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されたカスタム属性の配列を取得します。 (Attribute から継承されます。)
パブリック メソッド GetHashCode  このインスタンスのハッシュ コードを返します。 (Attribute から継承されます。)
パブリック メソッド GetType  現在のインスタンスの Type を取得します。 (Object から継承されます。)
パブリック メソッド IsDefaultAttribute  派生クラス内でオーバーライドされたときに、このインスタンスの値が派生クラスの既定値かどうかを示します。 (Attribute から継承されます。)
パブリック メソッド IsDefined  オーバーロードされます。 指定した型のカスタム属性が、アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されているかどうかを判断します。 (Attribute から継承されます。)
パブリック メソッド Match  派生クラス内でオーバーライドされたときに、指定したオブジェクトとこのインスタンスが等しいかどうかを示す値を返します。 (Attribute から継承されます。)
パブリック メソッド ReferenceEquals  指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。)
パブリック メソッド ToString  現在の Object を表す String を返します。 (Object から継承されます。)
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

XmlIgnoreAttribute クラス
System.Xml.Serialization 名前空間
XmlAttributeOverrides クラス
XmlAttributes クラス
XmlAttributes.XmlIgnore プロパティ
XmlSerializer
XmlAttributes クラス

その他の技術情報

XML シリアル化の概要
方法 : XML ストリームの代替要素名を指定する
属性を使用した XML シリアル化の制御
XML シリアル化の例
XML スキーマ定義ツール (Xsd.exe)



英和和英テキスト翻訳

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

辞書ショートカット

すべての辞書の索引

「XmlIgnoreAttribute」の関連用語

XmlIgnoreAttributeのお隣キーワード

   

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



XmlIgnoreAttributeのページの著作権

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

©2026 GRAS Group, Inc.RSS