473,511 Members | 16,849 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with collection classes

Hi,

how do I synchronize (to XML using XmlSerializer) something to this:
<Alignments name="Road Project">
<Alignment name="Centerline">
<CoordGeom>
<Line staStart="0">
<Start>2000 6000</Start>
<End>2186.841 6068.005</End>
</Line>
<Curve rot="cw" />
... arbitrary number of Line's and Curve's
... in arbitrary order
</CoordGeom>
... arbitrary number of CoordGeom's ...
</Alignment>
.... arbitrary number of Alignment's ...
</Alignments>

What troubles me is how to deal with the array of CoordGeom's, which are
generic arrays in the sense that they can contain either a Line or a Curve,
and any number of them.

I am using CS and have an array for each type as of now, i.e. one array for
Curve's and one for Line's. But this does not allow me to mix the order in
which they occur, so the Curve and Line elements have to be in the same
ArrayList.

I want to know how to structure my classes and what to make XmlArray of.
Any tips you can give me is much appreciated, thank you.

--
Daniel
Nov 12 '05 #1
6 2112
No answer...

Let me describe what I am doing. I've created these classes:
[XmlInclude(typeof(Car))]
[XmlInclude(typeof(Motorcycle))]
public class Vehicle
{
public Vehicle() {}
public string Make;
public string Model;
public int Year;
}
public class Car : Vehicle
{
public Car() {}
public string VIN;
}
public class Motorcycle : Vehicle
{
public Motorcycle() {}
}
public class ParkingLot
{
public ParkingLot()
{
ParkedVehicles = new ArrayList();
ParkedVehicles.Add(new Car());
ParkedVehicles.Add(new Motorcycle());
}
[XmlElement(ElementName="ParkedCar",Type=typeof(Car ))]
[XmlElement(ElementName="ParkedMotorcycle",Type=typ eof(Motorcycle))]
public ArrayList ParkedVehicles;
}

Serializing a ParkingLot creates this (which is just what I want):
<?xml version="1.0" encoding="utf-8"?>
<ParkingLot xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ParkedCar>
<Year>0</Year>
</ParkedCar>
<ParkedMotorcycle>
<Year>0</Year>
</ParkedMotorcycle>
</ParkingLot>

As you can see there is no parent element around parked car and parked
motorcycle, i.e. no ParkedVehicles element.

Now, I would like to have a collection of ParkingLot's inside another
class. So I add this:
public ArrayList ParkingLotCollection;
to my other class. Trying to serialize produces an exception:
Message: The type LX.ParkingLot was not expected. Use the XmlInclude or
SoapInclude attribute to specify types that are not known statically.

So I rewrite it like this:

[XmlArrayItem(Type=typeof(ParkingLot))]
public ArrayList ParkingLotCollection;

But this creates a parent element around my ParkingLot's, like this:
<ParkingLotCollection>
<ParkingLot>
<ParkedCar>
<Year>0</Year>
</ParkedCar>
<ParkedMotorcycle>
<Year>0</Year>
</ParkedMotorcycle>
</ParkingLot>
</ParkingLotCollection>

From what I've read I should be able to remove this parent element by
adding a empty XmlElement attribute to my ArrayList ParkingLotCollection:

[XmlArrayItem(Type=typeof(ParkingLot))]
[XmlElement]
public ArrayList ParkingLotCollection;

But this causes an exception:
Message: There was an error reflecting field 'ParkingLotCollection'.
I have no idea what to do. What am I doing wrong? Any information is very
much appreciated. Thanks.

--
Daniel
Nov 12 '05 #2
No answer...

Let me describe what I am doing. I've created these classes:
[XmlInclude(typeof(Car))]
[XmlInclude(typeof(Motorcycle))]
public class Vehicle
{
public Vehicle() {}
public string Make;
public string Model;
public int Year;
}
public class Car : Vehicle
{
public Car() {}
public string VIN;
}
public class Motorcycle : Vehicle
{
public Motorcycle() {}
}
public class ParkingLot
{
public ParkingLot()
{
ParkedVehicles = new ArrayList();
ParkedVehicles.Add(new Car());
ParkedVehicles.Add(new Motorcycle());
}
[XmlElement(ElementName="ParkedCar",Type=typeof(Car ))]
[XmlElement(ElementName="ParkedMotorcycle",Type=typ eof(Motorcycle))]
public ArrayList ParkedVehicles;
}

Serializing a ParkingLot creates this (which is just what I want):
<?xml version="1.0" encoding="utf-8"?>
<ParkingLot xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ParkedCar>
<Year>0</Year>
</ParkedCar>
<ParkedMotorcycle>
<Year>0</Year>
</ParkedMotorcycle>
</ParkingLot>

As you can see there is no parent element around parked car and parked
motorcycle, i.e. no ParkedVehicles element.

Now, I would like to have a collection of ParkingLot's inside another
class. So I add this:
public ArrayList ParkingLotCollection;
to my other class. Trying to serialize produces an exception:
Message: The type LX.ParkingLot was not expected. Use the XmlInclude or
SoapInclude attribute to specify types that are not known statically.

So I rewrite it like this:

[XmlArrayItem(Type=typeof(ParkingLot))]
public ArrayList ParkingLotCollection;

But this creates a parent element around my ParkingLot's, like this:
<ParkingLotCollection>
<ParkingLot>
<ParkedCar>
<Year>0</Year>
</ParkedCar>
<ParkedMotorcycle>
<Year>0</Year>
</ParkedMotorcycle>
</ParkingLot>
</ParkingLotCollection>

From what I've read I should be able to remove this parent element by
adding a empty XmlElement attribute to my ArrayList ParkingLotCollection:

[XmlArrayItem(Type=typeof(ParkingLot))]
[XmlElement]
public ArrayList ParkingLotCollection;

But this causes an exception:
Message: There was an error reflecting field 'ParkingLotCollection'.
I have no idea what to do. What am I doing wrong? Any information is very
much appreciated. Thanks.

--
Daniel
Nov 12 '05 #3
I don't understand.
If a class contains a ParkingLotCollection (a Mall?) , then shouldn't each
Lot in the collection be serialized independently?

<Mall>
<Lot>
<ParkedCar>
<Make>Ijbnxnwhna</Make>
<Year>1995</Year>
<Color>red</Color>
<VIN>582949646792293965529740</VIN>
</ParkedCar>
<ParkedMotorcycle>
<Make>Ggikttsgpp</Make>
<Year>1985</Year>
<Color>red</Color>
</ParkedMotorcycle>
</Lot>
<Lot>
<ParkedMotorcycle>
<Make>Dpdiqdccez</Make>
<Year>1986</Year>
<Color>green</Color>
</ParkedMotorcycle>
<ParkedCar>
<Make>Gbulediyje</Make>
<Year>1998</Year>
<Color>blue</Color>
<VIN>331456735041360460902400</VIN>
</ParkedCar>
</Lot>
</Mall>
What would you like to see happen?
By the way, the extra layer of structure isn't contributing anything to the
issue.
Suppose you had a Lot like this:

<ParkingLot>
<ParkedCar>
<Make>Dgvpadixcx</Make>
<Year>1998</Year>
<Color>blue</Color>
<VIN>045509407786350954614071</VIN>
</ParkedCar>
<ParkedMotorcycle>
<Make>Htvlwawaua</Make>
<Year>1985</Year>
<Color>blue</Color>
</ParkedMotorcycle>
</ParkingLot>
What you seem to want is to serialize the collection (in the Lot's case, it
is a collection of vehicles) without specifically identifying each vehicle.
Maybe like so:
<ParkingLot>
<Make>Dgvpadixcx</Make>
<Year>1998</Year>
<Color>blue</Color>
<VIN>045509407786350954614071</VIN>
<Make>Htvlwawaua</Make>
<Year>1985</Year>
<Color>blue</Color>
</ParkingLot>
What does that get you?

-D

"Daniel Lidström" <so*****@microsoft.com> wrote in message
news:1h****************************@40tude.net...
No answer...

Let me describe what I am doing. I've created these classes:
[XmlInclude(typeof(Car))]
[XmlInclude(typeof(Motorcycle))]
public class Vehicle
{
public Vehicle() {}
public string Make;
public string Model;
public int Year;
}
public class Car : Vehicle
{
public Car() {}
public string VIN;
}
public class Motorcycle : Vehicle
{
public Motorcycle() {}
}
public class ParkingLot
{
public ParkingLot()
{
ParkedVehicles = new ArrayList();
ParkedVehicles.Add(new Car());
ParkedVehicles.Add(new Motorcycle());
}
[XmlElement(ElementName="ParkedCar",Type=typeof(Car ))]
[XmlElement(ElementName="ParkedMotorcycle",Type=typ eof(Motorcycle))]
public ArrayList ParkedVehicles;
}

