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

XmlAttributeEventArgs クラス

UnknownAttribute イベントデータ提供します

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

Public Class XmlAttributeEventArgs
    Inherits EventArgs
Dim instance As XmlAttributeEventArgs
public class XmlAttributeEventArgs : EventArgs
public ref class XmlAttributeEventArgs : public
 EventArgs
public class XmlAttributeEventArgs extends
 EventArgs
public class XmlAttributeEventArgs extends
 EventArgs
解説解説
使用例使用例

UnknownAttributes.xml という名前のファイルかGroup という名前のクラスを逆シリアル化する例を次に示しますクラス内に対応するメンバ持たないファイル内で要素が見つかると、必ず UnknownAttribute イベント発生します。この例を試行するには、次の XML コードを UnknownAttributes.xml という名前のファイル貼り付けます。

 <?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"
 GroupType = 'Technical' GroupNumber = '42' GroupBase = 'Red'>
   <GroupName>MyGroup</GroupName>
 </Group>
Imports System
Imports System.IO
Imports System.Xml.Serialization
Imports System.Xml
Imports System.Xml.Schema
Imports Microsoft.VisualBasic

Public Class Group
   Public GroupName As String
 
End Class

Public Class Test
   Shared Sub Main()
      Dim t As Test = new
 Test()
      ' Deserialize the file containing unknown elements.
      t.DeserializeObject("UnknownAttributes.xml")
   End Sub

   Private Sub Serializer_UnknownAttribute
 _
   (sender As Object , e As
 XmlAttributeEventArgs)
      Console.WriteLine("Unknown Attribute")
      Console.WriteLine(ControlChars.Tab & e.Attr.Name + "
 " & e.Attr.InnerXml)
      Console.WriteLine(ControlChars.Tab & e.LineNumber & ":"
  & e.LineNumber)
      Console.WriteLine(ControlChars.Tab & e.LinePosition & ":"
   & e.LinePosition)
      
      Dim x As Group = CType( e.ObjectBeingDeserialized,
 Group)
      Console.WriteLine (x.GroupName)
      Console.WriteLine (sender.ToString())
   End Sub
   
   Private Sub DeserializeObject(filename As
 String)
      Dim ser As XmlSerializer = new
 XmlSerializer(GetType(Group))
      ' Add a delegate to handle unknown element events.
      AddHandler ser.UnknownAttribute, _
      AddressOf Serializer_UnknownAttribute 
      ' A FileStream is needed to read the XML document.
     Dim fs As FileStream  = new
 FileStream(filename, FileMode.Open)
     Dim g  As Group = CType(ser.Deserialize(fs)
,Group)
     fs.Close()
   End Sub
End Class
using System;
using System.IO;
using System.Xml.Serialization;
using System.Xml;
using System.Xml.Schema;

public class Group{
   public string GroupName;
}

public class Test{
   static void Main(){
      Test t = new Test();
      // Deserialize the file containing unknown elements.
      t.DeserializeObject("UnknownAttributes.xml");
   }
   private void Serializer_UnknownAttribute(object
 sender, XmlAttributeEventArgs e){
      Console.WriteLine("Unknown Attribute");
      Console.WriteLine("\t" + e.Attr.Name + " " + e.Attr.InnerXml);
      Console.WriteLine("\t LineNumber: " + e.LineNumber);
      Console.WriteLine("\t LinePosition: " + e.LinePosition);
      
      Group x  = (Group) e.ObjectBeingDeserialized;
      Console.WriteLine (x.GroupName);
      Console.WriteLine (sender.ToString());
   }
   private void DeserializeObject(string
 filename){
      XmlSerializer ser = new XmlSerializer(typeof(Group));
      // Add a delegate to handle unknown element events.
      ser.UnknownAttribute+=new XmlAttributeEventHandler(Serializer_UnknownAttribute);
      // A FileStream is needed to read the XML document.
     FileStream fs = new FileStream(filename, FileMode.Open);
     Group g = (Group) ser.Deserialize(fs);
     fs.Close();
       }
}
#using <System.Xml.dll>
#using <System.dll>

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

public ref class Group
{
public:
   String^ GroupName;
};

public ref class Test
{
public:
   static void main()
   {
      Test^ t = gcnew Test;
      
      // Deserialize the file containing unknown elements.
      t->DeserializeObject( "UnknownAttributes.xml" );
   }

private:
   void Serializer_UnknownAttribute( Object^ sender, XmlAttributeEventArgs^
 e )
   {
      Console::WriteLine( "Unknown Attribute" );
      Console::WriteLine( "\t{0} {1}", e->Attr->Name, e->Attr->InnerXml
 );
      Console::WriteLine( "\t LineNumber: {0}", e->LineNumber );
      Console::WriteLine( "\t LinePosition: {0}", e->LinePosition );
      Group^ x = dynamic_cast<Group^>(e->ObjectBeingDeserialized);
      Console::WriteLine( x->GroupName );
      Console::WriteLine( sender );
   }

   void DeserializeObject( String^ filename )
   {
      XmlSerializer^ ser = gcnew XmlSerializer( Group::typeid );

      // Add a delegate to handle unknown element events.
      ser->UnknownAttribute += gcnew XmlAttributeEventHandler( this,
 &Test::Serializer_UnknownAttribute );

      // A FileStream is needed to read the XML document.
      FileStream^ fs = gcnew FileStream( filename,FileMode::Open );
      Group^ g = dynamic_cast<Group^>(ser->Deserialize( fs ));
      fs->Close();
   }
};

int main()
{
   Test::main();
}
import System.*;
import System.IO.*;
import System.Xml.Serialization.*;
import System.Xml.*;
import System.Xml.Schema.*;

public class Group
{
    public String groupName;
} //Group

public class Test
{
    public static void main(String[]
 args)
    {
        Test t = new Test();
        // Deserialize the file containing unknown elements.
        t.DeserializeObject("UnknownAttributes.xml");
    } //main

    private void Serializer_UnknownAttribute(Object
 sender,
        XmlAttributeEventArgs e)
    {
        Console.WriteLine("Unknown Attribute");
        Console.WriteLine("\t" + e.get_Attr().get_Name() + " "
            + e.get_Attr().get_InnerXml());
        Console.WriteLine("\t LineNumber: " + e.get_LineNumber());
        Console.WriteLine("\t LinePosition: " + e.get_LinePosition());

        Group x = (Group)e.get_ObjectBeingDeserialized();
        Console.WriteLine(x.groupName);
        Console.WriteLine(sender.ToString());
    } //Serializer_UnknownAttribute

    private void DeserializeObject(String filename)
    {
        XmlSerializer ser = new XmlSerializer(Group.class.ToType());

        // Add a delegate to handle unknown element events.
        ser.add_UnknownAttribute(new XmlAttributeEventHandler
            (Serializer_UnknownAttribute));

        // A FileStream is needed to read the XML document.
        FileStream fs = new FileStream(filename, FileMode.Open);
        Group g = (Group)ser.Deserialize(fs);
        fs.Close();
    } //DeserializeObject
} //Test
継承階層継承階層
System.Object
   System.EventArgs
    System.Xml.Serialization.XmlAttributeEventArgs
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
XmlAttributeEventArgs メンバ
System.Xml.Serialization 名前空間
XmlAttributeEventHandler

XmlAttributeEventArgs プロパティ


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

  名前 説明
パブリック プロパティ ObjectBeingDeserialized シリアル化されているオブジェクト取得します
参照参照

関連項目

XmlAttributeEventArgs クラス
System.Xml.Serialization 名前空間
XmlAttributeEventHandler

XmlAttributeEventArgs メソッド


XmlAttributeEventArgs メンバ

UnknownAttribute イベントデータ提供します

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


パブリック プロパティパブリック プロパティ
  名前 説明
パブリック プロパティ ObjectBeingDeserialized シリアル化されているオブジェクト取得します
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

XmlAttributeEventArgs クラス
System.Xml.Serialization 名前空間
XmlAttributeEventHandler



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

辞書ショートカット

すべての辞書の索引

「XmlAttributeEventArgs」の関連用語

XmlAttributeEventArgsのお隣キーワード
検索ランキング

   

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



XmlAttributeEventArgsのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS