473,667 Members | 2,568 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Deserialize Serialize this example:

How would would you deserialize this example below?

Imports System
Imports System.Collecti ons
Imports System.IO
Imports System.Xml.Seri alization

Public Class App1

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

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

ser.Serialize(o ut, list)
End Sub
End Class
Nov 21 '05 #1
17 1861
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("a rray.xml")
Dim ser As XmlSerializer = New XMLSerializer(l ist.GetType())

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

ser.Serialize(o ut, 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 = "<departmen t>" & _
"<employee name=""ABC"" age=""31"" sex=""male""/>" & _
"<employee name=""CDE"" age=""40"" sex=""male""/></department>"
Dim sr As New System.IO.Strin gReader(xmlStri ng)
Dim doc As New Xml.XmlDocument
doc.Load(sr)
'or just in this case doc.LoadXML(xml String)
Dim reader As New Xml.XmlNodeRead er(doc)
While reader.Read()
Select Case reader.NodeType
Case Xml.XmlNodeType .Element
If reader.Name = "employee" Then
MessageBox.Show (reader.GetAttr ibute("name"))
End If
End Select
End While
///

I hope this helps?

Cor
Nov 21 '05 #2
"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("a rray.xml")
Dim ser As XmlSerializer = New XMLSerializer(l ist.GetType())

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

ser.Serialize(o ut, 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/>

Nov 21 '05 #3

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
Nov 21 '05 #4
"Cor Ligthert" <no************ @planet.nl> schrieb:
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


There is no guarantee that I'll answer a question.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #5
Herfried,
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


There is no guarantee that I'll answer a question.


You said it was simple, so I could not resist that was the only reason.

:-)

Cor

"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> "Cor Ligthert" <no************ @planet.nl> schrieb:
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #6
Cor
I think that you are confusing us. What you are trying to do is not
serializing in my opinion. Huh????

You may want to review MSDN on what the XmlSerializer in .NET is!

http://msdn.microsoft.com/library/de...classtopic.asp

<quote>
XmlSerializer

Serializes and deserializes objects into and from XML documents.
</quote>

To Deserialize an object that was serialized with XmlSerializer you simply
call, wait for it, the Deserialize method!
ser.Serialize(o ut, list)
Dim ser As XmlSerializer = New XMLSerializer(l ist.GetType())


Dim input As StreamReader
list = ser.Deserialze( input)

For a more complete example see my other post.

Hope this helps
Jay

"Cor Ligthert" <no************ @planet.nl> wrote in message
news:eC******** ******@tk2msftn gp13.phx.gbl... 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("a rray.xml")
Dim ser As XmlSerializer = New XMLSerializer(l ist.GetType())

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

ser.Serialize(o ut, 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 = "<departmen t>" & _
"<employee name=""ABC"" age=""31"" sex=""male""/>" & _
"<employee name=""CDE"" age=""40"" sex=""male""/></department>"
Dim sr As New System.IO.Strin gReader(xmlStri ng)
Dim doc As New Xml.XmlDocument
doc.Load(sr)
'or just in this case doc.LoadXML(xml String)
Dim reader As New Xml.XmlNodeRead er(doc)
While reader.Read()
Select Case reader.NodeType
Case Xml.XmlNodeType .Element
If reader.Name = "employee" Then
MessageBox.Show (reader.GetAttr ibute("name"))
End If
End Select
End While
///

I hope this helps?

Cor

Nov 21 '05 #7
Peter,
If you use XMLSerializer.S erialize to serialize an object, you can use
XMLSerializer.D eserialize to deserialize the object.

Something like:

Dim ser As XmlSerializer = New XMLSerializer(G etType(ArrayLis t))
Dim input As StreamReader = New StreamReader("a rray.xml")
Dim list As ArrayList = DirectCast(ser. Deserialize(inp ut),
ArrayList)
input.Close()

For information on the XMLSerializer class with examples, see:

http://msdn.microsoft.com/library/de...ialization.asp

http://msdn.microsoft.com/library/de...classtopic.asp

Hope this helps
Jay
"Peter" <pe***@mclinn.c om> wrote in message
news:dc******** *************** ***@posting.goo gle.com...
How would would you deserialize this example below?

Imports System
Imports System.Collecti ons
Imports System.IO
Imports System.Xml.Seri alization

Public Class App1

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

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

ser.Serialize(o ut, list)
End Sub
End Class

Nov 21 '05 #8
Jay,

I had changed my mind already and had reviewed these articles therefore
"again" on saterday.

And tried some things with using the arraylist with that, however I have not
the idea it is easy to create nodes from the objects from an arraylist, and
therefore I waited on a more concrete answer from Peter.

As well do I think it is much easier only to serialize an arraylist and not
try to bring it to an XML document. However that is as well waiting for an
answer from Peter.

Thanks any way for sending the links you could not know that.

Cor
Nov 21 '05 #9
"Cor Ligthert" <no************ @planet.nl> schrieb:
I had changed my mind already and had reviewed these articles therefore
"again" on saterday.

And tried some things with using the arraylist with that, however I have
not the idea it is easy to create nodes from the objects from an
arraylist, and therefore I waited on a more concrete answer from Peter.

As well do I think it is much easier only to serialize an arraylist and
not try to bring it to an XML document. However that is as well waiting
for an answer from Peter.

Thanks any way for sending the links you could not know that.


Huh (again)?!

When using XML serialization to serialize the arraylist, you don't need to
deal with 'XMLDocument' and nodes at all. The serializer/deserializer will
do that for you.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
5826
by: Ian Tompsett | last post by:
H I was wondering if it possible for an object to serialize/deserialize itself from XML. I'd be guessing that it would need to use the XmlSerializer class, but that seems to want to create a brand new object when deserializing. In my case I have an existing object that I'd like to pass some XML to for the object to repopulate its member variables. Similarly I'd like it to be able to populate an XML string from the values of its member...
2
11681
by: Hollywood | last post by:
After doing a search through google's archives of this list, I didn't see what I was looking for so here goes... Is it possible to serialize/deserialize multiple objects from a single XML file? I was looking to use the XML serialization to be able to translate complex XML elements in a single XML file through XML serialization as opposed to using SAX and coding my own serializer. However, the XML Serialization API appears to only...
2
9531
by: Greg | last post by:
I'm writing a class in C# .... I have a collection calls Reports made up of Report objects. I'm trying to deserialize an XML file that looks like : <Reports> <Report> <Title>some title</Title> <Notes> some notes </Notes> </Report> <Report> blah blah blah </Report>
0
2169
by: Mike Pollett | last post by:
Hi, I have used the ISerializable interface before and the code below worked fine. Until I derived it from CollectionBase. The code will still serialize and deserialize the properties in this class and properties derived from this class but will not serialize or deserialize the properties in CollectionBase. Like InnerList, which is a read only property of CollectionBase. How can I serialize and deserialize the InnerList property of...
1
7084
by: Mike Pollett | last post by:
Hi, I have used the ISerializable interface before and the code below worked fine. Until I derived it from CollectionBase. The code will still serialize and deserialize the properties in this class and properties derived from this class but will not serialize or deserialize the properties in CollectionBase. Like InnerList, which is a read only property of CollectionBase. How can I serialize and deserialize the InnerList property of...
3
9345
by: Just D. | last post by:
Can we deserialize an unknown object? The task is simple - we have many different types of objects stored in ArrayList. We can implement Serialize() method for each object and serialize all these objects, or maybe even serialize the whole ArrayList at once. Is it possible to deserialize this array list keeping in mind that we can have many different types of objects in this ArrayList? Just D.
2
6068
by: PCH | last post by:
I have 2 functions, one to serialize an object, and one to deserialize it. I can serialize just fine, the problem is when I try to deserialize it later... I get an error: {"Invalid BinaryFormatter stream. " } I looked at the serialized string vs whats passed into the deserialize
2
2423
by: alexandre martins | last post by:
Every time i try to make Deserialize the computer gives me the folowing error: "End of Stream encountered before parsing was complete" the code that i'm running is simple and is based on an MSDN example. The CODE is BELOW this lines. If you see something wrong or missing please answer. Class declaration:
2
35680
by: Joe | last post by:
Hi I have a Generics List in a PropertyGrid I am able to Serialize it to XML but when I try to deserialize back to the class of the PropertyGrid The Constructor doesn't seem to fire to reload the saved settings Can anyone see something that I have missed ?
0
8457
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8788
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8563
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7390
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4200
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4372
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2013
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1778
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.