XmlSerializer.Deserialize メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > XmlSerializer.Deserialize メソッドの意味・解説 

XmlSerializer.Deserialize メソッド (XmlReader, String)

メモ : このメソッドは、.NET Framework version 2.0新しく追加されたものです。

指定した XmlReader格納されている XML ドキュメントを、指定したエンコーディング スタイル使用してシリアル化ます。

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

Public Function Deserialize ( _
    xmlReader As XmlReader, _
    encodingStyle As String _
) As Object
Dim instance As XmlSerializer
Dim xmlReader As XmlReader
Dim encodingStyle As String
Dim returnValue As Object

returnValue = instance.Deserialize(xmlReader, encodingStyle)
public Object Deserialize (
    XmlReader xmlReader,
    string encodingStyle
)
public:
Object^ Deserialize (
    XmlReader^ xmlReader, 
    String^ encodingStyle
)
public Object Deserialize (
    XmlReader xmlReader, 
    String encodingStyle
)
public function Deserialize (
    xmlReader : XmlReader, 
    encodingStyle : String
) : Object

パラメータ

xmlReader

シリアル化する XML ドキュメント格納している XmlReader

encodingStyle

シリアル化された XMLエンコーディング スタイル

戻り値
シリアル化されたオブジェクト

例外例外
解説解説

シリアル化とは、XML ドキュメントインスタンス読み取り、そのドキュメントXML スキーマ (XSD) に厳密に指定されオブジェクト構築する処理のことです。

シリアル化する前に、逆シリアル化対象オブジェクトの型を使用して XmlSerializer を生成する必要があります

SOAP Version 1.1 エンコーディング使用する場合は、encodingStyle パラメータを "http://schemas.xmlsoap.org/soap/encoding/" に設定しますそれ以外場合は、SOAP Version 1.2 エンコーディング使用する "http://www.w3.org/2001/12/soap-encoding" に設定します

メモ   次のような ArrayList の配列および List配列については、XmlSerializer で逆シリアル化することはできません。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

XmlSerializer.Deserialize メソッド (Stream)

指定した Stream格納されている XML ドキュメントを逆シリアル化ます。

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

解説解説

シリアル化とは、XML ドキュメント読み取り、そのドキュメントXML スキーマ (XSD) に厳密に指定されオブジェクト構築する処理のことです。

シリアル化する前に、逆シリアル化対象オブジェクトの型を使用して XmlSerializer を生成する必要があります

stream パラメータ使用してストリーム書き込むようにデザインされている、Stream クラスから派生したオブジェクト指定しますStream派生クラスには、次のクラス含まれます。

  • BufferedStream

  • FileStream

  • MemoryStream

  • NetworkStream

  • CryptoStream

メモ   次のような ArrayList の配列および List配列については、XmlSerializer で逆シリアル化することはできません。

使用例使用例

Stream オブジェクト使用してオブジェクトを逆シリアル化する例を次に示します

Imports System
Imports System.IO
Imports System.Xml.Serialization
Imports Microsoft.VisualBasic


' This is the class that will be deserialized.
Public Class OrderedItem
    <XmlElement(Namespace := "http://www.cpandl.com")>
 _
    Public ItemName As String

    <XmlElement(Namespace := "http://www.cpandl.com")>
 _
    Public Description As String
    
    <XmlElement(Namespace := "http://www.cohowinery.com")>
 _
    Public UnitPrice As Decimal
    
    <XmlElement(Namespace := "http://www.cpandl.com")>
 _
    Public Quantity As Integer
    
    <XmlElement(Namespace := "http://www.cohowinery.com")>
 _
    Public LineTotal As Decimal
    
    'A custom method used to calculate price per item.
    Public Sub Calculate()
        LineTotal = UnitPrice * Quantity
    End Sub
End Class

Public Class Test
    
    Public Shared Sub Main()
        Dim t As New Test()
        ' Read a purchase order.
        t.DeserializeObject("simple.xml")
    End Sub
        
    Private Sub DeserializeObject(ByVal
 filename As String)
        Console.WriteLine("Reading with Stream")
        ' Create an instance of the XmlSerializer.
        Dim serializer As New
 XmlSerializer(GetType(OrderedItem))
        ' Reading the XML document requires a FileStream.
        Dim reader As New
 FileStream(filename, FileMode.Open)
        
        ' Declare an object variable of the type to be deserialized.
        Dim i As OrderedItem
        
        ' Call the Deserialize method to restore the object's state.
        i = CType(serializer.Deserialize(reader), OrderedItem)
        
        ' Write out the properties of the object.
        Console.Write(i.ItemName & ControlChars.Tab & _
                      i.Description & ControlChars.Tab & _
                      i.UnitPrice & ControlChars.Tab & _
                      i.Quantity & ControlChars.Tab & _
                      i.LineTotal)
    End Sub
