本文整理匯總了VB.NET中System.Xml.Serialization.XmlSerializer.Deserialize方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET XmlSerializer.Deserialize方法的具體用法?VB.NET XmlSerializer.Deserialize怎麽用?VB.NET XmlSerializer.Deserialize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Xml.Serialization.XmlSerializer
的用法示例。
在下文中一共展示了XmlSerializer.Deserialize方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: OrderedItem
' 導入命名空間
Imports System.IO
Imports System.Xml.Serialization
' This is the class that will be deserialized.
Public Class OrderedItem
<XmlElement(Namespace := "http://www.cpandl.com")> _
Public ItemName As String
<XmlElement(Namespace := "http://www.cpandl.com")> _
Public Description As String
<XmlElement(Namespace := "http://www.cohowinery.com")> _
Public UnitPrice As Decimal
<XmlElement(Namespace := "http://www.cpandl.com")> _
Public Quantity As Integer
<XmlElement(Namespace := "http://www.cohowinery.com")> _
Public LineTotal As Decimal
'A custom method used to calculate price per item.
Public Sub Calculate()
LineTotal = UnitPrice * Quantity
End Sub
End Class
Public Class Test
Public Shared Sub Main()
Dim t As New Test()
' Read a purchase order.
t.DeserializeObject("simple.xml")
End Sub
Private Sub DeserializeObject(ByVal filename As String)
Console.WriteLine("Reading with Stream")
' Create an instance of the XmlSerializer.
Dim serializer As New XmlSerializer(GetType(OrderedItem))
' Declare an object variable of the type to be deserialized.
Dim i As OrderedItem
Using reader As New Filestream(filename, FileMode.Open)
' Call the Deserialize method to restore the object's state.
i = CType(serializer.Deserialize(reader), OrderedItem)
End Using
' Write out the properties of the object.
Console.Write(i.ItemName & ControlChars.Tab & _
i.Description & ControlChars.Tab & _
i.UnitPrice & ControlChars.Tab & _
i.Quantity & ControlChars.Tab & _
i.LineTotal)
End Sub
End Class
示例2: OrderedItem
' 導入命名空間
Imports System.IO
Imports System.Text
Imports System.Xml.Serialization
' This is the class that will be deserialized.
Public Class OrderedItem
<XmlElement(Namespace := "http://www.cpandl.com")> _
Public ItemName As String
<XmlElement(Namespace := "http://www.cpandl.com")> _
Public Description As String
<XmlElement(Namespace := "http://www.cohowinery.com")> _
Public UnitPrice As Decimal
<XmlElement(Namespace := "http://www.cpandl.com")> _
Public Quantity As Integer
<XmlElement(Namespace := "http://www.cohowinery.com")> _
Public LineTotal As Decimal
' A custom method used to calculate price per item.
Public Sub Calculate()
LineTotal = UnitPrice * Quantity
End Sub
End Class
Public Class Test
Public Shared Sub Main()
Dim t As New Test()
' Read a purchase order.
t.DeserializeObject("simple.xml")
End Sub
Private Sub DeserializeObject(filename As String)
Console.WriteLine("Reading with TextReader")
' Create an instance of the XmlSerializer specifying type.
Dim serializer As New XmlSerializer(GetType(OrderedItem))
' Create a TextReader to read the file.
Dim fs as New FileStream(filename, FileMode.OpenOrCreate)
Dim reader As New StreamReader(fs)
' Declare an object variable of the type to be deserialized.
Dim i As OrderedItem
' Use the Deserialize method to restore the object's state.
i = CType(serializer.Deserialize(reader), OrderedItem)
' Write out the properties of the object.
Console.Write(i.ItemName & ControlChars.Tab & _
i.Description & ControlChars.Tab & _
i.UnitPrice & ControlChars.Tab & _
i.Quantity & ControlChars.Tab & _
i.LineTotal)
End Sub
End Class
示例3: OrderedItem
' 導入命名空間
Imports System.IO
Imports System.Text
Imports System.Xml
Imports System.Xml.Serialization
' This is the class that will be deserialized.
Public Class OrderedItem
Public ItemName As String
Public Description As String
Public UnitPrice As Decimal
Public Quantity As Integer
Public LineTotal As Decimal
' A custom method used to calculate price per item.
Public Sub Calculate()
LineTotal = UnitPrice * Quantity
End Sub
End Class
Public Class Test
Public Shared Sub Main()
Dim t As New Test()
' Read a purchase order.
t.DeserializeObject("simple.xml")
End Sub
Private Sub DeserializeObject(ByVal filename As String)
Console.WriteLine("Reading with XmlReader")
' Create an instance of the XmlSerializer specifying type and namespace.
Dim serializer As New XmlSerializer(GetType(OrderedItem))
' A FileStream is needed to read the XML document.
Dim fs As New FileStream(filename, FileMode.Open)
Dim reader As XmlReader = XmlReader.Create(fs)
' Declare an object variable of the type to be deserialized.
Dim i As OrderedItem
' Use the Deserialize method to restore the object's state.
i = CType(serializer.Deserialize(reader), OrderedItem)
fs.Close()
' Write out the properties of the object.
Console.Write(i.ItemName & ControlChars.Tab & _
i.Description & ControlChars.Tab & _
i.UnitPrice & ControlChars.Tab & _
i.Quantity & ControlChars.Tab & _
i.LineTotal)
End Sub
End Class