/GovHack/Parsers/GHIndustriesParser.m

https://bitbucket.org/devilscurls/govhack · Objective C · 105 lines · 78 code · 16 blank · 11 comment · 6 complexity · cdf9031a333ec1304e5e615e3198f8f6 MD5 · raw file

  1. //
  2. // GHProvidersParser.m
  3. // GovHack
  4. //
  5. // Created by Luke Scholefield on 1/06/13.
  6. // Copyright (c) 2013 Luke Scholefield. All rights reserved.
  7. //
  8. #import "GHIndustriesParser.h"
  9. @implementation GHIndustriesParser
  10. - (NSArray *)parse
  11. {
  12. self.desiredIndustries = @[
  13. // @"Mathematical Sciences",
  14. // @"Physics And Astronomy",
  15. @"Chemical Sciences",
  16. @"Earth Sciences",
  17. @"Other Natural And Physical Sciences",
  18. @"Information Systems",
  19. @"Other Information Technology",
  20. // @"Manufacturing Engineering And Technology",
  21. @"Process And Resources Engineering",
  22. @"Automotive Engineering And Technology",
  23. @"Mechanical And Industrial Engineering And Technology",
  24. @"Civil Engineering",
  25. @"Geomatic Engineering",
  26. @"Electrical And Electronic Engineering And Technology",
  27. @"Other Engineering And Related Technologies",
  28. @"Architecture And Urban Environment",
  29. @"Building",
  30. @"Environmental Studies",
  31. @"Other Agriculture, Environmental And Related Studies",
  32. @"Accounting",
  33. @"Business And Management",
  34. @"Banking, Finance And Related Fields",
  35. @"Other Management And Commerce",
  36. @"Economics And Econometrics",
  37. // @"Food And Hospitality",
  38. @"Personal Services",
  39. @"Employment Skills Programmes",
  40. @"Other Mixed Field Programmes"
  41. ];
  42. self.industries = [NSMutableArray array];
  43. NSString* path = [[NSBundle mainBundle] pathForResource:@"Industries" ofType:@"xml"];
  44. NSData *xmlData = [[NSMutableData alloc] initWithContentsOfFile:path];
  45. NSXMLParser *parser = [[NSXMLParser alloc] initWithData:xmlData];
  46. parser.delegate = self;
  47. [parser parse];
  48. return self.industries;
  49. }
  50. -(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
  51. {
  52. if ([elementName isEqualToString:@"Industry"])
  53. {
  54. self.currentIndustry = [[GHIndustry alloc] init];
  55. }
  56. else
  57. {
  58. self.currentElement = elementName;
  59. }
  60. }
  61. - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
  62. if ([self.currentElement isEqualToString:@"IndustryName"])
  63. {
  64. if ([self.desiredIndustries containsObject:string])
  65. {
  66. self.currentIndustry.name = string;
  67. }
  68. else
  69. {
  70. self.currentIndustry = nil;
  71. }
  72. }
  73. if ([self.currentElement isEqualToString:@"IndustryValue"])
  74. {
  75. self.currentIndustry.value = string;
  76. }
  77. }
  78. -(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
  79. {
  80. if ([elementName isEqualToString:@"Industry"])
  81. {
  82. if (self.currentIndustry)
  83. {
  84. [self.industries addObject:self.currentIndustry];
  85. }
  86. self.currentIndustry = nil;
  87. }
  88. }
  89. @end