Serializing a ParkingLot creates this (which is just what I want):
<?xml version="1.0" encoding="utf-8"?>
<ParkingLot xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ParkedCar>
<Year>0</Year>
</ParkedCar>
<ParkedMotorcycle>
<Year>0</Year>
</ParkedMotorcycle>
</ParkingLot>

As you can see there is no parent element around parked car and parked
motorcycle, i.e. no ParkedVehicles element.

Now, I would like to have a collection of ParkingLot's inside another
class. So I add this:
public ArrayList ParkingLotCollection;
to my other class. Trying to serialize produces an exception:
Message: The type LX.ParkingLot was not expected. Use the XmlInclude or
SoapInclude attribute to specify types that are not known statically.

So I rewrite it like this:

[XmlArrayItem(Type=typeof(ParkingLot))]
public ArrayList ParkingLotCollection;

But this creates a parent element around my ParkingLot's, like this:
<ParkingLotCollection>
<ParkingLot>
<ParkedCar>
<Year>0</Year>
</ParkedCar>
<ParkedMotorcycle>
<Year>0</Year>
</ParkedMotorcycle>
</ParkingLot>
</ParkingLotCollection>

From what I've read I should be able to remove this parent element by
adding a empty XmlElement attribute to my ArrayList ParkingLotCollection:

[XmlArrayItem(Type=typeof(ParkingLot))]
[XmlElement]
public ArrayList ParkingLotCollection;

But this causes an exception:
Message: There was an error reflecting field 'ParkingLotCollection'.
I have no idea what to do. What am I doing wrong? Any information is very
much appreciated. Thanks.

--
Daniel

Nov 12 '05 #4
I don't understand.
If a class contains a ParkingLotCollection (a Mall?) , then shouldn't each
Lot in the collection be serialized independently?

<Mall>
<Lot>
<ParkedCar>
<Make>Ijbnxnwhna</Make>
<Year>1995</Year>
<Color>red</Color>
<VIN>582949646792293965529740</VIN>
</ParkedCar>
<ParkedMotorcycle>
<Make>Ggikttsgpp</Make>
<Year>1985</Year>
<Color>red</Color>
</ParkedMotorcycle>
</Lot>
<Lot>
<ParkedMotorcycle>
<Make>Dpdiqdccez</Make>
<Year>1986</Year>
<Color>green</Color>
</ParkedMotorcycle>
<ParkedCar>
<Make>Gbulediyje</Make>
<Year>1998</Year>
<Color>blue</Color>
<VIN>331456735041360460902400</VIN>
</ParkedCar>
</Lot>
</Mall>
What would you like to see happen?
By the way, the extra layer of structure isn't contributing anything to the
issue.
Suppose you had a Lot like this:

<ParkingLot>
<ParkedCar>
<Make>Dgvpadixcx</Make>
<Year>1998</Year>
<Color>blue</Color>
<VIN>045509407786350954614071</VIN>
</ParkedCar>
<ParkedMotorcycle>
<Make>Htvlwawaua</Make>
<Year>1985</Year>
<Color>blue</Color>
</ParkedMotorcycle>
</ParkingLot>
What you seem to want is to serialize the collection (in the Lot's case, it
is a collection of vehicles) without specifically identifying each vehicle.
Maybe like so:
<ParkingLot>
<Make>Dgvpadixcx</Make>
<Year>1998</Year>
<Color>blue</Color>
<VIN>045509407786350954614071</VIN>
<Make>Htvlwawaua</Make>
<Year>1985</Year>
<Color>blue</Color>
</ParkingLot>
What does that get you?

-D

"Daniel Lidström" <so*****@microsoft.com> wrote in message
news:1h****************************@40tude.net...
No answer...

