我正在创建一个xml的产品源,它需要完全匹配客户端方案.
我正在使用web api.我希望属性extractDate是一个属性.以下代码输出extractDate作为元素而不是属性
public Feed GetProducts() { var Feed = new Feed() { extractDate = "extractDate",incremental = true,name = "name",Brands = GetBrands(),Categories = GetCategories(),Products = GetProducts() }; return Feed; }
[XmlAttribute(AttributeName = "extractDate")] public class Feed { [XmlAttribute(AttributeName = "extractDate")] //attribute is ignored public string extractDate { get; set; } public bool incremental { get; set; } public string name { get; set; } public List<Brand> Brands { get; set; } public List<Category> Categories { get; set; } public List<Product> Products { get; set; } }
我如何输出
<Feed extractDate="2012/01/01" // other logic />