Archive

Posts Tagged ‘Serialization’

XML Serialization


   Private Function LoadInvoice(XMLFilename As String) As Boolean
      Try

         Dim reader As TextReader = New StreamReader(XMLFilename)
         Dim serializer As New XmlSerializer(GetType(Invoice.Documents))

         Dim myInvoices As New Invoice.Documents
         myInvoices = DirectCast(serializer.Deserialize(reader), Invoice.Documents)
         reader.Close()

         Dim xmlOutputFilename As String = Path.GetDirectoryName(XMLFilename)
         xmlOutputFilename &= "\" & Path.GetFileNameWithoutExtension(XMLFilename) & "_1.xml"

         Dim writer As FileStream = New FileStream(xmlOutputFilename, FileMode.Create)
         serializer = New XmlSerializer(GetType(Invoice.Documents))

         serializer.Serialize(writer, myInvoices)
         writer.Close()


      Catch ex As Exception
         Log.TraceError(ex, String.Format("Error occured in {0}", System.Reflection.MethodInfo.GetCurrentMethod.Name))

      End Try
   End Function

Categories: XML Serialization Tags: ,