473,473 Members | 1,692 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Serialization and Array

Let me describe the flow of my program first.
1. Deserialize data from xml file.
2. Addition of "PersonType" class to the AllPersonalData.
3. Serialize data back to the xml file.

My question is I have to use an array PersonType[] in the AllPersonalData class. But if I have to implement the "Addition of
PersonalType" (i.e. the step 2), I have to use ArrayList instead of a fixed length array. I know that I can use the ArrayList as an
intermediate, and then convert it to fixed length array when I do Serialization. But is there any alternative which is more direct?
Thanks.

The following are class declaration.

[System.Xml.Serialization.XmlRootAttribute("AllPers onalData", Namespace="", IsNullable=false)]
public class AllPersonalData {
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("Pers on")]
public PersonType[] Person;
}

public class PersonType {
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string Name;
}

--
My C++ and C# ( Traditional Chinese ) Web Site : www.franzwong.com/Home.php


Nov 11 '05 #1
3 3054
Do you mean I can first use the array for deserialization, and turn it to ArrayList, then I can directly serialize ArrayList?

--
My C++ and C# ( Traditional Chinese ) Web Site : www.franzwong.com/Home.php
"Christoph" <ch*************@austin.rr.com> ¼¶¼g©ó¶l¥ó·s»D:#h**************@tk2msftngp13.phx.g bl...
Franz,

Why don't you just serialize the ArrayList? ArrayLists work just as good as
typed arrays.

HTH,
Christoph Schittko
Software Architect, .NET Mentor
MS MVP XML .NET
"Franz" <ho******@yahoo.com.hk> wrote in message
news:uq*************@tk2msftngp13.phx.gbl...
Let me describe the flow of my program first.
1. Deserialize data from xml file.
2. Addition of "PersonType" class to the AllPersonalData.
3. Serialize data back to the xml file.

My question is I have to use an array PersonType[] in the AllPersonalData

class. But if I have to implement the "Addition of
PersonalType" (i.e. the step 2), I have to use ArrayList instead of a

fixed length array. I know that I can use the ArrayList as an
intermediate, and then convert it to fixed length array when I do

Serialization. But is there any alternative which is more direct?
Thanks.

The following are class declaration.

[System.Xml.Serialization.XmlRootAttribute("AllPers onalData",

Namespace="", IsNullable=false)]
public class AllPersonalData {
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("Pers on")]
public PersonType[] Person;
}

public class PersonType {
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string Name;
}

--
My C++ and C# ( Traditional Chinese ) Web Site :

www.franzwong.com/Home.php



Nov 11 '05 #2
You can change your AllPersonData class like this and you can dynamically
add PersonType objects to the collection.

[System.Xml.Serialization.XmlRootAttribute("AllPers onalData", Namespace="",
IsNullable=false)]
public class AllPersonalData {
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("Pers on", typeof(
PersonType))]
public ArrayList Person;
}

This is all you need, you can serialize and deserialize this class. You can
also write your own collection class derived from CollectionBase if you want
type-safety. The Framework SDK docs show an example, IIRC.

HTH,
Christoph Schittko
Software Architect, .NET Mentor
MS MVP XML .NET

"Franz" <ho******@yahoo.com.hk> wrote in message
news:eU**************@TK2MSFTNGP11.phx.gbl...
Do you mean I can first use the array for deserialization, and turn it to ArrayList, then I can directly serialize ArrayList?
--
My C++ and C# ( Traditional Chinese ) Web Site : www.franzwong.com/Home.php

"Christoph" <ch*************@austin.rr.com>

¼¶¼g©ó¶l¥ó·s»D:#h**************@tk2msftngp13.phx.g bl...
Franz,

Why don't you just serialize the ArrayList? ArrayLists work just as good as typed arrays.

HTH,
Christoph Schittko
Software Architect, .NET Mentor
MS MVP XML .NET
"Franz" <ho******@yahoo.com.hk> wrote in message
news:uq*************@tk2msftngp13.phx.gbl...
Let me describe the flow of my program first.
1. Deserialize data from xml file.
2. Addition of "PersonType" class to the AllPersonalData.
3. Serialize data back to the xml file.

My question is I have to use an array PersonType[] in the
AllPersonalData class. But if I have to implement the "Addition of
PersonalType" (i.e. the step 2), I have to use ArrayList instead of a

fixed length array. I know that I can use the ArrayList as an
intermediate, and then convert it to fixed length array when I do

Serialization. But is there any alternative which is more direct?
Thanks.

The following are class declaration.

[System.Xml.Serialization.XmlRootAttribute("AllPers onalData",

Namespace="", IsNullable=false)]
public class AllPersonalData {
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("Pers on")]
public PersonType[] Person;
}

public class PersonType {
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string Name;
}

