I have an XML of the format like here: http://pastie.org/1311506 (not inserting it here because comment parser deletes tags).
This XML is serealized/deserialized using the following code:
[XmlRoot("products")]
public class Products
{
[XmlElement("label")]
public string Label { get; set; }
[XmlArray("cars")]
[XmlArrayItem("car")]
public Car[] Cars { get; set; }
}
public class Car
{
[XmlAttribute("name")]
public string Name { get; set; }
}
...
var products = new Products
{
Label = "1",
Cars = new[]
{
new Car {Name = "BMW"},
new Car {Name = "Volvo"}
}
};
var serializer = new XmlSerializer(typeof(Products));
var writer = new StringWriter();
serializer.Serialize(writer, products);
Console.WriteLine(writer);
I need an additional attribute to <cars>
node called type
(like here: http://pastie.org/1311514). How can I do it?
In other words, how to define data classes (Products and Car and maybe others if necessary) in order to parse XML of the format shown in the second pastie link?