-
Notifications
You must be signed in to change notification settings - Fork 164
/
MGTwitterSocialGraphParser.m
67 lines (53 loc) · 2.13 KB
/
MGTwitterSocialGraphParser.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//
// MGTwitterSocialGraphParser.m
// MGTwitterEngine
//
// Created by Robert McGovern on 2010/03/19.
// Copyright 2010 Tarasis. All rights reserved.
//
#import "MGTwitterSocialGraphParser.h"
#import "MGTwitterMiscParser.h"
@implementation MGTwitterSocialGraphParser
#pragma mark NSXMLParser delegate methods
- (void)parser:(NSXMLParser *)theParser didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName
attributes:(NSDictionary *)attributeDict
{
//NSLog(@"SG: Started element: %@ (%@)", elementName, attributeDict);
[self setLastOpenedElement:elementName];
if ([elementName isEqualToString:@"ids"]) {
twitterIDs = [NSMutableArray arrayWithCapacity:0];
NSMutableDictionary *newNode = [NSMutableDictionary dictionaryWithCapacity:0];
[parsedObjects addObject:newNode];
currentNode = newNode;
} else if (currentNode && ![elementName isEqualToString:@"id"]) {
// Create relevant name-value pair.
[currentNode setObject:[NSMutableString string] forKey:elementName];
}
}
- (void)parser:(NSXMLParser *)theParser foundCharacters:(NSString *)characters
{
//NSLog(@"SG: Found characters: %@", characters);
// Add the Twitter ID to the array
if ([lastOpenedElement isEqualToString:@"id"]) {
[twitterIDs addObject:characters];
// Append found characters to value of lastOpenedElement in currentNode.
} else if (lastOpenedElement && currentNode) {
[[currentNode objectForKey:lastOpenedElement] appendString:characters];
}
}
- (void)parser:(NSXMLParser *)theParser didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
//NSLog(@"SG: didEndElement: %@", elementName);
[super parser:theParser didEndElement:elementName namespaceURI:namespaceURI qualifiedName:qName];
// At the end of parsing, add the source type
if ([elementName isEqualToString:@"id_list"]) {
[self addSource];
currentNode = nil;
} else if ([elementName isEqualToString:@"ids"]) {
[currentNode setObject:twitterIDs forKey:elementName];
currentNode = [parsedObjects lastObject];
}
}
@end