Home > XML Serialization > XML 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

Advertisements
Categories: XML Serialization Tags: ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: