我有這樣的格式的XML:http://pastie.org/1311506(不插入它在這裏,因爲評論分析器刪除標籤)。如何將屬性添加到標有XmlArrayAttribute的集合中?
[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);
我需要一個額外的屬性,稱爲type
(如這裏:http://pastie.org/1311514)<cars>
節點:
此XML serealized /使用以下代碼反序列化。我該怎麼做?
換句話說,如何定義數據類(產品和汽車,如果需要也可能是其他),以便解析第二個pastie鏈接中顯示的格式的XML?
「解析器刪除標籤」:不,如果你格式化爲代碼(按4個空格縮進或使用Ctrl + K) – 2010-11-19 19:08:32