This repository has been archived by the owner on Apr 15, 2019. It is now read-only.
forked from eczarny/xmlrpc
-
Notifications
You must be signed in to change notification settings - Fork 29
/
XMLRPCEventBasedParser.m
81 lines (57 loc) · 1.58 KB
/
XMLRPCEventBasedParser.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#import "XMLRPCEventBasedParser.h"
#import "XMLRPCEventBasedParserDelegate.h"
@implementation XMLRPCEventBasedParser
- (id)initWithData: (NSData *)data {
if (!data) {
return nil;
}
if (self = [self init]) {
myParser = [[NSXMLParser alloc] initWithData: data];
myParserDelegate = nil;
isFault = NO;
}
return self;
}
#pragma mark -
- (id)parse {
[myParser setDelegate: self];
[myParser parse];
if ([myParser parserError]) {
return nil;
}
return [myParserDelegate elementValue];
}
- (void)abortParsing {
[myParser abortParsing];
}
#pragma mark -
- (NSError *)parserError {
return [myParser parserError];
}
#pragma mark -
- (BOOL)isFault {
return isFault;
}
#pragma mark -
- (void)dealloc {
#if ! __has_feature(objc_arc)
[myParser release];
[myParserDelegate release];
[super dealloc];
#endif
}
@end
#pragma mark -
@implementation XMLRPCEventBasedParser (NSXMLParserDelegate)
- (void)parser: (NSXMLParser *)parser didStartElement: (NSString *)element namespaceURI: (NSString *)namespaceURI qualifiedName: (NSString *)qualifiedName attributes: (NSDictionary *)attributes {
if ([element isEqualToString: @"fault"]) {
isFault = YES;
} else if ([element isEqualToString: @"value"]) {
myParserDelegate = [[XMLRPCEventBasedParserDelegate alloc] initWithParent: nil];
[myParser setDelegate: myParserDelegate];
}
}
- (void)parser: (NSXMLParser *)parser parseErrorOccurred: (NSError *)parseError {
[self abortParsing];
}
@end