/// <summary> /// 解析XML节点 /// </summary> /// <param name="provinceNodeList">provinceNodeList</param> /// <returns>结果</returns> private static Dictionary <string, Area> LoadProvinces(XmlNodeList provinceNodeList) { Dictionary <string, Area> result = new Dictionary <string, Area>(); foreach (XmlNode provinceNode in provinceNodeList) { string code = GetAttribute(provinceNode, "code"); string name = GetAttribute(provinceNode, "name"); Area province = new Area(code, name, null); var cities = LoadCities(province, provinceNode.ChildNodes); foreach (var city in cities) { province.AppendChild(city); } result.Add(code, province); } return(result); }
/// <summary> /// 加载城市 /// </summary> /// <param name="province">省</param> /// <param name="cityNodeList">节点</param> /// <returns>结果</returns> private static IEnumerable <Area> LoadCities(Area province, XmlNodeList cityNodeList) { List <Area> result = new List <Area>(); if (cityNodeList != null) { foreach (XmlNode cityNode in cityNodeList) { string code = GetAttribute(cityNode, "code"); string name = GetAttribute(cityNode, "name"); Area city = new Area(code, name, province); var counties = loadCounties(city, cityNode.ChildNodes); foreach (var county in counties) { city.AppendChild(county); } result.Add(city); } } return(result); }
/// <summary> /// 解析XML节点 /// </summary> /// <param name="provinceNodeList">provinceNodeList</param> /// <returns>结果</returns> private static Dictionary<string, Area> LoadProvinces(XmlNodeList provinceNodeList) { Dictionary<string, Area> result = new Dictionary<string, Area>(); foreach (XmlNode provinceNode in provinceNodeList) { string code = GetAttribute(provinceNode, "code"); string name = GetAttribute(provinceNode, "name"); Area province = new Area(code, name, null); var cities = LoadCities(province, provinceNode.ChildNodes); foreach (var city in cities) { province.AppendChild(city); } result.Add(code, province); } return result; }
/// <summary> /// 加载城市 /// </summary> /// <param name="province">省</param> /// <param name="cityNodeList">节点</param> /// <returns>结果</returns> private static IEnumerable<Area> LoadCities(Area province, XmlNodeList cityNodeList) { List<Area> result = new List<Area>(); if (cityNodeList != null) { foreach (XmlNode cityNode in cityNodeList) { string code = GetAttribute(cityNode, "code"); string name = GetAttribute(cityNode, "name"); Area city = new Area(code, name, province); var counties = loadCounties(city, cityNode.ChildNodes); foreach (var county in counties) { city.AppendChild(county); } result.Add(city); } } return result; }