Let me describe what I am doing. I've created these classes:
[XmlInclude(typeof(Car))]
[XmlInclude(typeof(Motorcycle))]
public class Vehicle
{
public Vehicle() {}
public string Make;
public string Model;
public int Year;
}
public class Car : Vehicle
{
public Car() {}
public string VIN;
}
public class Motorcycle : Vehicle
{
public Motorcycle() {}
}
public class ParkingLot
{
public ParkingLot()
{
ParkedVehicles = new ArrayList();
ParkedVehicles.Add(new Car());
ParkedVehicles.Add(new Motorcycle());
}
[XmlElement(ElementName="ParkedCar",Type=typeof(Car ))]
[XmlElement(ElementName="ParkedMotorcycle",Type=typ eof(Motorcycle))]
public ArrayList ParkedVehicles;
}

Serializing a ParkingLot creates this (which is just what I want):
<?xml version="1.0" encoding="utf-8"?>
<ParkingLot xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ParkedCar>
<Year>0</Year>
</ParkedCar>
<ParkedMotorcycle>
<Year>0</Year>
</ParkedMotorcycle>
</ParkingLot>

As you can see there is no parent element around parked car and parked
motorcycle, i.e. no ParkedVehicles element.

Now, I would like to have a collection of ParkingLot's inside another
class. So I add this:
public ArrayList ParkingLotCollection;
to my other class. Trying to serialize produces an exception:
Message: The type LX.ParkingLot was not expected. Use the XmlInclude or
SoapInclude attribute to specify types that are not known statically.

So I rewrite it like this:

[XmlArrayItem(Type=typeof(ParkingLot))]
public ArrayList ParkingLotCollection;

But this creates a parent element around my ParkingLot's, like this:
<ParkingLotCollection>
<ParkingLot>
<ParkedCar>
<Year>0</Year>
</ParkedCar>
<ParkedMotorcycle>
<Year>0</Year>
</ParkedMotorcycle>
</ParkingLot>
</ParkingLotCollection>

From what I've read I should be able to remove this parent element by
adding a empty XmlElement attribute to my ArrayList ParkingLotCollection:

[XmlArrayItem(Type=typeof(ParkingLot))]
[XmlElement]
public ArrayList ParkingLotCollection;

But this causes an exception:
Message: There was an error reflecting field 'ParkingLotCollection'.
I have no idea what to do. What am I doing wrong? Any information is very
much appreciated. Thanks.

--
Daniel

Nov 12 '05 #5
On Fri, 25 Jun 2004 14:12:25 -0400, Dino Chiesa [Microsoft] wrote:
I don't understand.
If a class contains a ParkingLotCollection (a Mall?) , then shouldn't each
Lot in the collection be serialized independently?

<Mall>
<Lot>
<ParkedCar>
<Make>Ijbnxnwhna</Make>
<Year>1995</Year>
<Color>red</Color>
<VIN>582949646792293965529740</VIN>
</ParkedCar>
<ParkedMotorcycle>
<Make>Ggikttsgpp</Make>
<Year>1985</Year>
<Color>red</Color>
</ParkedMotorcycle>
</Lot>
<Lot>
<ParkedMotorcycle>
<Make>Dpdiqdccez</Make>
<Year>1986</Year>
<Color>green</Color>
</ParkedMotorcycle>
<ParkedCar>
<Make>Gbulediyje</Make>
<Year>1998</Year>
<Color>blue</Color>
<VIN>331456735041360460902400</VIN>
</ParkedCar>
</Lot>
</Mall>
What would you like to see happen?


That is what I would like to have. Only that I would like to be able to
have more than one Mall.

Maybe I should have told you right away what I really want. I want to
serialize the following (well, a subset actually):
http://landxml.org/schema/landxml-1....LandXMLDoc.htm

I'm having a lot of trouble with the Alignment and Alignments elements in
the LandXML element. There is a sample file here:

http://www.landxml.org/schema/LandXM...20Profiles.xml

If you have a look at it, you will see that it is possible to have several
Alignments' within the LandXML element, and within each Alignments it
should be possible to have several Alignment's, although this sample only
has one. This sample shows several Alignment's within each Alignments:
http://www.landxml.org/schema/LandXM...k/hidden_m.xml

The LandXML specification says something like this:
LandXML can contain 1-oo (oo == infinite) number of Alignments. Alignments
can contain 1-oo number of Alignment's. Alignment's are collections of
CoordGeoms, which can contain Line's, Curve's, or Spiral's (in a specific
order!).

Dino, do you know how I can serialize this? You can use the parkinglot
example if you'd like. I hope I have understood LandXML the right way. If
so, it should be equivalent to the parkinglot at the top of this message,
with the possibility to have 1-oo Mall's.

