@@ -6,9 +6,9 @@ extern NSString* const SSYRSSParserErrorDomain ;
6
6
/* !
7
7
@brief A class for parsing RSS feeds
8
8
9
- @detail I made this as a pretty much drop-in replacement for Brent Simmons'
10
- 'RSS' class which he published in year 2002, and which was based on the
11
- now-deprecated CFXMLParser. This class is based on NSXMLParser instead.
9
+ @detail I made this to replace Brent Simmons' 'RSS' class which he published
10
+ in year 2002, and which was based on the now-deprecated CFXMLParser. This
11
+ class is based on NSXMLParser instead.
12
12
*/
13
13
@interface SSYRSSParser : NSObject <NSXMLParserDelegate > {
14
14
NSData * m_data ;
@@ -23,13 +23,37 @@ extern NSString* const SSYRSSParserErrorDomain ;
23
23
24
24
/* !
25
25
@brief Designated initializer for SSYRSS class
26
-
27
- @detail Synchronously parses .
28
26
*/
29
- - (SSYRSSParser*)initWithData : (NSData *)data
30
- error_p : (NSError **)error ;
27
+ - (SSYRSSParser*)initWithData : (NSData *)data ;
28
+
29
+ /* !
30
+ @brief Synchronously parses the data
31
+ @details You must invoke this method prior to -headerItems, -newsItems or
32
+ -version in order for the latter methods to give expected results.
33
+ @param error_p If result is NO, upon return, will point to an NSError
34
+ explaining the problem.
35
+ @result YES if data was successfully parsed; otherwise NO
36
+ */
37
+ - (BOOL )parseError_p : (NSError **)error ;
38
+
39
+ /* !
40
+ @brief Returns the element keys and values parsed from the header of the
41
+ receiver's data
42
+ @details Will return nil if -parseError_p: has not run successfully.
43
+ */
31
44
- (NSMutableDictionary *)headerItems ;
45
+
46
+ /* !
47
+ @brief Returns the news items parsed from the receiver's data. Each item is
48
+ a dictionary containing the item's element keys and values.
49
+ @details Will return nil if -parseError_p: has not run successfully.
50
+ */
32
51
- (NSMutableArray *)newsItems ;
52
+
53
+ /* !
54
+ @brief Returns the version parsed from the RSS (not the version of the XML)
55
+ @details Will return nil if -parseError_p: has not run successfully.
56
+ */
33
57
- (NSString *)version ;
34
58
35
59
@end
@@ -77,17 +101,25 @@ extern NSString* const SSYRSSParserErrorDomain ;
77
101
78
102
+ (void )test {
79
103
NSError * error ;
80
- SSYRSSParser* parser = [[SSYRSSParser alloc ] initWithData: [self testData ]
81
- error_p: &error] ;
82
- printf (" *** Parsed version: %s \n " , [[[parser version ] description ] UTF8String ]) ;
83
- printf (" *** Parsed header items:\n %s \n " , [[[parser headerItems ] description ] UTF8String ]) ;
84
- printf (" *** Parsed news items:\n %s \n " , [[[parser newsItems ] description ] UTF8String ]) ;
104
+ SSYRSSParser* parser = [[SSYRSSParser alloc ] initWithData: [self testData ]] ;
105
+ BOOL ok = [parser parseError_p: &error] ;
106
+ NSString * judgment = ok ? @" succeeded" : @" failed" ;
107
+ printf (" *** Parser %s with error: %s \n " ,
108
+ [judgment UTF8String ],
109
+ [[error description ] UTF8String ]) ;
110
+ printf (" *** Parsed version: %s \n " ,
111
+ [[[parser version ] description ] UTF8String ]) ;
112
+ printf (" *** Parsed header items:\n %s \n " ,
113
+ [[[parser headerItems ] description ] UTF8String ]) ;
114
+ printf (" *** Parsed news items:\n %s \n " ,
115
+ [[[parser newsItems ] description ] UTF8String ]) ;
85
116
[parser release ] ;
86
117
}
87
118
88
119
#if 0
89
120
***** Expected result from +test : *****
90
121
********************************************************************************
122
+ *** Parser succeeded with error: (null)
91
123
*** Parsed version: 2.02
92
124
*** Parsed header items:
93
125
{
0 commit comments