Advertisement
Guest User

Untitled

a guest
Dec 5th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.58 KB | None | 0 0
  1. static void XmlTest()
  2. {
  3.         Stopwatch sw = new Stopwatch();
  4.         string XmlFilePath = "TOROKORSZAG39.xml";
  5.         Console.WriteLine("Nyomjunk egy billentyűt a kezdéshez!" + Environment.NewLine + "Beolvasandó fájl: " + XmlFilePath);
  6.         Console.ReadKey();
  7.  
  8.         Dictionary<string, List<string>> travel_data = new Dictionary<string, List<string>>();
  9.  
  10.         sw.Start();
  11.        
  12.         string id = "";
  13.         using (XmlReader xmlReader = XmlReader.Create(XmlFilePath))
  14.         {
  15.                 while (xmlReader.Read())                                
  16.                 {
  17.  
  18.                         if (xmlReader.Name == "code")
  19.                         {
  20.                                 id = (XNode.ReadFrom(xmlReader) as XElement).Value;
  21.                                 travel_data.Add(id, new List<string>());
  22.                         }
  23.                         /*if (xmlReader.Name == "name")
  24.                         {
  25.                                 XElement item = XNode.ReadFrom(xmlReader) as XElement;
  26.                                 Console.WriteLine(id + " :: " + item.Value);
  27.  
  28.                         }*/
  29.  
  30.                         if (id != "" && (xmlReader.Name == "name" || xmlReader.Name == "id" || xmlReader.Name == "code" || xmlReader.Name == "region"))
  31.                         {
  32.                                 travel_data[id].Add(xmlReader.Value);
  33.                         }
  34.                 }
  35.         }
  36.         sw.Stop();
  37.         Console.WriteLine("=== Kész! " + String.Format("{0:00}:{1:00}:{2:00}.{3:00}", sw.Elapsed.Hours, sw.Elapsed.Minutes, sw.Elapsed.Seconds, sw.Elapsed.Milliseconds/10) + " ===");
  38.  
  39.         foreach(KeyValuePair<string,List<string>> item in travel_data)
  40.         {
  41.                 List<string> data = item.Value;
  42.                 Console.WriteLine(item.Key);                                
  43.                 foreach (string datavalue in data)
  44.                 {
  45.                         Console.WriteLine(datavalue.ToString());
  46.                 }
  47.                 Console.WriteLine("=====");
  48.         }                        
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement