<?xml version="1.0" encoding="utf-8"?> <HotelGeos> <HotelGeoList> <HotelGeo Country="中国" ProvinceName="北京" ProvinceId="0100" CityName="北京" CityCode="0101"> <Districts> <Location Id="0028" Name="昌平区" /> <Location Id="0003" Name="朝阳区" /> </Districts> <CommericalLocations> <Location Id="010186" Name="安贞" /> <Location Id="010120" Name="八大处风景区" /> </CommericalLocations> <LandmarkLocations> <Location Id="0005" Name="东方广场" /> <Location Id="0006" Name="中国国际展览中心" /> </LandmarkLocations> </HotelGeo> <HotelGeo Country="中国" ProvinceName="上海" ProvinceId="0200" CityName="上海" CityCode="0201"> <Districts> <Location Id="0022" Name="宝山" /> <Location Id="0004" Name="长宁" /> </Districts> <CommericalLocations> <Location Id="020103" Name="安亭" /> <Location Id="020105" Name="安亭国际汽车城" /> </CommericalLocations> <LandmarkLocations> <Location Id="0003" Name="光大国际会展中心" /> <Location Id="0005" Name="外滩" /> <Location Id="0006" Name="东方明珠" /> </LandmarkLocations> </HotelGeo> </HotelGeoList> </HotelGeos>
对应的Model
[XmlRoot("HotelGeos")] public class HotelGeos { [XmlElement("HotelGeoList")] public HotelGeoList HotelGeoList { get; set; } } public class HotelGeo { [XmlAttribute("Country")] public string Country { get; set; } [XmlAttribute("ProvinceName")] public string ProvinceName { get; set; } [XmlAttribute("ProvinceId")] public string ProvinceId { get; set; } [XmlAttribute("CityName")] public string CityName { get; set; } [XmlAttribute("CityCode")] public string CityCode { get; set; } [XmlArrayItem("Districts")] public List<District> Districts { get; set; } [XmlArrayItem("CommericalLocations")] public List<CommericalLocation> CommericalLocations { get; set; } [XmlArrayItem("LandmarkLocations")] public List<LandmarkLocation> LandmarkLocations { get; set; } } public class HotelGeoList { [XmlArrayItem("HotelGeo")] public List<HotelGeo> HotelGeo { get; set; } } public class District { [XmlAttribute("Id")] public int Id { get; set; } [XmlAttribute("Name")] public string Name { get; set; } } public class CommericalLocation { [XmlAttribute("Id")] public int Id { get; set; } [XmlAttribute("Name")] public string Name { get; set; } } public class LandmarkLocation { [XmlAttribute("Id")] public int Id { get; set; } [XmlAttribute("Name")] public string Name { get; set; } }
请问,为什么每次反序列化的时候都会提示“XML 文档(2, 2)中有错误”,错误详情为:{"不应有 <HotelGeos xmlns=''>。"}
但是我的xml中没有xmlns这个属性啊,我想应该是model的问题,但是又找不出来哪里有问题,请帮忙看下,感谢!
果然model写错了