Site Map       
Home
Web Services
XML in .NET
XML Schema
XSLT and XPath
XML Serialization
Database and XML
XML Query
ASP.NET
Contact Info

.NET Notes

 

XML Deserialization

The following example shows how an XML document can be deserialized to retrieve consumer product data for a .NET class.

               



        
'Sample Code

        Dim prd As Product
        Dim ser As New XmlSerializer(GetType(Product))
        Dim fs As New FileStream(Server.MapPath("MyPath\MyProduct.xml"), FileMode.Open)

        Try
            prd = ser.Deserialize(fs)

        Catch
            'Handle Errors

        Finally
            'Clean Up
        End Try
        
 'Product Class

    Public Class Product

    Private ProdId As Integer
    Private ProdName As String
    Private ProdPrice As Decimal

    Public Property ProductID() As Integer
        Get
            Return ProdId
        End Get
        Set(ByVal Value As Integer)
            ProdId = Value
        End Set
    End Property

    Public Property ProductName() As String
        Get
            Return ProdName
        End Get
        Set(ByVal Value As String)
            ProdName = Value
        End Set
    End Property

    Public Property ProductPrice() As Decimal
        Get
            Return ProdPrice
        End Get
        Set(ByVal Value As Decimal)
            ProdPrice = Value
        End Set
    End Property

End Class       
    

Copyright © 2015 Seanco Technology, Inc.  All rights reserved.