反序列化序列化此示例: [英] Deserialize Serialize this example:

查看:114
本文介绍了反序列化序列化此示例:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你会如何反序化下面这个例子?


进口系统

进口System.Collections

Imports System.IO

进口System.Xml.Serialization


公共类App1


共享子主()

Dim list As ArrayList = New ArrayList()

Dim out As StreamWriter = New StreamWriter(" array.xml")

Dim ser As XmlSerializer = New XMLSerializer(list.GetType())


list.Add(" a")

list.Add(" 2")

list.Add(" three")

ser.Serialize(out,list)

End Sub

结束班

解决方案

Peter,


我认为你让我们感到困惑。在我看来,你要做的不是

序列化。

Shared Sub Main()
Dim list As ArrayList = New ArrayList( )
Dim out As StreamWriter = New StreamWriter(" array.xml")
Dim ser As XmlSerializer = New XMLSerializer(list.GetType())

list.Add( " a")
list.Add(" 2")
list.Add(" three")

ser.Serialize(out,list)



如果你想将一种XML文档转换为arraylist,这似乎就好了。

那不是序列化。那是使用XMLNodeReader。看看这个样本
我曾经做过的
,这只是一个开始,因为它需要更多。


\\\\ >
Dim xmlString As String ="< department>" &安培; _

"< employee name ="" ABC""年龄= QUOT;" 31 QUOT;"性别= QUOT;"雄"" />" &安培; _

"< employee name ="" CDE""年龄= QUOT;" 40"" sex ="" male"" />< / department>"

Dim sr As New System.IO.StringReader(xmlString)

Dim doc作为新的Xml.XmlDocument

doc.Load(sr)

''或者只是在这种情况下doc.LoadXML(xmlString)

昏暗的阅读器作为新的Xml.XmlNodeReader(doc)

而reader.Read()

选择Case reader.NodeType

Case Xml.XmlNodeType.Element

如果reader.Name =" employee"然后

MessageBox.Show(reader.GetAttribute(" name"))

结束如果

结束选择

结束时

///


我希望这有帮助吗?


Cor


" Cor Ligthert" <无************ @ planet.nl> schrieb:

我认为你让我们感到困惑。在我看来,你要做的不是序列化。

Shared Sub Main()
Dim list As ArrayList = New ArrayList()
Dim out As StreamWriter = New StreamWriter(" array.xml")
Dim ser As XmlSerializer = New XMLSerializer(list.GetType())

list.Add(" a" )
list.Add(" 2")
list.Add(" three")
ser.Serialize(out,list)



这似乎是你想将一种XML文档转换为arraylist。
这不是序列化。




嗯?! OP只是想反序列化已被序列化为XML的arraylist。


-

MS Herfried K. Wagner

MVP< URL:http://dotnet.mvps.org/>

VB< URL:http://dotnet.mvps.org/dotnet/ faqs />



嗯?! OP只是想反序列化已经序列化为XML的arraylist。




为什么你要给出一个简单的?样品


Cor


How would would you deserialize this example below?

Imports System
Imports System.Collections
Imports System.IO
Imports System.Xml.Serialization

Public Class App1

Shared Sub Main()
Dim list As ArrayList = New ArrayList()
Dim out As StreamWriter = New StreamWriter("array.xml")
Dim ser As XmlSerializer = New XMLSerializer(list.GetType())

list.Add("a")
list.Add("2")
list.Add("three")

ser.Serialize(out, list)
End Sub
End Class

解决方案

Peter,

I think that you are confusing us. What you are trying to do is not
serializing in my opinion.

Shared Sub Main()
Dim list As ArrayList = New ArrayList()
Dim out As StreamWriter = New StreamWriter("array.xml")
Dim ser As XmlSerializer = New XMLSerializer(list.GetType())

list.Add("a")
list.Add("2")
list.Add("three")

ser.Serialize(out, list)



This seems if you want to convert a kind of XML document to an arraylist.
That is not serializing. That is using the XMLNodeReader. See this sample
that I once made, just as a start because it needs a lot more.

\\\\
Dim xmlString As String = "<department>" & _
"<employee name=""ABC"" age=""31"" sex=""male""/>" & _
"<employee name=""CDE"" age=""40"" sex=""male""/></department>"
Dim sr As New System.IO.StringReader(xmlString)
Dim doc As New Xml.XmlDocument
doc.Load(sr)
''or just in this case doc.LoadXML(xmlString)
Dim reader As New Xml.XmlNodeReader(doc)
While reader.Read()
Select Case reader.NodeType
Case Xml.XmlNodeType.Element
If reader.Name = "employee" Then
MessageBox.Show(reader.GetAttribute("name"))
End If
End Select
End While
///

I hope this helps?

Cor


"Cor Ligthert" <no************@planet.nl> schrieb:

I think that you are confusing us. What you are trying to do is not
serializing in my opinion.

Shared Sub Main()
Dim list As ArrayList = New ArrayList()
Dim out As StreamWriter = New StreamWriter("array.xml")
Dim ser As XmlSerializer = New XMLSerializer(list.GetType())

list.Add("a")
list.Add("2")
list.Add("three")

ser.Serialize(out, list)



This seems if you want to convert a kind of XML document to an arraylist.
That is not serializing.



Huh?! The OP simply wants to deserialize an arraylist that has been
serialized to XML.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>



Huh?! The OP simply wants to deserialize an arraylist that has been
serialized to XML.



Why do you than not give a "simple" sample for that

Cor


这篇关于反序列化序列化此示例:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