--
My C++ and C# ( Traditional Chinese ) Web Site :

www.franzwong.com/Home.php




Nov 11 '05 #3
That's what I want.
Thank you.

--
My C++ and C# ( Traditional Chinese ) Web Site : www.franzwong.com
"Christoph Schittko [MVP]" <ch********************@austin.rr.com> ¼¶¼g©ó¶l¥ó·s»D:e7**************@TK2MSFTNGP10.phx.g bl...
You can change your AllPersonData class like this and you can dynamically
add PersonType objects to the collection.

[System.Xml.Serialization.XmlRootAttribute("AllPers onalData", Namespace="",
IsNullable=false)]
public class AllPersonalData {
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("Pers on", typeof(
PersonType))]
public ArrayList Person;
}

This is all you need, you can serialize and deserialize this class. You can
also write your own collection class derived from CollectionBase if you want
type-safety. The Framework SDK docs show an example, IIRC.

HTH,
Christoph Schittko
Software Architect, .NET Mentor
MS MVP XML .NET

"Franz" <ho******@yahoo.com.hk> wrote in message
news:eU**************@TK2MSFTNGP11.phx.gbl...
Do you mean I can first use the array for deserialization, and turn it to

ArrayList, then I can directly serialize ArrayList?

--
My C++ and C# ( Traditional Chinese ) Web Site :

www.franzwong.com/Home.php


"Christoph" <ch*************@austin.rr.com>

¼¶¼g©ó¶l¥ó·s»D:#h**************@tk2msftngp13.phx.g bl...
Franz,

Why don't you just serialize the ArrayList? ArrayLists work just as good as typed arrays.

HTH,
Christoph Schittko
Software Architect, .NET Mentor
MS MVP XML .NET
"Franz" <ho******@yahoo.com.hk> wrote in message
news:uq*************@tk2msftngp13.phx.gbl...
> Let me describe the flow of my program first.
> 1. Deserialize data from xml file.
> 2. Addition of "PersonType" class to the AllPersonalData.
> 3. Serialize data back to the xml file.
>
> My question is I have to use an array PersonType[] in the AllPersonalData class. But if I have to implement the "Addition of
> PersonalType" (i.e. the step 2), I have to use ArrayList instead of a
fixed length array. I know that I can use the ArrayList as an
> intermediate, and then convert it to fixed length array when I do
Serialization. But is there any alternative which is more direct?
> Thanks.
>
> The following are class declaration.
>
> [System.Xml.Serialization.XmlRootAttribute("AllPers onalData",
Namespace="", IsNullable=false)]
> public class AllPersonalData {
> /// <remarks/>
> [System.Xml.Serialization.XmlElementAttribute("Pers on")]
> public PersonType[] Person;
> }
>
> public class PersonType {
> /// <remarks/>
> [System.Xml.Serialization.XmlAttributeAttribute()]
> public string Name;
> }
>
> --
> My C++ and C# ( Traditional Chinese ) Web Site :
www.franzwong.com/Home.php
>
>
>
>



Nov 11 '05 #4

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

Similar topics

16
by: Bob Rock | last post by:
Hello, when serializing an array of elements of a class Classname using XmlSerializer.Serialize() I get an XML like the following: <?xml version="1.0"> <ArrayOfClassname> ....... ..........
3
by: Ice | last post by:
All - I'm pretty comfortable with simple XML serialization of objects. However I observed something the other day and I wanted to know if I solved it the right way. Basically if I have a...
4
by: ron | last post by:
Hi, I have class object that i serialize using the System.Xml.Serialization class. Intermittently the object is not getting serialized correctly, using System.Xml.Serialization classes....
3
by: Amadelle | last post by:
Hi all and thanks in advance for your help, I am having problems deserializing an object which seems to be serializing just fine. I save the byte array of the serialized object in the database...
11
by: ajou_king | last post by:
I was running some tests on my Win32 1GHZ processor to see how long it would take to transmit objects numerous times via TCP/IP using C# ..NET Remoting vs the C++ trustworthy method of binary...
0
by: umhlali | last post by:
I get the following exception when my VB.NET app calls a Java web service that returns an array of objects. The same call works for a single object though. So looks like there is no problem...
1
by: elziko | last post by:
My intention is to store an array of singles inside a DataTable so that it can me peristed somehow, maybe XML file, maybe Access/SQL Server I don't know yet so I'm just saving it as an XML file for...
5
by: Henry Jones | last post by:
I read a bit on Serialization and came up with the following definition: The System.Runtime.Serialization namespace contains classes that can be used for serializing and deserializing objects....
1
by: kikisan | last post by:
I am developing a windows service which utilizes the following classes: interface IPersistable; abstract class PersistableObject : IPersistable;
0
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
1
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
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...
0
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
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
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 ...

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.