End Class

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

// This is the class that will be deserialized.
public class OrderedItem
{
   [XmlElement(Namespace = "http://www.cpandl.com")]
   public string ItemName;
   [XmlElement(Namespace = "http://www.cpandl.com")]
   public string Description;
   [XmlElement(Namespace="http://www.cohowinery.com")]
   public decimal UnitPrice;
   [XmlElement(Namespace = "http://www.cpandl.com")]
   public int Quantity;
   [XmlElement(Namespace="http://www.cohowinery.com")]
   public decimal LineTotal;
   // A custom method used to calculate price per item.
   public void Calculate()
   {
      LineTotal = UnitPrice * Quantity;
   }
}
 
public class Test
{
   public static void Main()
   {
      Test t = new Test();
      // Read a purchase order.
      t.DeserializeObject("simple.xml");
   }

   private void DeserializeObject(string
 filename)
   {   
      Console.WriteLine("Reading with Stream");
      // Create an instance of the XmlSerializer.
      XmlSerializer serializer = 
      new XmlSerializer(typeof(OrderedItem));
      // Reading the XML document requires a FileStream.
      Stream reader= new FileStream(filename,FileMode.Open);
          
      // Declare an object variable of the type to be deserialized.
      OrderedItem i;

      // Call the Deserialize method to restore the object's state.
      i = (OrderedItem) serializer.Deserialize(reader);

      // Write out the properties of the object.
      Console.Write(
      i.ItemName + "\t" +
      i.Description + "\t" +
      i.UnitPrice + "\t" +
      i.Quantity + "\t" +
      i.LineTotal);
   }
}

#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 deserialized.
public ref class OrderedItem
{
public:

   [XmlElement(Namespace="http://www.cpandl.com")]
   String^ ItemName;

   [XmlElement(Namespace="http://www.cpandl.com")]
   String^ Description;

   [XmlElement(Namespace="http://www.cohowinery.com")]
   Decimal UnitPrice;

   [XmlElement(Namespace="http://www.cpandl.com")]
   int Quantity;

   [XmlElement(Namespace="http://www.cohowinery.com")]
   Decimal LineTotal;

   // A custom method used to calculate price per item.
   void Calculate()
   {
      LineTotal = UnitPrice * Quantity;
   }
};

void DeserializeObject( String^ filename )
{
   Console::WriteLine( "Reading with Stream" );

   // Create an instance of the XmlSerializer.
   XmlSerializer^ serializer = gcnew XmlSerializer( OrderedItem::typeid );

   // Reading the XML document requires a FileStream.
   Stream^ reader = gcnew FileStream( filename,FileMode::Open );

   // Declare an object variable of the type to be deserialized.
   OrderedItem^ i;

   // Call the Deserialize method to restore the object's state.
   i = dynamic_cast<OrderedItem^>(serializer->Deserialize( reader ));

   // Write out the properties of the object.
   Console::Write( "{0}\t{1}\t{2}\t{3}\t{4}", i->ItemName, i->Description,
 i->UnitPrice, i->Quantity, i->LineTotal );
}

int main()
{
   // Read a purchase order.
   DeserializeObject( "simple.xml" );
}
import System.*;
import System.IO.*;
import System.Xml.Serialization.*;

// This is the class that will be deserialized.
public class OrderedItem
{
    /** @attribute XmlElement(Namespace = "http://www.cpandl.com")
     */
    public String itemName;
    /** @attribute XmlElement(Namespace = "http://www.cpandl.com")
     */
    public String description;
    /** @attribute XmlElement(Namespace = "http://www.cohowinery.com")
     */
    public System.Decimal unitPrice;
    /** @attribute XmlElement(Namespace = "http://www.cpandl.com")
     */
    public int quantity;
    /** @attribute XmlElement(Namespace = "http://www.cohowinery.com")
     */
    public System.Decimal lineTotal;

    // A custom method used to calculate price per item.
    public void Calculate()
    {
        lineTotal = Decimal.Multiply(unitPrice, Convert.ToDecimal(quantity));
    } //Calculate
} //OrderedItem

