首页 新闻 搜索 专区 学院

关于 XML 反序列化

0
悬赏园豆:5 [已关闭问题] 关闭于 2014-04-14 01:33
<?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>
XML

对应的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; }

    }
View Code

 

请问,为什么每次反序列化的时候都会提示“XML 文档(2, 2)中有错误”,错误详情为:{"不应有 <HotelGeos xmlns=''>。"}

但是我的xml中没有xmlns这个属性啊,我想应该是model的问题,但是又找不出来哪里有问题,请帮忙看下,感谢!

然后、没所以的主页 然后、没所以 | 初学一级 | 园豆:5
提问于:2014-04-13 08:24
< >
分享
所有回答(1)
0

果然model写错了

然后、没所以 | 园豆:5 (初学一级) | 2014-04-14 01:33
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册