473,320 Members | 1,926 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Serializing a collection class

Hi,

is it possible to serialize a top-level class with a collection of items?
For example, is this possible:
<ParkingLot ...>
<ParkedCar><Make>Ford</Make></ParkedCar>
<ParkedMotorcycle><Make>Honda</Make></ParkedMotorcycle>
<ParkedCar><Make>Hyondai</Make></ParkedCar>
<ParkedCar><Make>Volvo</Make></ParkedCar>
.... lots of other cars and motorcycles ...
</ParkingLot>

I know it is possible to serialize a known number of vehicles, with a class
like this:

public class ParkingLot
{
public ParkingLot()
{
Vehicles = new Vehicle[2];
}
[XmlElement(ElementName="ParkedCar", Type=typeof(Car))]
[XmlElement(ElementName="ParkedMotorcycle", Type=typeof(Motorcycle))]
public Vehicle[] Vehicles;
}
(both Car and Motorcycle derive from Vehicle).

But what if I don't know in advance how many Vehicles are going to be
serialized? I do not want to have an extra parent element around all my
vehicles as such:
<ParkingLot ...>
<ParkedVehicles>
<ParkedCar><Make>Ford</Make></ParkedCar>
<ParkedMotorcycle><Make>Honda</Make></ParkedMotorcycle>
</ParkedVehicles>
</ParkingLot>

I am grateful for any tips you can give me.
Thank you!

--
Daniel
Nov 12 '05 #1
0 1189

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

Similar topics

5
by: Jeff Bunting | last post by:
I'm trying to serialize a class I have and have been getting: An unhandled exception of type 'System.InvalidOperationException' occurred in system.xml.dll There was an error reflecting type...
1
by: dotNetDave | last post by:
I'm trying to create xml seriaizable collection class (below), but the xml keeps coming out wrong. In the resulting xml from the web service (below) the "ArrayOfAlarmProcessor" tag should really be...
2
by: Aleksei Guzev | last post by:
Imagine one writing a class library CL1 for data storage. He defines classes ‘DataItem’ and ‘DataRecord’ so that the latter contains a collection of the former. And he derives class ‘IntItem’ from...
0
by: Jordan Bowness | last post by:
I make a similar post in another newsgroup, but this example is simplified somewhat. I have a component (cmpMyComponent) with 2 properties. The 1st property is a string value (Description) and...
0
by: Michael Maercker | last post by:
Hi! I'm about to go nuts over my serializing problem. This is my situation: I have a Data-Class that can have children of the same class which are stored in a hashtable, i.e: X has A as a...
3
by: axr | last post by:
Having trouble with Serilization of objects that contain members which are of type Interface eg public class SomeClass { ISomeInterface1 itf1; ClassType1 ct1; ISomeInterface2 itf2;
3
by: RandomEngineer | last post by:
So here's the challenge... How can a collection (System.Collections.Generic.IList) of some custom type be serialized in a web service using .NET 2.0? Below are the class and the web methods in...
0
by: Yofnik | last post by:
Is there a way to avoid serializing an empty ArrayList? I would like the following class: public class Collection { public ArrayList Items = new ArrayList(); } ....to serialize like this:
0
by: freddie | last post by:
Hi, I am adding the data binding feature to the list view control. I am bale to populate the column collection dynamically from the datasource. I would like to allow the user to remove or add any...
1
by: Karthik1979 | last post by:
I have a custom class inherited from List<T> collection. Along with the base class functionality, I have included my additional properties. When serializing, only the base class items are serialized...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.