public class Test
{
    public static void main(String[]
 args)
    {
        Test t = new Test();
        // Read a purchase order.
        t.DeserializeObject("simple.xml");
    } //main

    private void DeserializeObject(String fileName)
    {
        Console.WriteLine("Reading with Stream");

        // Create an instance of the XmlSerializer.
        XmlSerializer serializer =
            new XmlSerializer(OrderedItem.class.ToType());

        // Reading the XML document requires a FileStream.
        Stream reader = new FileStream(fileName, FileMode.Open);

        // Declare an object variable of the type to be deserialized.
        OrderedItem i;

        // Call the Deserialize method to restore the object's state.
        i = (OrderedItem)serializer.Deserialize(reader);

        // Write out the properties of the object.
        Console.Write(i.itemName + "\t" + i.description + "\t"
 + i.unitPrice
            + "\t" + i.quantity + "\t" + i.lineTotal);
    } //DeserializeObject
} //Test
<?xml version="1.0"?>
 <OrderedItem xmlns:inventory="http://www.cpandl.com"
 xmlns:money="http://www.cohowinery.com">
   <inventory:ItemName>Widget</inventory:ItemName>
   <inventory:Description>Regular
 Widget</inventory:Description>
   <money:UnitPrice>2.3</money:UnitPrice>
   <inventory:Quantity>10</inventory:Quantity>
   <money:LineTotal>23</money:LineTotal>
 </OrderedItem>

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

XmlSerializer.Deserialize メソッド (TextReader)

指定した TextReader格納されている XML ドキュメントを逆シリアル化ます。

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

Public Function Deserialize ( _
    textReader As TextReader _
) As Object
Dim instance As XmlSerializer
Dim textReader As TextReader
Dim returnValue As Object

returnValue = instance.Deserialize(textReader)
public Object Deserialize (
    TextReader textReader
)
public:
Object^ Deserialize (
    TextReader^ textReader
)
public Object Deserialize (
    TextReader textReader
)
public function Deserialize (
    textReader : TextReader
) : Object

パラメータ

textReader

シリアル化する XML ドキュメント格納している TextReader。

戻り値
シリアル化される Object

例外例外
解説解説
使用例使用例

TextReader オブジェクト使用してオブジェクトを逆シリアル化する例を次に示します

Imports System
Imports System.IO
Imports System.Text
Imports System.Xml.Serialization
Imports Microsoft.VisualBasic

' This is the class that will be deserialized.
Public Class OrderedItem
    <XmlElement(Namespace := "http://www.cpandl.com")>
 _
    Public ItemName As String

    <XmlElement(Namespace := "http://www.cpandl.com")>
 _
    Public Description As String
    
    <XmlElement(Namespace := "http://www.cohowinery.com")>
 _
    Public UnitPrice As Decimal
    
    <XmlElement(Namespace := "http://www.cpandl.com")>
 _
    Public Quantity As Integer
    
    <XmlElement(Namespace := "http://www.cohowinery.com")>
 _
    Public LineTotal As Decimal
    ' A custom method used to calculate price per item.
    Public Sub Calculate()
        LineTotal = UnitPrice * Quantity
    End Sub
End Class
Public Class Test
    
    Public Shared Sub Main()
        Dim t As New Test()
        ' Read a purchase order.
        t.DeserializeObject("simple.xml")
    End Sub
    
    Private Sub DeserializeObject(filename
 As String)
        Console.WriteLine("Reading with TextReader")
        
        ' Create an instance of the XmlSerializer specifying type.
        Dim serializer As New
 XmlSerializer(GetType(OrderedItem))
        
        ' Create a TextReader to read the file. 
        Dim fs as New FileStream(filename,
 FileMode.OpenOrCreate)
        Dim reader As New
 StreamReader(fs)
        
        ' Declare an object variable of the type to be deserialized.
        Dim i As OrderedItem
        
        ' Use the Deserialize method to restore the object's state.
        i = CType(serializer.Deserialize(reader), OrderedItem)
        
        ' Write out the properties of the object.
        Console.Write(i.ItemName & ControlChars.Tab & _
                      i.Description & ControlChars.Tab & _
                      i.UnitPrice & ControlChars.Tab & _
                      i.Quantity & ControlChars.Tab & _
                      i.LineTotal)
    End Sub