Thank you!

--
Daniel
Nov 12 '05 #6
On Fri, 25 Jun 2004 14:12:25 -0400, Dino Chiesa [Microsoft] wrote:
I don't understand.
If a class contains a ParkingLotCollection (a Mall?) , then shouldn't each
Lot in the collection be serialized independently?

<Mall>
<Lot>
<ParkedCar>
<Make>Ijbnxnwhna</Make>
<Year>1995</Year>
<Color>red</Color>
<VIN>582949646792293965529740</VIN>
</ParkedCar>
<ParkedMotorcycle>
<Make>Ggikttsgpp</Make>
<Year>1985</Year>
<Color>red</Color>
</ParkedMotorcycle>
</Lot>
<Lot>
<ParkedMotorcycle>
<Make>Dpdiqdccez</Make>
<Year>1986</Year>
<Color>green</Color>
</ParkedMotorcycle>
<ParkedCar>
<Make>Gbulediyje</Make>
<Year>1998</Year>
<Color>blue</Color>
<VIN>331456735041360460902400</VIN>
</ParkedCar>
</Lot>
</Mall>
What would you like to see happen?


That is what I would like to have. Only that I would like to be able to
have more than one Mall.

Maybe I should have told you right away what I really want. I want to
serialize the following (well, a subset actually):
http://landxml.org/schema/landxml-1....LandXMLDoc.htm

I'm having a lot of trouble with the Alignment and Alignments elements in
the LandXML element. There is a sample file here:

http://www.landxml.org/schema/LandXM...20Profiles.xml

If you have a look at it, you will see that it is possible to have several
Alignments' within the LandXML element, and within each Alignments it
should be possible to have several Alignment's, although this sample only
has one. This sample shows several Alignment's within each Alignments:
http://www.landxml.org/schema/LandXM...k/hidden_m.xml

The LandXML specification says something like this:
LandXML can contain 1-oo (oo == infinite) number of Alignments. Alignments
can contain 1-oo number of Alignment's. Alignment's are collections of
CoordGeoms, which can contain Line's, Curve's, or Spiral's (in a specific
order!).

Dino, do you know how I can serialize this? You can use the parkinglot
example if you'd like. I hope I have understood LandXML the right way. If
so, it should be equivalent to the parkinglot at the top of this message,
with the possibility to have 1-oo Mall's.

Thank you!

--
Daniel
Nov 12 '05 #7

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

Similar topics

1
3318
by: CodeMonkey | last post by:
Hi, I am trying to use xml serialization to simplify load/save functions in some classes i have created and am hitting a few problems. Any help to either would be most appreciated. I have...
1
6428
by: Terry | last post by:
I created a collection derived from CollectionBase that is just made up of strings, called "StringList". I have another object that has as a member one of these StringList. If I assign that...
2
2498
by: Edward Diener | last post by:
In C++ an overridden virtual function in a derived class must have the exact same signature of the function which is overridden in the base class, except for the return type which may return a...
7
2900
by: jsale | last post by:
I'm currently using ASP.NET with VS2003 and SQL Server 2003. The ASP.NET app i have made is running on IIS v6 and consists of a number of pages that allow the user to read information from the...
11
1670
by: EDom | last post by:
Hi, I have aspnet_wp.exe with increasing on every postback and not every revisit to any page. Even if I clear session and close the browser it remains in the memory. I have only one connection...
7
1780
by: Joe | last post by:
I've tracked the performance issue down to a single class. This class derives from CollectionBase and stores a basic value type such as string, int, double, etc... I also store the type itself...
19
4891
by: Jamey Shuemaker | last post by:
I'm in the process of expanding my knowledge and use of Class Modules. I've perused MSDN and this and other sites, and I'm pretty comfortable with my understanding of Class Modules with the...
3
1596
by: Kaba | last post by:
Hello I have a design problem, which I don't seem to have a good solution. By example: class B; class C; class D {
7
5733
by: =?Utf-8?B?Q29kZVJhem9y?= | last post by:
Can someone explain a few things about collections to me. In C# 2 generics, you can create a collection class by inheriting from System.Collections.ObjectModel.Collection. Using this you can...
0
7138
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
7355
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
5668
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,...
1
5066
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
4737
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
3225
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
3213
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1576
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
447
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.