473,513 Members | 2,266 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.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
Nov 21 '05 #1
17 1850
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
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("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/>

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(out, list)
Dim ser As XmlSerializer = New XMLSerializer(list.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**************@tk2msftngp13.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("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

Nov 21 '05 #7
Peter,
If you use XMLSerializer.Serialize to serialize an object, you can use
XMLSerializer.Deserialize to deserialize the object.

Something like:

Dim ser As XmlSerializer = New XMLSerializer(GetType(ArrayList))
Dim input As StreamReader = New StreamReader("array.xml")
Dim list As ArrayList = DirectCast(ser.Deserialize(input),
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.com> wrote in message
news:dc**************************@posting.google.c om...
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

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
>Herfried K.Wagner
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.


Again, show than that sample (when it is so simple as you repeatedly say)
when as the OP showed an from a class instanced object (or even different
objects, what he did not show) are the objects that the arraylist contains

Cor
Nov 21 '05 #11
Cor,

"Cor Ligthert" <no************@planet.nl> schrieb:
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.


Again, show than that sample (when it is so simple as you repeatedly say)
when as the OP showed an from a class instanced object (or even different
objects, what he did not show) are the objects that the arraylist contains


Jay already gave parts of an example and lots of related information.

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

Jay already gave parts of an example and lots of related information.

Yes that I wrote already long before you.

Cor
Nov 21 '05 #13
"Cor Ligthert" <no************@planet.nl> schrieb:
Jay already gave parts of an example and lots of related information.


Yes that I wrote already long before you.


Then why do you expect that I post a sample? The question was/is already
answered by Jay B. Harlow [MVP - Outlook]. No need to repeat what he wrote.

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

In contradiction too you, I did not repeat it, I was answering Jay and in
that was the conformation about what he wrote.

Although I readed his sample in his answer just as a link to the answer. To
do deserialization, you you have first have to serialize an arraylist, and
that is in my opinion not as simple as the answer from Jay.

Cor

"Herfried K. Wagner [MVP]"
"Cor Ligthert" <no************@planet.nl> schrieb:
Jay already gave parts of an example and lots of related information.


Yes that I wrote already long before you.


Then why do you expect that I post a sample? The question was/is already
answered by Jay B. Harlow [MVP - Outlook]. No need to repeat what he
wrote.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 21 '05 #15
The only thing I'm trying to accomplish here is to Export this
Arraylisr into a xml file and then re-import it back into another
arraylist.
I'll read through the posted articles tonight. Thank you.

-Peter

Nov 21 '05 #16
Peter,

And when you do not succeed, than convert it first to a datatable, add that
to a dataset and than do ds.writexml(path) and to get it back
ds.readxml(path).

One of the reasons to use it as XML is why there are datasets you know.

Just my thought,

Cor

The only thing I'm trying to accomplish here is to Export this
Arraylisr into a xml file and then re-import it back into another
arraylist.
I'll read through the posted articles tonight. Thank you.

Nov 21 '05 #17
It is VERY easty to serialize/deserialize an arraylist, as long as the
contained objects in the arraylist are also serializable:
//DESERIALIZE
objFileStream = new FileStream( "ServerList.data", FileMode.Open );
_Servers = (ArrayList)objBinaryFormatter.Deserialize( objFileStream );
objFileStream.Close();
foreach(clsServer cServer in _Servers)
{
TreeNode tvNode = new TreeNode();
tvNode.Text = cServer.ServerName;
tvNode.Tag = "SERVER";
ctrlTree.Nodes[rNode.Index].Nodes.Add(tvNode);
}
//SERIALIZE
FileStream objFileStream;
BinaryFormatter objBinaryFormatter;
objFileStream = new FileStream( "ServerList.data" ,
FileMode.OpenOrCreate );
objBinaryFormatter = new BinaryFormatter();
objBinaryFormatter.Serialize(objFileStream, _Servers);
objFileStream.Close();
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #18

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

Similar topics

7
5809
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...
2
11641
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? ...
2
9515
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>...
0
2160
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...
1
7071
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...
3
9337
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...
2
6034
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...
2
2416
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...
2
35568
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...
0
7265
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,...
0
7388
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7111
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...
0
7539
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5095
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4751
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...
0
3240
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...
0
1605
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
461
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...

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.