End Class
using System;
using System.IO;
using System.Text;
using System.Xml.Serialization;

// This is the class that will be deserialized.
public class OrderedItem
{
    [XmlElement(Namespace = "http://www.cpandl.com")]
    public string ItemName;
    [XmlElement(Namespace = "http://www.cpandl.com")]
    public string Description;
    [XmlElement(Namespace = "http://www.cohowinery.com")]
    public decimal UnitPrice;
    [XmlElement(Namespace = "http://www.cpandl.com")]
    public int Quantity;
    [XmlElement(Namespace = "http://www.cohowinery.com")]
    public decimal LineTotal;
    // A custom method used to calculate price per item.
    public void Calculate()
    {
        LineTotal = UnitPrice * Quantity;
    }
}
 
public class Test
{
   public static void Main()
   {
      Test t = new Test();
      // Read a purchase order.
      t.DeserializeObject("simple.xml");
   }
   private void DeserializeObject(string
 filename)
   {   
      Console.WriteLine("Reading with TextReader");

      // Create an instance of the XmlSerializer specifying type.
      XmlSerializer serializer = 
      new XmlSerializer(typeof(OrderedItem));

      // Create a TextReader to read the file. 
      FileStream fs = new FileStream(filename, FileMode.OpenOrCreate);
      TextReader reader = new StreamReader(fs);
      
      // Declare an object variable of the type to be deserialized.
      OrderedItem i;

      // Use the Deserialize method to restore the object's state.
      i = (OrderedItem) serializer.Deserialize(reader);

      // Write out the properties of the object.
      Console.Write(
      i.ItemName + "\t" +
      i.Description + "\t" +
      i.UnitPrice + "\t" +
      i.Quantity + "\t" +
      i.LineTotal);
   }
}
#using <System.Xml.dll>
#using <System.dll>

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

// This is the class that will be deserialized.
public ref class OrderedItem
{
public:
   String^ ItemName;
   String^ Description;
   Decimal UnitPrice;
   int Quantity;
   Decimal LineTotal;

   // A custom method used to calculate price per item.
   void Calculate()
   {
      LineTotal = UnitPrice * Quantity;
   }
};

void DeserializeObject( String^ filename )
{
   Console::WriteLine( "Reading with TextReader" );

   // Create an instance of the XmlSerializer specifying type.
   XmlSerializer^ serializer = gcnew XmlSerializer( OrderedItem::typeid );

   /* Create a TextReader to read the file. Specify an
      Encoding to use. */
   TextReader^ reader = gcnew StreamReader( filename,Encoding::Unicode );

   // Declare an object variable of the type to be deserialized.
   OrderedItem^ i;

   // Use the Deserialize method to restore the object's state.
   i = dynamic_cast<OrderedItem^>(serializer->Deserialize( reader ));

   // Write out the properties of the object.
   Console::Write( "{0}\t{1}\t{2}\t{3}\t{4}", i->ItemName, i->Description,
 i->UnitPrice, i->Quantity, i->LineTotal );
}

int main()
{
   // Read a purchase order.
   DeserializeObject( "simple.xml" );
}
import System.*;
import System.IO.*;
import System.Text.*;
import System.Xml.Serialization.*;

// This is the class that will be deserialized.
public class OrderedItem
{
    public String itemName;
    public String description;
    public System.Decimal unitPrice;
    public int quantity;
    public System.Decimal lineTotal;

    // A custom method used to calculate price per item.
    public void Calculate()
    {
        lineTotal = Decimal.Multiply(unitPrice, Convert.ToDecimal(quantity));
    } //Calculate
} //OrderedItem

public class Test
{
    public static void main(String[]
 args)
    {
        Test t = new Test();
        // Read a purchase order.
        t.DeserializeObject("simple.xml");
    } //main

    private void DeserializeObject(String fileName)
    {
        Console.WriteLine("Reading with TextReader");

        // Create an instance of the XmlSerializer specifying type.
        XmlSerializer serializer =
            new XmlSerializer(OrderedItem.class.ToType());

        /* Create a TextReader to read the file. Specify an
           Encoding to use. */
        TextReader reader = new StreamReader(fileName, Encoding.get_Unicode());

        // Declare an object variable of the type to be deserialized.
        OrderedItem i;

        // Use the Deserialize method to restore the object's state.
        i = (OrderedItem)serializer.Deserialize(reader);

        // Write out the properties of the object.
        Console.Write(i.itemName + "\t" + i.description + "\t"
 + i.unitPrice
            + "\t" + i.quantity + "\t" + i.lineTotal);
    } //DeserializeObject
} //Test
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

XmlSerializer.Deserialize メソッド (XmlReader, String, XmlDeserializationEvents)

メモ : このメソッドは、.NET Framework version 2.0新しく追加されたものです。

指定した XmlReader格納されているデータ使用してオブジェクトを逆シリアル化ます。

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

Public Function Deserialize ( _
    xmlReader As XmlReader, _
    encodingStyle As String, _
    events As XmlDeserializationEvents _
) As Object
Dim instance As XmlSerializer
Dim xmlReader As XmlReader
Dim encodingStyle As String
Dim events As XmlDeserializationEvents
Dim returnValue As Object

returnValue = instance.Deserialize(xmlReader, encodingStyle, events)
public Object Deserialize (
    XmlReader xmlReader,
    string encodingStyle,
    XmlDeserializationEvents events
)
public:
Object^ Deserialize (
    XmlReader^ xmlReader, 
    String^ encodingStyle, 
    XmlDeserializationEvents events
)
public Object Deserialize (
    XmlReader xmlReader, 
    String encodingStyle, 
    XmlDeserializationEvents events
)
public function Deserialize (
    xmlReader : XmlReader, 
    encodingStyle : String, 
    events : XmlDeserializationEvents
) : Object

パラメータ

xmlReader

ドキュメント読み取り使用される XmlReader クラスインスタンス

encodingStyle

使用されるエンコーディング

events

XmlDeserializationEvents クラスインスタンス

戻り値
シリアル化されているオブジェクト

解説解説
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
XmlSerializer クラス
XmlSerializer メンバ
System.Xml.Serialization 名前空間

XmlSerializer.Deserialize メソッド

XML ドキュメントを逆シリアル化ます。
オーバーロードの一覧オーバーロードの一覧

名前 説明
XmlSerializer.Deserialize (Stream) 指定した Stream格納されている XML ドキュメントを逆シリアル化ます。

.NET Compact Framework によってサポートされています。

XmlSerializer.Deserialize (TextReader) 指定した TextReader に格納されている XML ドキュメントを逆シリアル化ます。

.NET Compact Framework によってサポートされています。

XmlSerializer.Deserialize (XmlReader) 指定した XmlReader格納されている XML ドキュメントを逆シリアル化ます。

.NET Compact Framework によってサポートされています。

XmlSerializer.Deserialize (XmlSerializationReader) 指定した XmlSerializationReader に格納されている XML ドキュメントを逆シリアル化ます。
XmlSerializer.Deserialize (XmlReader, String) 指定した XmlReader格納されている XML ドキュメントを、指定したエンコーディング スタイル使用してシリアル化ます。

.NET Compact Framework によってサポートされています。

XmlSerializer.Deserialize (XmlReader, XmlDeserializationEvents) 指定した XmlReader格納されている XML ドキュメントを逆シリアル化ます。また、シリアル化発生するイベントオーバーライド可能にます。
XmlSerializer.Deserialize (XmlReader, String, XmlDeserializationEvents) 指定した XmlReader格納されているデータ使用してオブジェクトを逆シリアル化ます。
参照参照

関連項目

XmlSerializer クラス
XmlSerializer メンバ
System.Xml.Serialization 名前空間
XmlAttributes クラス
CanDeserialize
Serialize

その他の技術情報

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

XmlSerializer.Deserialize メソッド (XmlReader)

指定した XmlReader格納されている XML ドキュメントを逆シリアル化ます。

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

例外例外
解説解説

シリアル化とは、XML ドキュメントインスタンス読み取り、そのドキュメントXML スキーマ (XSD) に厳密に指定されオブジェクト構築する処理のことです。

シリアル化する前に、逆シリアル化対象オブジェクトの型を使用して XmlSerializer を生成する必要があります

XmlReader は、XML ドキュメント指定されエンコーディング自動的に検出し使用します

メモ   次のような ArrayList の配列および List配列については、XmlSerializer で逆シリアル化することはできません。

使用例使用例

XmlReader使用してオブジェクトを逆シリアル化する例を次に示します

Imports System
Imports System.IO
Imports System.Text
Imports System.Xml
Imports System.Xml.Serialization
Imports Microsoft.VisualBasic


' This is the class that will be deserialized.
Public Class OrderedItem
    Public ItemName As String
    Public Description As String
    Public UnitPrice As Decimal
    Public Quantity As Integer
    Public LineTotal As Decimal
        
    ' A custom method used to calculate price per item.
    Public Sub Calculate()
        LineTotal = UnitPrice * Quantity
    End Sub
End Class

Public Class Test
    
    Public Shared Sub Main()
        Dim t As New Test()
        ' Read a purchase order.
        t.DeserializeObject("simple.xml")
    End Sub
      
    Private Sub DeserializeObject(ByVal
 filename As String)
        Console.WriteLine("Reading with XmlReader")
        
        ' Create an instance of the XmlSerializer specifying type and
 namespace.
        Dim serializer As New
 XmlSerializer(GetType(OrderedItem))
        
        ' A FileStream is needed to read the XML document.
        Dim fs As New FileStream(filename,
 FileMode.Open)
        Dim reader As XmlReader = XmlReader.Create(fs)
        
        ' Declare an object variable of the type to be deserialized.
        Dim i As OrderedItem
        
        ' Use the Deserialize method to restore the object's state.
        i = CType(serializer.Deserialize(reader), OrderedItem)
        fs.Close()

        ' Write out the properties of the object.
        Console.Write(i.ItemName & ControlChars.Tab & _
                      i.Description & ControlChars.Tab & _
                      i.UnitPrice & ControlChars.Tab & _
                      i.Quantity & ControlChars.Tab & _
                      i.LineTotal)
    End Sub
End Class

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

// This is the class that will be deserialized.
public class OrderedItem
{
    public string ItemName;
    public string Description;
    public decimal UnitPrice;
    public int Quantity;
    public decimal LineTotal;

    // A custom method used to calculate price per item.
    public void Calculate()
    {
        LineTotal = UnitPrice * Quantity;
    }
}
public class Test
{
    public static void Main(string[]
 args)
    {
        Test t = new Test();
        // Read a purchase order.
        t.DeserializeObject("simple.xml");
    }

    private void DeserializeObject(string
 filename)
    {
        Console.WriteLine("Reading with XmlReader");

        // Create an instance of the XmlSerializer specifying type and
 namespace.
        XmlSerializer serializer = new
        XmlSerializer(typeof(OrderedItem));

        // A FileStream is needed to read the XML document.
        FileStream fs = new FileStream(filename, FileMode.Open);
        XmlReader reader = XmlReader.Create(fs);

        // Declare an object variable of the type to be deserialized.
        OrderedItem i;

        // Use the Deserialize method to restore the object's state.
        i = (OrderedItem)serializer.Deserialize(reader);
        fs.Close();

        // Write out the properties of the object.
        Console.Write(
        i.ItemName + "\t" +
        i.Description + "\t" +
        i.UnitPrice + "\t" +
        i.Quantity + "\t" +
        i.LineTotal);
    }
}
#using <System.Xml.dll>
#using <System.dll>

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

// This is the class that will be deserialized.
public ref class OrderedItem
{
public:
   String^ ItemName;
   String^ Description;
   Decimal UnitPrice;
   int Quantity;
   Decimal LineTotal;

   // A custom method used to calculate price per item.
   void Calculate()
   {
      LineTotal = UnitPrice * Quantity;
   }
};

void DeserializeObject( String^ filename )
{
   Console::WriteLine( "Reading with XmlReader" );

   // Create an instance of the XmlSerializer specifying type and namespace.
   XmlSerializer^ serializer = gcnew XmlSerializer( OrderedItem::typeid );

   // A FileStream is needed to read the XML document.
   FileStream^ fs = gcnew FileStream( filename,FileMode::Open );
   XmlReader^ reader = gcnew XmlTextReader( fs );

   // Declare an object variable of the type to be deserialized.
   OrderedItem^ i;

   // Use the Deserialize method to restore the object's state.
   i = dynamic_cast<OrderedItem^>(serializer->Deserialize( reader ));

   // Write out the properties of the object.
   Console::Write( "{0}\t{1}\t{2}\t{3}\t{4}", i->ItemName, i->Description,
 i->UnitPrice, i->Quantity, i->LineTotal );
}

int main()
{
   // Read a purchase order.
   DeserializeObject( "simple.xml" );
}
import System.*;
import System.IO.*;
import System.Text.*;
import System.Xml.*;
import System.Xml.Serialization.*;

