Advertisement
Guest User

Untitled

a guest
Feb 28th, 2015
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.17 KB | None | 0 0
  1.  //
  2.         //list that contain all the cities & their streets
  3.         //
  4.         List<city_details> list_of_cities = new List<city_details>();
  5.  
  6.         //
  7.         //index for the loop that adding the streets & the cities to the list
  8.         //
  9.         int index = 0;
  10.  
  11.         private void Form1_Load(object sender, EventArgs e)
  12.         {
  13.             //
  14.             //new xml object
  15.             //
  16.             XmlDocument xml = new XmlDocument();
  17.             xml.Load(@"rechov.xml");
  18.  
  19.             //
  20.             //
  21.             //
  22.             foreach (XmlNode node in xml.SelectNodes("ROWDATA/ROW"))
  23.             {
  24.  
  25.                 //
  26.                 //if the list is empty - add new city and new street, and ncrease the index in one.
  27.                 //
  28.                 if (list_of_cities.Count == 0)
  29.                 {
  30.                     list_of_cities.Add(new city_details(node.SelectSingleNode("city_name").InnerText, node.SelectSingleNode("street_name").InnerText));
  31.                     index++;
  32.                 }
  33.  
  34.                 //
  35.                 //if its not empty -
  36.                 //
  37.                 else
  38.                 {
  39.                     //
  40.                     //if this city and the previous city they not the same city
  41.                     //
  42.                     if ((node.SelectSingleNode("city_name").InnerText != list_of_cities[index - 1].city))
  43.                     {
  44.                         //
  45.                         // add a new city & a new stret, and increase the index in one
  46.                         //
  47.                         list_of_cities.Add(new city_details(node.SelectSingleNode("city_name").InnerText, node.SelectSingleNode("street_name").InnerText));
  48.                         index++;
  49.                     }
  50.                         //
  51.                         //if they same city
  52.                         //
  53.                     else
  54.                     {
  55.                         //
  56.                         //just add a new street
  57.                         //
  58.                         list_of_cities[index - 1].street.Add(node.SelectSingleNode("street_name").InnerText);
  59.                     }
  60.                 }
  61.  
  62.             }
  63.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement