Advertisement
TankorSmash

parse fixedapi.nfpox C#

Feb 18th, 2013
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.79 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Xml;
  5.  
  6. namespace fixedAPI_parser
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.  
  13.             List<Tuple<int, string>> genre_ids_strings = new List<Tuple<int, string>>();
  14.  
  15.             using (XmlReader xmlReader = XmlReader.Create(@"c:/fixedapi.nfpox"))
  16.             {
  17.                 while (xmlReader.Read())
  18.                 {
  19.                     if ((xmlReader.NodeType == XmlNodeType.Element) && (xmlReader.Name == "category"))
  20.                     {
  21.  
  22.                         string possible_genre_url =
  23.                             xmlReader.GetAttribute("scheme");
  24.  
  25.                         if (possible_genre_url.Contains("genres"))
  26.                         {
  27.                             //gotta split url for the id
  28.                             int genre_id =
  29.                                 Convert.ToInt32(possible_genre_url.Split('/').Last());
  30.                             string genre_string = xmlReader.GetAttribute("label");
  31.                             //so long as the group isn't in the list, add it it
  32.                             if (
  33.                                 genre_ids_strings.All(item => item.Item1 != genre_id))
  34.                             {
  35.  
  36.                                 genre_ids_strings.Add(
  37.                                     new Tuple<int, string>(genre_id,
  38.                                                            genre_string));
  39.  
  40.                                 //Console.WriteLine("added id {0}", genre_id);
  41.                             }
  42.                         }
  43.                     }
  44.                 }
  45.             }
  46.  
  47.             Console.WriteLine("Done, found {0}", genre_ids_strings.Count);
  48.             Console.ReadLine();
  49.  
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement