XML ストリームへの保存・読み込み方法

Public m_pXMLString As String

'===== オブジェクトをXMLにシリアライズ =====
Public Sub WriteXML()
  ' ポイントの作成
  Dim pPoint As IPoint
  Set pPoint = New Point
  pPoint.PutCoords 139.74, 35.66
  
  Dim pXMLStream As IXMLStream
  Set pXMLStream = New XMLStream
  
  Dim pStream As IStream
  Set pStream = pXMLStream
  
  Dim pXMLWriter As IXMLWriter
  Set pXMLWriter = New XMLWriter
  pXMLWriter.WriteTo pStream
  
  'ポイント・オブジェクトをXMLにシリアライズ
  Dim pXMLSerializer As IXMLSerializer
  Set pXMLSerializer = New XMLSerializer
  pXMLSerializer.WriteObject pXMLWriter, Nothing, Nothing, "", "", pPoint
  
  ' モジュール変数にXMLを格納
  m_pXMLString = pXMLStream.SaveToString
  
  ' XMLをメッセージボックスに表示
'  MsgBox m_pXMLString
  Debug.Print m_pXMLString
  
  pXMLStream.SaveToFile "D:\test.xml"
End Sub

'===== XMLからオブジェクトにデシリアライズ =====
Public Sub ReadXML()
  ' モジュール変数のXMLを読み込み
  Dim pXMLStream As IXMLStream
  Set pXMLStream = New XMLStream
  pXMLStream.LoadFromString m_pXMLString
  pXMLStream.LoadFromString obj
  
  Dim pStream As IStream
  Set pStream = pXMLStream
  
  Dim pXMLReader As IXMLReader
  Set pXMLReader = New XMLReader
  pXMLReader.ReadFrom pStream
  
  Dim pXMLSerializer As IXMLSerializer
  Set pXMLSerializer = New XMLSerializer
  
  ' XMLからポイント・オブジェクトにデシリアライズ
  Dim pPoint As IPoint
  Set pPoint = pXMLSerializer.ReadObject(pXMLReader, Nothing, Nothing)
  
  ' ポイント・オブジェクトが持つXY座標をメッセージボックスに表示
  MsgBox "X座標 = " & pPoint.X & ", Y座標 = " & pPoint.Y
End Sub

'ArcコミュニティNo.069 より引用