views:

284

answers:

2

Let's say I have a class;

public class Car 
{ 
  public List<Pasenger> Passengers {get; set;} 
}

I want to serialize this to XML such that Passengers are child nodes of Car and there is no intervening Passengers node. In other words I want the output to look like this;

<Car>
  <Passenger>...</Passenger>
  <Passenger>...</Passenger>
</Car>

and not like this, which is the default layout;

<Car>   
  <Passengers>
    <Passenger>...</Passenger>
    <Passenger>...</Passenger>
  </Passengers> 
</Car>

There's an attribute I need to add to Car.Passengers to achieve this, I don't recall which though.

A: 

The index to maintain the order in which it was present in your original list?

dirkgently
+7  A: 

This is what I was after!

[XmlElement("Pasenger")]
public List<Pasenger> Passengers {get; set;}
Stuart Hallows