// This is the class that will be deserialized.
public class OrderedItem
{
    public String itemName;
    public String description;
    public System.Decimal unitPrice;
    public int quantity;
    public System.Decimal lineTotal;

    // A custom method used to calculate price per item.
    public void Calculate()
    {
        lineTotal = Decimal.Multiply(unitPrice, Convert.ToDecimal(quantity));
    } //Calculate
} //OrderedItem

public class Test
{
    public static void main(String[]
 args)
    {
        Test t = new Test();
        // Read a purchase order.
        t.DeserializeObject("simple.xml");
    } //main

    private void DeserializeObject(String fileName)
    {
        Console.WriteLine("Reading with XmlReader");

        // Create an instance of the XmlSerializer specifying type and
 namespace.
        XmlSerializer serializer =
            new XmlSerializer(OrderedItem.class.ToType());

        // A FileStream is needed to read the XML document.
        FileStream fs = new FileStream(fileName, FileMode.Open);
        XmlReader reader = new XmlTextReader(fs);

        // Declare an object variable of the type to be deserialized.
        OrderedItem i;

        // Use the Deserialize method to restore the object's state.
        i = (OrderedItem)serializer.Deserialize(reader);

        // Write out the properties of the object.
        Console.Write(i.itemName + "\t" + i.description + "\t"
 + i.unitPrice
            + "\t" + i.quantity + "\t" + i.lineTotal);
    } //DeserializeObject
} //Test
<?xml version="1.0"?>
 <OrderedItem xmlns:inventory="http://www.cpandl.com"
 xmlns:money="http://www.cohowinery.com">
   <inventory:ItemName>Widget</inventory:ItemName>
   <inventory:Description>Regular
 Widget</inventory:Description>
   <money:UnitPrice>2.3</money:UnitPrice>
   <inventory:Quantity>10</inventory:Quantity>
   <money:LineTotal>23</money:LineTotal>
 </OrderedItem>

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

XmlSerializer.Deserialize メソッド (XmlReader, XmlDeserializationEvents)

メモ : このメソッドは、.NET Framework version 2.0新しく追加されたものです。

指定した XmlReader格納されている XML ドキュメントを逆シリアル化ます。また、シリアル化発生するイベントオーバーライド可能にます。

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

Public Function Deserialize ( _
    xmlReader As XmlReader, _
    events As XmlDeserializationEvents _
) As Object
Dim instance As XmlSerializer
Dim xmlReader As XmlReader
Dim events As XmlDeserializationEvents
Dim returnValue As Object

returnValue = instance.Deserialize(xmlReader, events)
public Object Deserialize (
    XmlReader xmlReader,
    XmlDeserializationEvents events
)
public:
Object^ Deserialize (
    XmlReader^ xmlReader, 
    XmlDeserializationEvents events
)
public Object Deserialize (
    XmlReader xmlReader, 
    XmlDeserializationEvents events
)
public function Deserialize (
    xmlReader : XmlReader, 
    events : XmlDeserializationEvents
) : Object

パラメータ

xmlReader

シリアル化するドキュメント格納している XmlReader

events

XmlDeserializationEvents クラスインスタンス

戻り値
シリアル化される Object

解説解説

シリアル化されているオブジェクト

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
XmlSerializer クラス
XmlSerializer メンバ
System.Xml.Serialization 名前空間

XmlSerializer.Deserialize メソッド (XmlSerializationReader)

指定した XmlSerializationReader格納されている XML ドキュメントを逆シリアル化ます。

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

Protected Overridable Function
 Deserialize ( _
    reader As XmlSerializationReader _
) As Object
Dim reader As XmlSerializationReader
Dim returnValue As Object

returnValue = Me.Deserialize(reader)
protected virtual Object Deserialize (
    XmlSerializationReader reader
)
protected:
virtual Object^ Deserialize (
    XmlSerializationReader^ reader
)
protected Object Deserialize (
    XmlSerializationReader reader
)
protected function Deserialize (
    reader : XmlSerializationReader
) : Object

パラメータ

reader

シリアル化する XML ドキュメント格納している XmlSerializationReader。

戻り値
シリアル化されたオブジェクト

例外例外
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
XmlSerializer クラス
XmlSerializer メンバ
System.Xml.Serialization 名前空間



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

辞書ショートカット

すべての辞書の索引

XmlSerializer.Deserialize メソッドのお隣キーワード
検索ランキング

   

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



XmlSerializer.Deserialize メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2024 GRAS Group, Inc.RSS