Ejemplo n.º 1
0
 /// <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;
 }
Ejemplo n.º 2
0
 /// <summary>
 /// 加载区域
 /// </summary>
 /// <param name="city">市</param>
 /// <param name="countyNodeList">节点</param>
 /// <returns>结果</returns>
 private static IEnumerable<Area> loadCounties(Area city, XmlNodeList countyNodeList)
 {
     List<Area> result = new List<Area>();
     if (countyNodeList != null)
     {
         foreach (XmlNode countyNode in countyNodeList)
         {
             string code = GetAttribute(countyNode, "code");
             string name = GetAttribute(countyNode, "name");
             Area county = new Area(code, name, city);
             result.Add(county);
         }
     }
     return result;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// 添加子区域
 /// </summary>
 /// <param name="child">子节点</param>
 internal void AppendChild(Area child)
 {
     if (!this.childrenDic.ContainsKey(child.Info.Code))
     {
         this.childrenDic.Add(child.Info.Code, child);
         this.childrenList.Add(child);
     }
 }
Ejemplo n.º 4
0
 /// <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;
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Area"/> class. 
 /// </summary>
 /// <param name="code">代码</param>
 /// <param name="name">名称</param>
 /// <param name="parent">父区域</param>
 internal Area(string code, string name, Area parent)
 {
     this.Info = new CodeNameMapping(code, name);
     this.Parent = parent;
     this.childrenDic = new Dictionary<string, Area>();
     this.childrenList = new List<Area>();
 }