0
我想XML與元素atrribute自定義名稱,我聲明瞭名稱如下圖所示如何在序列化時重命名xml元素屬性?
[XmlRoot(ElementName = "country")]
public class CountryInRegion
{
[XmlElement(ElementName = "iso_code")]
public string IsoCode { get; set; }
[XmlElement(ElementName = "name")]
public string Name { get; set; }
[XmlElement(ElementName = "region_id")]
public string RegionId { get; set; }
}
[XmlRoot(ElementName = "countries")]
public class Countries
{
[XmlArray(ElementName = "country")]
public IList<CountryInRegion> countries { get; set; }
public Countries()
{
countries = new List<CountryInRegion>();
}
}
,我得到這樣
<Countries>
<countries>
<CountryInRegion>
<IsoCode>AD</IsoCode>
<Name>Andorra</Name>
<RegionId>EUROPE</RegionId></CountryInRegion>
</CountryInRegion>
</countries>
</Countries>
輸出我試圖[的XmlElement(「名稱「)]但沒有獲得任何更改