Click here to Skip to main content
15,881,380 members
Articles / Programming Languages / Visual Basic

XML Serialization - Part 1

Rate me:
Please Sign up or sign in to vote.
3.95/5 (6 votes)
21 Feb 2008CPOL1 min read 32K   405   19  
How to Use XML to Serialize and Deserialize an Object
Imports System.Xml.Serialization

<XmlRoot(ElementName:="Class_Order")> _
Public Class Order
    Dim m_menuitem As String
    Dim m_OrderQty As Int16
    Dim m_Taste As String
    Dim m_Fat As String
    Dim m_Customer As String
    Dim m_TableNo As String
    Public Sub New()

    End Sub
    Public Sub New(ByVal m_menuitem As String, ByVal m_OrderQty As Int16, ByVal m_Taste As String, ByVal m_Fat As String, ByVal m_Customer As String, ByVal m_TableNo As String)
        Me.MenuItem = m_menuitem
        Me.OrderedQty = m_OrderQty
        Me.OrderedTaste = m_Taste
        Me.OrderedFat = m_Fat
        Me.Customer = m_Customer
        Me.TableNo = m_TableNo
    End Sub
    <XmlElement(ElementName:="Customer")> _
    Public Property Customer() As String
        Get
            Return m_Customer
        End Get
        Set(ByVal value As String)
            m_Customer = value
        End Set
    End Property
    <XmlElement(ElementName:="TableNo")> _
    Public Property TableNo() As String
        Get
            Return m_TableNo
        End Get
        Set(ByVal value As String)
            m_TableNo = value
        End Set
    End Property
    <XmlElement(ElementName:="OrderedQty")> _
    Public Property OrderedQty() As Int16
        Get
            Return m_OrderQty
        End Get
        Set(ByVal value As Int16)
            m_OrderQty = value
        End Set
    End Property
    <XmlElement(ElementName:="OrderedTaste")> _
    Public Property OrderedTaste() As String
        Get
            Return m_Taste
        End Get
        Set(ByVal value As String)
            m_Taste = value
        End Set
    End Property
    <XmlElement(ElementName:="OrderedFat")> _
    Public Property OrderedFat() As String
        Get
            Return m_Fat
        End Get
        Set(ByVal value As String)
            m_Fat = value
        End Set
    End Property
    <XmlElement(ElementName:="MenuItem")> _
    Public Property MenuItem() As String
        Get
            Return m_menuitem
        End Get
        Set(ByVal value As String)
            m_menuitem = value
        End Set
    End Property
    
End Class




By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
India India
Pranav Patel
B.Sc, MCSD

I am serving my company as Sr. Software Engineer. I have more than 4 years of experience in Microsoft Technologies specially VB 6, VB.Net,C#,ASP.Net and MS SQL Server

Comments and Discussions