473,320 Members | 2,124 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 752

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: 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...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.