Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 100 lines (83 sloc) 2.885 kB
e744c0b @tarasis Added a LibXML parser for the Social Graph API requests (friends/ids …
tarasis authored
1 //
2 // MGTwitterSocialGraphLibXMLParser.m
3 // MGTwitterEngine
4 //
5 // Created by Robert McGovern on 2010/03/20.
6 // Copyright 2010 Tarasis. All rights reserved.
7 //
8
9 #import "MGTwitterSocialGraphLibXMLParser.h"
10
11
12 @implementation MGTwitterSocialGraphLibXMLParser
13 - (void)parse
14 {
15 int readerResult = xmlTextReaderRead(_reader);
16 if (readerResult != 1)
17 return;
18
19 int nodeType = xmlTextReaderNodeType(_reader);
20 const xmlChar *name = xmlTextReaderConstName(_reader);
21
22 NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
23
24 while (! (nodeType == XML_READER_TYPE_END_ELEMENT))
25 {
26 //NSLog(@"name is: %@", [NSString stringWithUTF8String:(const char *)name]);
27 if (nodeType == XML_READER_TYPE_ELEMENT)
28 {
29 if (xmlStrEqual(name, BAD_CAST "ids"))
30 {
31 [dictionary addEntriesFromDictionary:[self _socialGraphDictionaryForNodeWithName:name]];
32 }
33 else if (xmlStrEqual(BAD_CAST "previous_cursor", name) || xmlStrEqual(BAD_CAST "next_cursor", name))
34 {
35 // process element as a string -- API calls like friendships/exists.xml just return <friends>false</friends> or <friends>true</friends>
36 NSString *string = [self _nodeValueAsString];
37 if (string)
38 {
39 [dictionary setObject:string forKey:[NSString stringWithUTF8String:(const char *)name]];
40 }
41 }
42
43 }
44
45 // advance reader
f70adf5 @richardbuckle Eliminated vars w/ same name in inner scope.
richardbuckle authored
46 readerResult = xmlTextReaderRead(_reader);
e744c0b @tarasis Added a LibXML parser for the Social Graph API requests (friends/ids …
tarasis authored
47 if (readerResult != 1)
48 {
49 break;
50 }
51 nodeType = xmlTextReaderNodeType(_reader);
52 name = xmlTextReaderConstName(_reader);
53 }
54
55 [dictionary setObject:[NSNumber numberWithInt:requestType] forKey:TWITTER_SOURCE_REQUEST_TYPE];
56 [parsedObjects addObject:dictionary];
57 }
58
59 - (NSDictionary *)_socialGraphDictionaryForNodeWithName:(const xmlChar *)parentNodeName
60 {
61 if (xmlTextReaderIsEmptyElement(_reader))
62 return nil;
63 NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
64 twitterIDs = [NSMutableArray arrayWithCapacity:0];
65
66 int readerResult = xmlTextReaderRead(_reader);
67 if (readerResult != 1)
68 return nil;
69 int nodeType = xmlTextReaderNodeType(_reader);
70 const xmlChar *name = xmlTextReaderConstName(_reader);
71 while (! (nodeType == XML_READER_TYPE_END_ELEMENT && xmlStrEqual(parentNodeName, name)))
72 {
73 if (nodeType == XML_READER_TYPE_ELEMENT)
74 {
75 //NSLog(@" name is: %@", [NSString stringWithUTF8String:(const char *)name]);
76 // process element as an integer
77 NSNumber *number = [self _nodeValueAsInt];
78 if (number)
79 {
80 //[dictionary setObject:number forKey:[NSString stringWithUTF8String:(const char *)name]];
81 [twitterIDs addObject:number];
82 }
83 }
84
85 // advance reader
f70adf5 @richardbuckle Eliminated vars w/ same name in inner scope.
richardbuckle authored
86 readerResult = xmlTextReaderRead(_reader);
e744c0b @tarasis Added a LibXML parser for the Social Graph API requests (friends/ids …
tarasis authored
87 if (readerResult != 1)
88 break;
89 nodeType = xmlTextReaderNodeType(_reader);
90 name = xmlTextReaderConstName(_reader);
91 }
92
93 [dictionary setObject:twitterIDs forKey:[NSString stringWithUTF8String:(const char *)name]];
94
95 return dictionary;
96 }
97
98
99 @end
Something went wrong with that request. Please try again.